Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

167 rader
4.2 KiB

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