public
Last active

Guided Tour/Pointer API

  • Download Gist
guided-tour-api.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
<?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();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.