3 * Administration API: WP_Internal_Pointers class
6 * @subpackage Administration
11 * Core class used to implement an internal admin pointers API.
15 final class WP_Internal_Pointers {
17 * Initializes the new feature pointers.
21 * All pointers can be disabled using the following:
22 * remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
24 * Individual pointers (e.g. wp390_widgets) can be disabled using the following:
25 * remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp390_widgets' ) );
29 * @param string $hook_suffix The current admin page.
31 public static function enqueue_scripts( $hook_suffix ) {
33 * Register feature pointers
37 * hook_suffix => pointer callback
42 * 'themes.php' => 'wp390_widgets'
45 $registered_pointers = array(
49 // Check if screen related pointer is registered
50 if ( empty( $registered_pointers[ $hook_suffix ] ) )
53 $pointers = (array) $registered_pointers[ $hook_suffix ];
56 * Specify required capabilities for feature pointers
60 * pointer callback => Array of required capabilities
65 * 'wp390_widgets' => array( 'edit_theme_options' )
68 $caps_required = array(
72 // Get dismissed pointers
73 $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
75 $got_pointers = false;
76 foreach ( array_diff( $pointers, $dismissed ) as $pointer ) {
77 if ( isset( $caps_required[ $pointer ] ) ) {
78 foreach ( $caps_required[ $pointer ] as $cap ) {
79 if ( ! current_user_can( $cap ) )
84 // Bind pointer print function
85 add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) );
89 if ( ! $got_pointers )
92 // Add pointers script and style to queue
93 wp_enqueue_style( 'wp-pointer' );
94 wp_enqueue_script( 'wp-pointer' );
98 * Print the pointer JavaScript data.
104 * @param string $pointer_id The pointer ID.
105 * @param string $selector The HTML elements, on which the pointer should be attached.
106 * @param array $args Arguments to be passed to the pointer JS (see wp-pointer.js).
108 private static function print_js( $pointer_id, $selector, $args ) {
109 if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
113 <script type="text/javascript">
115 var options = <?php echo wp_json_encode( $args ); ?>, setup;
120 options = $.extend( options, {
123 pointer: '<?php echo $pointer_id; ?>',
124 action: 'dismiss-wp-pointer'
130 $('<?php echo $selector; ?>').first().pointer( options ).pointer('open');
133 if ( options.position && options.position.defer_loading )
134 $(window).bind( 'load.wp-pointers', setup );
136 $(document).ready( setup );
143 public static function pointer_wp330_toolbar() {}
144 public static function pointer_wp330_media_uploader() {}
145 public static function pointer_wp330_saving_widgets() {}
146 public static function pointer_wp340_customize_current_theme_link() {}
147 public static function pointer_wp340_choose_image_from_library() {}
148 public static function pointer_wp350_media() {}
149 public static function pointer_wp360_revisions() {}
150 public static function pointer_wp360_locks() {}
151 public static function pointer_wp390_widgets() {}
152 public static function pointer_wp410_dfw() {}
155 * Prevents new users from seeing existing 'new feature' pointers.
161 * @param int $user_id User ID.
163 public static function dismiss_pointers_for_new_users( $user_id ) {
164 add_user_meta( $user_id, 'dismissed_wp_pointers', '' );