@@ -123,12 +123,13 @@ function perflab_admin_pointer( ?string $hook_suffix = '' ): void {
123
123
if ( is_network_admin () || is_user_admin () ) {
124
124
return ;
125
125
}
126
- $ current_user = get_current_user_id ();
127
- $ pointers = array_keys ( perflab_get_admin_pointers () );
128
- $ dismissed = perflab_get_dismissed_admin_pointer_ids ();
126
+
127
+ $ admin_pointers = perflab_get_admin_pointers ();
128
+ $ admin_pointer_ids = array_keys ( $ admin_pointers );
129
+ $ dismissed_pointer_ids = perflab_get_dismissed_admin_pointer_ids ();
129
130
130
131
// All pointers have been dismissed already.
131
- if ( count ( array_diff ( $ pointers , $ dismissed ) ) === 0 ) {
132
+ if ( count ( array_diff ( $ admin_pointer_ids , $ dismissed_pointer_ids ) ) === 0 ) {
132
133
return ;
133
134
}
134
135
@@ -138,11 +139,11 @@ function perflab_admin_pointer( ?string $hook_suffix = '' ): void {
138
139
// And if we're on the Performance screen, automatically dismiss the pointers.
139
140
if ( isset ( $ _GET ['page ' ] ) && PERFLAB_SCREEN === $ _GET ['page ' ] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
140
141
update_user_meta (
141
- $ current_user ,
142
+ get_current_user_id () ,
142
143
'dismissed_wp_pointers ' ,
143
144
implode (
144
145
', ' ,
145
- array_unique ( array_merge ( $ dismissed , $ pointers ) )
146
+ array_unique ( array_merge ( $ dismissed_pointer_ids , $ admin_pointer_ids ) )
146
147
)
147
148
);
148
149
}
@@ -153,30 +154,12 @@ function perflab_admin_pointer( ?string $hook_suffix = '' ): void {
153
154
// Enqueue pointer CSS and JS.
154
155
wp_enqueue_style ( 'wp-pointer ' );
155
156
wp_enqueue_script ( 'wp-pointer ' );
156
- add_action ( 'admin_print_footer_scripts ' , 'perflab_render_pointer ' , 10 , 0 );
157
- }
158
- add_action ( 'admin_enqueue_scripts ' , 'perflab_admin_pointer ' );
159
157
160
- /**
161
- * Renders the Admin Pointer.
162
- *
163
- * Handles the rendering of the admin pointer.
164
- *
165
- * @todo Eliminate this function in favor of putting it inside of perflab_admin_pointer() which attaches an inline script.
166
- *
167
- * @since 1.0.0
168
- * @since 2.4.0 Optional arguments were added to make the function reusable for different pointers.
169
- * @since n.e.x.t Unused arguments removed.
170
- */
171
- function perflab_render_pointer (): void {
172
158
$ new_install_pointer_id = 'perflab-admin-pointer ' ;
173
- $ perflab_admin_pointers = perflab_get_admin_pointers ();
174
- $ dismissed_pointer_ids = perflab_get_dismissed_admin_pointer_ids ();
175
-
176
159
if ( ! in_array ( $ new_install_pointer_id , $ dismissed_pointer_ids , true ) ) {
177
160
$ needed_pointer_ids = array ( $ new_install_pointer_id );
178
161
} else {
179
- $ needed_pointer_ids = array_diff ( array_keys ( $ perflab_admin_pointers ), $ dismissed_pointer_ids );
162
+ $ needed_pointer_ids = array_diff ( array_keys ( $ admin_pointers ), $ dismissed_pointer_ids );
180
163
}
181
164
182
165
$ args = array (
@@ -186,8 +169,8 @@ function perflab_render_pointer(): void {
186
169
$ args ['content ' ] = implode (
187
170
'' ,
188
171
array_map (
189
- static function ( string $ needed_pointer ) use ( $ perflab_admin_pointers ): string {
190
- return '<p> ' . $ perflab_admin_pointers [ $ needed_pointer ] . '</p> ' ;
172
+ static function ( string $ needed_pointer ) use ( $ admin_pointers ): string {
173
+ return '<p> ' . $ admin_pointers [ $ needed_pointer ] . '</p> ' ;
191
174
},
192
175
$ needed_pointer_ids
193
176
)
@@ -207,7 +190,9 @@ static function ( string $needed_pointer ) use ( $perflab_admin_pointers ): stri
207
190
'strong ' => array (),
208
191
);
209
192
210
- $ pointer_ids_to_dismiss = array_values ( array_diff ( array_keys ( $ perflab_admin_pointers ), $ dismissed_pointer_ids ) );
193
+ $ pointer_ids_to_dismiss = array_values ( array_diff ( array_keys ( $ admin_pointers ), $ dismissed_pointer_ids ) );
194
+
195
+ ob_start ();
211
196
?>
212
197
<script>
213
198
jQuery( function() {
@@ -246,7 +231,12 @@ function dismissNextPointer() {
246
231
} );
247
232
</script>
248
233
<?php
234
+ $ processor = new WP_HTML_Tag_Processor ( (string ) ob_get_clean () );
235
+ if ( $ processor ->next_tag ( array ( 'tag_name ' => 'SCRIPT ' ) ) ) {
236
+ wp_add_inline_script ( 'wp-pointer ' , $ processor ->get_modifiable_text () );
237
+ }
249
238
}
239
+ add_action ( 'admin_enqueue_scripts ' , 'perflab_admin_pointer ' );
250
240
251
241
/**
252
242
* Adds a link to the features page to the plugin's entry in the plugins list table.
0 commit comments