/wp-admin/includes/class-wp-internal-pointers.php

  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. * @static 
  28. * 
  29. * @param string $hook_suffix The current admin page. 
  30. */ 
  31. public static function enqueue_scripts( $hook_suffix ) { 
  32. /** 
  33. * Register feature pointers 
  34. * 
  35. * Format: 
  36. * array( 
  37. * hook_suffix => pointer callback 
  38. * ) 
  39. * 
  40. * Example: 
  41. * array( 
  42. * 'themes.php' => 'wp390_widgets' 
  43. * ) 
  44. */ 
  45. $registered_pointers = array( 
  46. // None currently 
  47. ); 
  48.  
  49. // Check if screen related pointer is registered 
  50. if ( empty( $registered_pointers[ $hook_suffix ] ) ) 
  51. return; 
  52.  
  53. $pointers = (array) $registered_pointers[ $hook_suffix ]; 
  54.  
  55. /** 
  56. * Specify required capabilities for feature pointers 
  57. * 
  58. * Format: 
  59. * array( 
  60. * pointer callback => Array of required capabilities 
  61. * ) 
  62. * 
  63. * Example: 
  64. * array( 
  65. * 'wp390_widgets' => array( 'edit_theme_options' ) 
  66. * ) 
  67. */ 
  68. $caps_required = array( 
  69. // None currently 
  70. ); 
  71.  
  72. // Get dismissed pointers 
  73. $dismissed = explode( ', ', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); 
  74.  
  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 ) ) 
  80. continue 2; 
  81.  
  82. // Bind pointer print function 
  83. add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) ); 
  84. $got_pointers = true; 
  85.  
  86. if ( ! $got_pointers ) 
  87. return; 
  88.  
  89. // Add pointers script and style to queue 
  90. wp_enqueue_style( 'wp-pointer' ); 
  91. wp_enqueue_script( 'wp-pointer' ); 
  92.  
  93. /** 
  94. * Print the pointer JavaScript data. 
  95. * 
  96. * @since 3.3.0 
  97. * 
  98. * @static 
  99. * 
  100. * @param string $pointer_id The pointer ID. 
  101. * @param string $selector The HTML elements, on which the pointer should be attached. 
  102. * @param array $args Arguments to be passed to the pointer JS (see wp-pointer.js). 
  103. */ 
  104. private static function print_js( $pointer_id, $selector, $args ) { 
  105. if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) ) 
  106. return; 
  107.  
  108. ?> 
  109. <script type="text/javascript"> 
  110. (function($) { 
  111. var options = <?php echo wp_json_encode( $args ); ?>, setup; 
  112.  
  113. if ( ! options ) 
  114. return; 
  115.  
  116. options = $.extend( options, { 
  117. close: function() { 
  118. $.post( ajaxurl, { 
  119. pointer: '<?php echo $pointer_id; ?>',  
  120. action: 'dismiss-wp-pointer' 
  121. }); 
  122. }); 
  123.  
  124. setup = function() { 
  125. $('<?php echo $selector; ?>').first().pointer( options ).pointer('open'); 
  126. }; 
  127.  
  128. if ( options.position && options.position.defer_loading ) 
  129. $(window).bind( 'load.wp-pointers', setup ); 
  130. else 
  131. $(document).ready( setup ); 
  132.  
  133. })( jQuery ); 
  134. </script> 
  135. <?php 
  136.  
  137. public static function pointer_wp330_toolbar() {} 
  138. public static function pointer_wp330_media_uploader() {} 
  139. public static function pointer_wp330_saving_widgets() {} 
  140. public static function pointer_wp340_customize_current_theme_link() {} 
  141. public static function pointer_wp340_choose_image_from_library() {} 
  142. public static function pointer_wp350_media() {} 
  143. public static function pointer_wp360_revisions() {} 
  144. public static function pointer_wp360_locks() {} 
  145. public static function pointer_wp390_widgets() {} 
  146. public static function pointer_wp410_dfw() {} 
  147.  
  148. /** 
  149. * Prevents new users from seeing existing 'new feature' pointers. 
  150. * 
  151. * @since 3.3.0 
  152. * 
  153. * @static 
  154. * 
  155. * @param int $user_id User ID. 
  156. */ 
  157. public static function dismiss_pointers_for_new_users( $user_id ) { 
  158. add_user_meta( $user_id, 'dismissed_wp_pointers', '' ); 
.