Created
October 4, 2011 12:14
-
-
Save nb/1261486 to your computer and use it in GitHub Desktop.
Guided Tour/Pointer API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Guided Tour/Pointer API | |
Notes: | |
- exit button is by default | |
- next button is there if another pointer is linked to this one via previous-pointer | |
- if no attach-to, put it in the center if the window | |
- tour and pointer slugs are used for IDs in HTML and keys in user options | |
*/ | |
$tour = new WPGuidedTour('admin'); | |
$tour->add_pointer( 'welcome', array( | |
'content' => '<h3>Welcome</h3><p>We will guide you throughout the wp-admin interface.</p>', | |
'show-on' => 'each-admin-page', | |
) ); | |
$tour->add_pointer( 'posts', array( | |
'content' => '<p>Posts are cool. Hover the posts menu to get started.</p>', | |
'show-on' => 'each-admin-page', | |
'attach-to' => '#menu-posts', | |
'position' => 'right', | |
'previous-pointer' => 'welcome', | |
) ); | |
$tour->add_pointer( 'add-new-post', array( | |
'content' => '<p>New posts are even cooler. Click on </p>', | |
'show-on' => 'each-admin-page', | |
'attach-to' => '#menu-posts li[href="post-new.php"]', | |
'position' => 'right', | |
'previous-pointer' => 'posts', | |
'pre-create-js' => 'function($) { $("#menu-posts").hover(); }', | |
) ); | |
$tour->add_pointer( 'post-title', array( | |
'content' => 'Write a title', | |
'show-on' => array( 'hook-suffix' => 'post-new.php' ), | |
'attach-to' => '#title', | |
'position' => 'bottom', | |
'previous-pointer' => 'add-new-post', | |
'js-pre-create' => <<<JS | |
function($) { | |
window.location.href = "post-new.php"; | |
$("#title").focus(); | |
} | |
JS; | |
) ); | |
$tour->add_pointer( 'post-body', array( | |
'content' => 'Write a body', | |
'show-on' => array( 'hook-suffix' => 'post-new.php' ), | |
'attach-to' => '#body', | |
'position' => array( 'my' => 'left top', 'at' => 'center bottom', 'offset' => '-25 0' ), | |
'previous-pointer' => 'post-title', | |
'js-pre-create' => <<<JS | |
function($) { | |
$("#body").focus(); | |
} | |
JS; | |
) ); | |
/* Init will set all the needed hooks, enqueue scripts, etc. */ | |
add_action( 'init', function() use ($tour) { $tour->init(); } ); | |
$pointer = $tour->get_pointer( 'add-new-post' ); | |
$pointer = $tour->get_next_pointer_of( 'add-new-post' ); | |
$pointers = $tour->get_pointers(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment