-final class WP_Internal_Pointers {
- /**
- * Initializes the new feature pointers.
- *
- * @since 3.3.0
- *
- * All pointers can be disabled using the following:
- * remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
- *
- * Individual pointers (e.g. wp330_toolbar) can be disabled using the following:
- * remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp330_toolbar' ) );
- */
- public static function enqueue_scripts( $hook_suffix ) {
- /*
- * Register feature pointers
- * Format: array( hook_suffix => pointer_id )
- */
-
- $registered_pointers = array(
- 'index.php' => 'wp330_toolbar',
- 'post-new.php' => 'wp330_media_uploader',
- 'post.php' => 'wp330_media_uploader',
- 'themes.php' => array( 'wp330_saving_widgets', 'wp340_customize_current_theme_link' ),
- 'appearance_page_custom-header' => 'wp340_choose_image_from_library',
- 'appearance_page_custom-background' => 'wp340_choose_image_from_library',
- );
-
- // Check if screen related pointer is registered
- if ( empty( $registered_pointers[ $hook_suffix ] ) )
- return;
-
- $pointers = (array) $registered_pointers[ $hook_suffix ];
-
- $caps_required = array(
- 'wp330_media_uploader' => array( 'upload_files' ),
- 'wp330_saving_widgets' => array( 'edit_theme_options', 'switch_themes' ),
- 'wp340_customize_current_theme_link' => array( 'edit_theme_options' ),
- 'wp340_choose_image_from_library' => array( 'edit_theme_options' ),
- );
-
- // Get dismissed pointers
- $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
-
- $got_pointers = false;
- foreach ( array_diff( $pointers, $dismissed ) as $pointer ) {
- if ( isset( $caps_required[ $pointer ] ) ) {
- foreach ( $caps_required[ $pointer ] as $cap ) {
- if ( ! current_user_can( $cap ) )
- continue 2;
- }
- }
-
- // Bind pointer print function
- add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) );
- $got_pointers = true;
- }
-
- if ( ! $got_pointers )
- return;
-
- // Add pointers script and style to queue
- wp_enqueue_style( 'wp-pointer' );
- wp_enqueue_script( 'wp-pointer' );
- }
-
- /**
- * Print the pointer javascript data.
- *
- * @since 3.3.0
- *
- * @param string $pointer_id The pointer ID.
- * @param string $selector The HTML elements, on which the pointer should be attached.
- * @param array $args Arguments to be passed to the pointer JS (see wp-pointer.dev.js).
- */
- private static function print_js( $pointer_id, $selector, $args ) {
- if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) )
- return;
-
- ?>
- <script type="text/javascript">
- //<![CDATA[
- (function($){
- var options = <?php echo json_encode( $args ); ?>, setup;
-
- if ( ! options )
- return;
-
- options = $.extend( options, {
- close: function() {
- $.post( ajaxurl, {
- pointer: '<?php echo $pointer_id; ?>',
- action: 'dismiss-wp-pointer'
- });
- }
- });
-
- setup = function() {
- $('<?php echo $selector; ?>').pointer( options ).pointer('open');
- };
-
- if ( options.position && options.position.defer_loading )
- $(window).bind( 'load.wp-pointers', setup );
- else
- $(document).ready( setup );
-
- })( jQuery );
- //]]>
- </script>
- <?php