[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/includes/ -> class-wp-internal-pointers.php (source)

   1  <?php
   2  /**
   3   * Administration API: WP_Internal_Pointers class
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   * @since 4.4.0
   8   */
   9  
  10  /**
  11   * Core class used to implement an internal admin pointers API.
  12   *
  13   * @since 3.3.0
  14   */
  15  final class WP_Internal_Pointers {
  16      /**
  17       * Initializes the new feature pointers.
  18       *
  19       * @since 3.3.0
  20       *
  21       * All pointers can be disabled using the following:
  22       *     remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) );
  23       *
  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' ) );
  26       *
  27       * @param string $hook_suffix The current admin page.
  28       */
  29  	public static function enqueue_scripts( $hook_suffix ) {
  30          /*
  31           * Register feature pointers
  32           *
  33           * Format:
  34           *     array(
  35           *         hook_suffix => pointer callback
  36           *     )
  37           *
  38           * Example:
  39           *     array(
  40           *         'themes.php' => 'wp390_widgets'
  41           *     )
  42           */
  43          $registered_pointers = array(
  44              //None currently.
  45          );
  46  
  47          // Check if screen related pointer is registered
  48          if ( empty( $registered_pointers[ $hook_suffix ] ) ) {
  49              return;
  50          }
  51  
  52          $pointers = (array) $registered_pointers[ $hook_suffix ];
  53  
  54          /*
  55           * Specify required capabilities for feature pointers
  56           *
  57           * Format:
  58           *     array(
  59           *         pointer callback => Array of required capabilities
  60           *     )
  61           *
  62           * Example:
  63           *     array(
  64           *         'wp390_widgets' => array( 'edit_theme_options' )
  65           *     )
  66           */
  67          $caps_required = array(
  68              // None currently.
  69          );
  70  
  71          // Get dismissed pointers
  72          $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
  73  
  74          $got_pointers = false;
  75          foreach ( array_diff( $pointers, $dismissed ) as $pointer ) {
  76              if ( isset( $caps_required[ $pointer ] ) ) {
  77                  foreach ( $caps_required[ $pointer ] as $cap ) {
  78                      if ( ! current_user_can( $cap ) ) {
  79                          continue 2;
  80                      }
  81                  }
  82              }
  83  
  84              // Bind pointer print function
  85              add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) );
  86              $got_pointers = true;
  87          }
  88  
  89          if ( ! $got_pointers ) {
  90              return;
  91          }
  92  
  93          // Add pointers script and style to queue
  94          wp_enqueue_style( 'wp-pointer' );
  95          wp_enqueue_script( 'wp-pointer' );
  96      }
  97  
  98      /**
  99       * Print the pointer JavaScript data.
 100       *
 101       * @since 3.3.0
 102       *
 103       * @param string $pointer_id The pointer ID.
 104       * @param string $selector The HTML elements, on which the pointer should be attached.
 105       * @param array  $args Arguments to be passed to the pointer JS (see wp-pointer.js).
 106       */
 107  	private static function print_js( $pointer_id, $selector, $args ) {
 108          if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) ) {
 109              return;
 110          }
 111  
 112          ?>
 113          <script type="text/javascript">
 114          (function($){
 115              var options = <?php echo wp_json_encode( $args ); ?>, setup;
 116  
 117              if ( ! options )
 118                  return;
 119  
 120              options = $.extend( options, {
 121                  close: function() {
 122                      $.post( ajaxurl, {
 123                          pointer: '<?php echo $pointer_id; ?>',
 124                          action: 'dismiss-wp-pointer'
 125                      });
 126                  }
 127              });
 128  
 129              setup = function() {
 130                  $('<?php echo $selector; ?>').first().pointer( options ).pointer('open');
 131              };
 132  
 133              if ( options.position && options.position.defer_loading )
 134                  $(window).bind( 'load.wp-pointers', setup );
 135              else
 136                  $(document).ready( setup );
 137  
 138          })( jQuery );
 139          </script>
 140          <?php
 141      }
 142  
 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() {}
 153  	public static function pointer_wp496_privacy() {}
 154  
 155      /**
 156       * Prevents new users from seeing existing 'new feature' pointers.
 157       *
 158       * @since 3.3.0
 159       *
 160       * @param int $user_id User ID.
 161       */
 162  	public static function dismiss_pointers_for_new_users( $user_id ) {
 163          add_user_meta( $user_id, 'dismissed_wp_pointers', '' );
 164      }
 165  }


Generated: Sun Sep 15 01:00:03 2019 Cross-referenced by PHPXref 0.7.1