-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. wp390_widgets) can be disabled using the following:
- * remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp390_widgets' ) );
- */
- public static function enqueue_scripts( $hook_suffix ) {
- /*
- * Register feature pointers
- * Format: array( hook_suffix => pointer_id )
- */
-
- $registered_pointers = array(
- 'post-new.php' => 'wp410_dfw',
- 'post.php' => 'wp410_dfw',
- 'edit.php' => 'wp360_locks',
- 'widgets.php' => 'wp390_widgets',
- 'themes.php' => 'wp390_widgets',
- );
-
- // Check if screen related pointer is registered
- if ( empty( $registered_pointers[ $hook_suffix ] ) )
- return;
-
- $pointers = (array) $registered_pointers[ $hook_suffix ];
-
- $caps_required = array(
- 'wp390_widgets' => 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.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 wp_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; ?>').first().pointer( options ).pointer('open');
- };
-
- if ( options.position && options.position.defer_loading )
- $(window).bind( 'load.wp-pointers', setup );
- else
- $(document).ready( setup );
-
- })( jQuery );
- //]]>
- </script>
- <?php
- }
-
- public static function pointer_wp330_toolbar() {}
- public static function pointer_wp330_media_uploader() {}
- public static function pointer_wp330_saving_widgets() {}
- public static function pointer_wp340_customize_current_theme_link() {}
- public static function pointer_wp340_choose_image_from_library() {}
- public static function pointer_wp350_media() {}
- public static function pointer_wp360_revisions() {}
-
- public static function pointer_wp360_locks() {
- if ( ! is_multi_author() ) {
- return;
- }
-
- $content = '<h3>' . __( 'Edit Lock' ) . '</h3>';
- $content .= '<p>' . __( 'Someone else is editing this. No need to refresh; the lock will disappear when they’re done.' ) . '</p>';
-
- self::print_js( 'wp360_locks', 'tr.wp-locked .locked-indicator', array(
- 'content' => $content,
- 'position' => array( 'edge' => 'left', 'align' => 'left' ),
- ) );
- }
-
- public static function pointer_wp390_widgets() {
- if ( ! current_theme_supports( 'widgets' ) ) {
- return;
- }
-
- $content = '<h3>' . __( 'New Feature: Live Widget Previews' ) . '</h3>';
- $content .= '<p>' . __( 'Add, edit, and play around with your widgets from the Customizer.' ) . ' ' . __( 'Preview your changes in real-time and only save them when you’re ready.' ) . '</p>';
-
- if ( 'themes' === get_current_screen()->id ) {
- $selector = '.theme.active .customize';
- $position = array( 'edge' => is_rtl() ? 'right' : 'left', 'align' => 'center' );
- } else {
- $selector = 'a[href^="customize.php"]';
- if ( is_rtl() ) {
- $position = array( 'edge' => 'right', 'align' => 'center', 'my' => 'right-5px' );
- } else {
- $position = array( 'edge' => 'left', 'align' => 'center', 'my' => 'left-5px' );
- }
- }
-
- self::print_js( 'wp390_widgets', $selector, array(
- 'content' => $content,
- 'position' => $position,
- ) );
- }
-
- public static function pointer_wp410_dfw() {
- // Don't show when editor-scrolling is not used.
- if ( empty( $GLOBALS['_wp_editor_expand'] ) ) {
- return;
- }
-
- $content = '<h3>' . __( 'Distraction-Free Writing' ) . '</h3>';
- $content .= '<p>' . __( 'Enable distraction-free writing mode, and everything surrounding the editor will fade away when you start typing. Move your mouse out of the editor to reveal everything again.' ) . '</p>';
-
- if ( is_rtl() ) {
- $position = array( 'edge' => 'left', 'align' => 'center', 'my' => 'left+40 top-11', 'at' => 'left top' );
- } else {
- $position = array( 'edge' => 'right', 'align' => 'center', 'my' => 'right-40 top-11', 'at' => 'right top' );
- }
-
- self::print_js( 'wp410_dfw', '#wp-content-wrap', array(
- 'content' => $content,
- 'position' => $position,
- ) );
- }
-
- /**
- * Prevents new users from seeing existing 'new feature' pointers.
- *
- * @since 3.3.0
- */
- public static function dismiss_pointers_for_new_users( $user_id ) {
- add_user_meta( $user_id, 'dismissed_wp_pointers', 'wp360_locks,wp390_widgets' );
- }
-}
-
-add_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
-add_action( 'user_register', array( 'WP_Internal_Pointers', 'dismiss_pointers_for_new_users' ) );
-