WP_Internal_Pointers

Core class used to implement an internal admin pointers API.

Defined (1)

The class is defined in the following location(s).

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