22 * remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) ); |
22 * remove_action( 'admin_enqueue_scripts', array( 'WP_Internal_Pointers', 'enqueue_scripts' ) ); |
23 * |
23 * |
24 * Individual pointers (e.g. wp390_widgets) can be disabled using the following: |
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' ) ); |
25 * remove_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_wp390_widgets' ) ); |
26 * |
26 * |
27 * @static |
|
28 * |
|
29 * @param string $hook_suffix The current admin page. |
27 * @param string $hook_suffix The current admin page. |
30 */ |
28 */ |
31 public static function enqueue_scripts( $hook_suffix ) { |
29 public static function enqueue_scripts( $hook_suffix ) { |
32 /* |
30 /* |
33 * Register feature pointers |
31 * Register feature pointers |
41 * array( |
39 * array( |
42 * 'themes.php' => 'wp390_widgets' |
40 * 'themes.php' => 'wp390_widgets' |
43 * ) |
41 * ) |
44 */ |
42 */ |
45 $registered_pointers = array( |
43 $registered_pointers = array( |
46 'index.php' => 'wp496_privacy', |
44 //None currently. |
47 ); |
45 ); |
48 |
46 |
49 // Check if screen related pointer is registered |
47 // Check if screen related pointer is registered |
50 if ( empty( $registered_pointers[ $hook_suffix ] ) ) |
48 if ( empty( $registered_pointers[ $hook_suffix ] ) ) { |
51 return; |
49 return; |
|
50 } |
52 |
51 |
53 $pointers = (array) $registered_pointers[ $hook_suffix ]; |
52 $pointers = (array) $registered_pointers[ $hook_suffix ]; |
54 |
53 |
55 /* |
54 /* |
56 * Specify required capabilities for feature pointers |
55 * Specify required capabilities for feature pointers |
64 * array( |
63 * array( |
65 * 'wp390_widgets' => array( 'edit_theme_options' ) |
64 * 'wp390_widgets' => array( 'edit_theme_options' ) |
66 * ) |
65 * ) |
67 */ |
66 */ |
68 $caps_required = array( |
67 $caps_required = array( |
69 'wp496_privacy' => array( |
68 // None currently. |
70 'manage_privacy_options', |
|
71 'export_others_personal_data', |
|
72 'erase_others_personal_data', |
|
73 ), |
|
74 ); |
69 ); |
75 |
70 |
76 // Get dismissed pointers |
71 // Get dismissed pointers |
77 $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); |
72 $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); |
78 |
73 |
79 $got_pointers = false; |
74 $got_pointers = false; |
80 foreach ( array_diff( $pointers, $dismissed ) as $pointer ) { |
75 foreach ( array_diff( $pointers, $dismissed ) as $pointer ) { |
81 if ( isset( $caps_required[ $pointer ] ) ) { |
76 if ( isset( $caps_required[ $pointer ] ) ) { |
82 foreach ( $caps_required[ $pointer ] as $cap ) { |
77 foreach ( $caps_required[ $pointer ] as $cap ) { |
83 if ( ! current_user_can( $cap ) ) |
78 if ( ! current_user_can( $cap ) ) { |
84 continue 2; |
79 continue 2; |
|
80 } |
85 } |
81 } |
86 } |
82 } |
87 |
83 |
88 // Bind pointer print function |
84 // Bind pointer print function |
89 add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) ); |
85 add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) ); |
90 $got_pointers = true; |
86 $got_pointers = true; |
91 } |
87 } |
92 |
88 |
93 if ( ! $got_pointers ) |
89 if ( ! $got_pointers ) { |
94 return; |
90 return; |
|
91 } |
95 |
92 |
96 // Add pointers script and style to queue |
93 // Add pointers script and style to queue |
97 wp_enqueue_style( 'wp-pointer' ); |
94 wp_enqueue_style( 'wp-pointer' ); |
98 wp_enqueue_script( 'wp-pointer' ); |
95 wp_enqueue_script( 'wp-pointer' ); |
99 } |
96 } |
101 /** |
98 /** |
102 * Print the pointer JavaScript data. |
99 * Print the pointer JavaScript data. |
103 * |
100 * |
104 * @since 3.3.0 |
101 * @since 3.3.0 |
105 * |
102 * |
106 * @static |
|
107 * |
|
108 * @param string $pointer_id The pointer ID. |
103 * @param string $pointer_id The pointer ID. |
109 * @param string $selector The HTML elements, on which the pointer should be attached. |
104 * @param string $selector The HTML elements, on which the pointer should be attached. |
110 * @param array $args Arguments to be passed to the pointer JS (see wp-pointer.js). |
105 * @param array $args Arguments to be passed to the pointer JS (see wp-pointer.js). |
111 */ |
106 */ |
112 private static function print_js( $pointer_id, $selector, $args ) { |
107 private static function print_js( $pointer_id, $selector, $args ) { |
113 if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) ) |
108 if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) ) { |
114 return; |
109 return; |
|
110 } |
115 |
111 |
116 ?> |
112 ?> |
117 <script type="text/javascript"> |
113 <script type="text/javascript"> |
118 (function($){ |
114 (function($){ |
119 var options = <?php echo wp_json_encode( $args ); ?>, setup; |
115 var options = <?php echo wp_json_encode( $args ); ?>, setup; |
152 public static function pointer_wp350_media() {} |
148 public static function pointer_wp350_media() {} |
153 public static function pointer_wp360_revisions() {} |
149 public static function pointer_wp360_revisions() {} |
154 public static function pointer_wp360_locks() {} |
150 public static function pointer_wp360_locks() {} |
155 public static function pointer_wp390_widgets() {} |
151 public static function pointer_wp390_widgets() {} |
156 public static function pointer_wp410_dfw() {} |
152 public static function pointer_wp410_dfw() {} |
157 |
153 public static function pointer_wp496_privacy() {} |
158 /** |
|
159 * Display a pointer for the new privacy tools. |
|
160 * |
|
161 * @since 4.9.6 |
|
162 */ |
|
163 public static function pointer_wp496_privacy() { |
|
164 $content = '<h3>' . __( 'Personal Data and Privacy' ) . '</h3>'; |
|
165 $content .= '<h4>' . __( 'Personal Data Export and Erasure' ) . '</h4>'; |
|
166 $content .= '<p>' . __( 'New <strong>Tools</strong> have been added to help you with personal data export and erasure requests.' ) . '</p>'; |
|
167 $content .= '<h4>' . __( 'Privacy Policy' ) . '</h4>'; |
|
168 $content .= '<p>' . __( 'Create or select your site’s privacy policy page under <strong>Settings > Privacy</strong> to keep your users informed and aware.' ) . '</p>'; |
|
169 |
|
170 if ( is_rtl() ) { |
|
171 $position = array( |
|
172 'edge' => 'right', |
|
173 'align' => 'bottom', |
|
174 ); |
|
175 } else { |
|
176 $position = array( |
|
177 'edge' => 'left', |
|
178 'align' => 'bottom', |
|
179 ); |
|
180 } |
|
181 |
|
182 $js_args = array( |
|
183 'content' => $content, |
|
184 'position' => $position, |
|
185 'pointerClass' => 'wp-pointer arrow-bottom', |
|
186 'pointerWidth' => 420, |
|
187 ); |
|
188 self::print_js( 'wp496_privacy', '#menu-tools', $js_args ); |
|
189 } |
|
190 |
154 |
191 /** |
155 /** |
192 * Prevents new users from seeing existing 'new feature' pointers. |
156 * Prevents new users from seeing existing 'new feature' pointers. |
193 * |
157 * |
194 * @since 3.3.0 |
158 * @since 3.3.0 |
195 * |
159 * |
196 * @static |
|
197 * |
|
198 * @param int $user_id User ID. |
160 * @param int $user_id User ID. |
199 */ |
161 */ |
200 public static function dismiss_pointers_for_new_users( $user_id ) { |
162 public static function dismiss_pointers_for_new_users( $user_id ) { |
201 add_user_meta( $user_id, 'dismissed_wp_pointers', 'wp496_privacy' ); |
163 add_user_meta( $user_id, 'dismissed_wp_pointers', '' ); |
202 } |
164 } |
203 } |
165 } |