Creating Intro.js Powered Tours in WordPress

Posted by Unknown on Sunday, January 19, 2014

In a previous article, An Introduction to Product Tours with Intro.js, we discussed the importance of creating product tours and how we can use Intro.js to create awesome product tours. Unfortunately, we configured each step manually – a methodology that is not suitable for users with limited programming knowledge. However, the real power of Intro.js comes from its ability to create product tours on dynamic content without much programming. This tutorial will teach you how to integrate Intro.js into WordPress.


Building an Intro.js WordPress Plugin


Plugins are the recommended components for adding custom behavior into WordPress. We will be using a plugin to integrate Intro.js into WordPress. Begin by creating a new folder within the wp-content/plugins folder and name it wpintrojs. Next, create the main plugin file, index.php, and use the following code to define the plugin.



<?php
/*
Plugin Name: Introjs Tours
Plugin URI:
Description: Integrating intro.js powered product tours into WordPress
Author: Your Name
Version: 1.0
Author URI: http://www.innovativephp.com/
*/

Next, login as admin and activate the plugin in the Plugins section.


Creating Product Tour Steps


In the previous tutorial, we configured each step manually by assigning the necessary data-attributes and values. Here, we need a simpler way to configure tour steps, as the content is generated dynamically within WordPress. So, it’s essential to build a plugin specific page to configure the steps. Let’s start by adding new a plugin specific page using the following code.



add_action( 'admin_menu', 'wpintro_menu_page' );

function wpintro_menu_page(){
add_menu_page( 'Product Tours', 'Product Tours', 'manage_options', 'wpintro_tour', 'wpintro_menu_page_display', plugins_url( 'myplugin/images/icon.png' ), 6 );
add_submenu_page( 'wpintro_tour', 'Manage Steps', 'Manage Steps', 'manage_options', 'wpintro_tour_steps', 'wpintro_manage_steps_display' );
}

In this code, we have a main admin page as well as a sub menu page. The main menu page is used to configure the steps, while the sub menu page is used to configure the order of the steps within the tour. First, we are going to look at the product step creation page by implementing the wpintro_menu_page_display function used in the previous code block. This function is shown below.



function wpintro_menu_page_display() {
global $wip_message;
$pages = get_pages();
$html = '';

if ($wip_message != '') {
$html .= '<div style="background:#9FD09F;padding:5px;">' . $wip_message . '</div>';
}

$html .= '<h2>Create Product Tour</h2>';
$html .= '<form action="" method="post">';
$html .= '<table class="form-table"><tbody>';
$html .= ' <tr valign="top">
<th scope="row"><label>Select Page</label></th>
<td><select class="regular-text" id="wpi_page" name="wpi_page">';

foreach ($pages as $page) {
$html .= '<option value="' . get_page_link($page->ID) . '">';
$html .= $page->post_title;
$html .= '</option>';
}

$html .= ' </select></td>
</tr>';
$html .= ' <tr valign="top">
<th scope="row"><label>Intro Text</label></th>
<td><textarea class="regular-text" id="wpi_intro_text" name="wpi_intro_text"></textarea></td>
</tr>';
$html .= ' <tr valign="top">
<th scope="row"><label>Element ID</label></th>
<td><input type="text" class="regular-text" id="wpi_element_id" name="wpi_element_id"/></td>
</tr>';
$html .= ' <tr valign="top">
<th scope="row"><label></label></th>
<td><input type="hidden" class="regular-text" id="wpi_action" name="wpi_action" value="save_steps" />
<input type="submit" class="regular-text" id="wpi_submit" name="wpi_submit" value="Save" /></td>
</tr>';
$html .= '</tbody></table></form>';
echo $html;
}

This function is used to display the contents of the menu page. The page consists of a heading and a html form for generating steps. The form contains three fields for adding new steps.



  • Element ID – This


Truncated by Planet PHP, read more at the original (another 16147 bytes)




more

{ 0 comments... » Creating Intro.js Powered Tours in WordPress read them below or add one }

Post a Comment

Popular Posts