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