@@ -120,78 +120,84 @@ function perflab_get_admin_pointers(): array {
120
120
* ensure that `$hook_suffix` is a string when it calls `do_action( 'admin_enqueue_scripts', $hook_suffix )`.
121
121
*/
122
122
function perflab_admin_pointer ( ?string $ hook_suffix = '' ): void {
123
- // Do not show admin pointer in multisite Network admin or User admin UI.
124
- if ( is_network_admin () || is_user_admin () ) {
123
+ $ is_performance_screen = (
124
+ 'options-general.php ' === $ hook_suffix &&
125
+ ( isset ( $ _GET ['page ' ] ) && PERFLAB_SCREEN === $ _GET ['page ' ] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
126
+ );
127
+
128
+ // Do not show admin pointer in multisite Network admin, User admin UI, dashboard, or plugins list table. However,
129
+ // do proceed on the Performance screen so that all pointers can be auto-dismissed.
130
+ if (
131
+ is_network_admin () ||
132
+ is_user_admin () ||
133
+ (
134
+ ! in_array ( $ hook_suffix , array ( 'index.php ' , 'plugins.php ' ), true ) &&
135
+ ! $ is_performance_screen
136
+ )
137
+ ) {
125
138
return ;
126
139
}
127
140
128
141
$ admin_pointers = perflab_get_admin_pointers ();
129
142
$ admin_pointer_ids = array_keys ( $ admin_pointers );
130
143
$ dismissed_pointer_ids = perflab_get_dismissed_admin_pointer_ids ();
131
144
132
- // All pointers have been dismissed already.
133
- if ( count ( array_diff ( $ admin_pointer_ids , $ dismissed_pointer_ids ) ) === 0 ) {
134
- return ;
135
- }
136
-
137
- // Do not show the admin pointer when not on the dashboard or plugins list table.
138
- if ( ! in_array ( $ hook_suffix , array ( 'index.php ' , 'plugins.php ' ), true ) ) {
139
-
140
- // And if we're on the Performance screen, automatically dismiss the pointers.
141
- if ( isset ( $ _GET ['page ' ] ) && PERFLAB_SCREEN === $ _GET ['page ' ] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
142
- update_user_meta (
143
- get_current_user_id (),
144
- 'dismissed_wp_pointers ' ,
145
- implode (
146
- ', ' ,
147
- array_unique ( array_merge ( $ dismissed_pointer_ids , $ admin_pointer_ids ) )
148
- )
149
- );
150
- }
151
-
152
- return ;
145
+ // And if we're on the Performance screen, automatically dismiss all the pointers.
146
+ $ auto_dismissed_pointer_ids = array ();
147
+ if ( $ is_performance_screen ) {
148
+ $ auto_dismissed_pointer_ids = array_merge ( $ auto_dismissed_pointer_ids , $ admin_pointer_ids );
153
149
}
154
150
155
- /**
156
- * Installed plugin slugs.
157
- *
158
- * @var non-empty-string[] $installed_plugin_slugs
159
- */
160
- $ installed_plugin_slugs = array_map (
161
- static function ( $ name ) {
162
- return strtok ( $ name , '/ ' );
163
- },
164
- array_keys ( get_plugins () )
165
- );
166
-
167
151
// List of pointer IDs that are tied to feature plugin slugs.
152
+ // TODO: Add this to perflab_get_admin_pointers().
168
153
$ plugin_dependent_pointers = array (
169
154
'perflab-feature-view-transitions ' => 'view-transitions ' ,
170
155
'perflab-feature-nocache-bfcache ' => 'nocache-bfcache ' ,
171
156
);
172
157
173
- // Make sure that the dismissed pointers include any plugins that are already installed.
174
- $ dismissed_pointers_updated = false ;
175
- foreach ( $ plugin_dependent_pointers as $ pointer_id => $ slug ) {
176
- if ( in_array ( $ slug , $ installed_plugin_slugs , true ) && ! in_array ( $ pointer_id , $ dismissed_pointer_ids , true ) ) {
177
- $ dismissed_pointer_ids [] = $ pointer_id ;
178
- $ dismissed_pointers_updated = true ;
158
+ // Preemptively dismiss plugin-specific pointers for plugins which are already installed.
159
+ $ plugin_dependent_pointers_undismissed = array_diff ( array_keys ( $ plugin_dependent_pointers ), $ dismissed_pointer_ids );
160
+ if ( count ( $ plugin_dependent_pointers_undismissed ) > 0 ) {
161
+ /**
162
+ * Installed plugin slugs.
163
+ *
164
+ * @var non-empty-string[] $installed_plugin_slugs
165
+ */
166
+ $ installed_plugin_slugs = array_map (
167
+ static function ( $ name ) {
168
+ return strtok ( $ name , '/ ' );
169
+ },
170
+ array_keys ( get_plugins () )
171
+ );
172
+
173
+ foreach ( $ plugin_dependent_pointers_undismissed as $ pointer_id ) {
174
+ if (
175
+ in_array ( $ plugin_dependent_pointers [ $ pointer_id ], $ installed_plugin_slugs , true ) &&
176
+ ! in_array ( $ pointer_id , $ dismissed_pointer_ids , true )
177
+ ) {
178
+ $ auto_dismissed_pointer_ids [] = $ pointer_id ;
179
+ }
179
180
}
180
181
}
181
- if ( $ dismissed_pointers_updated ) {
182
+
183
+ // Persist the automatically-dismissed pointers.
184
+ if ( count ( $ auto_dismissed_pointer_ids ) > 0 ) {
185
+ $ dismissed_pointer_ids = array_unique ( array_merge ( $ dismissed_pointer_ids , $ auto_dismissed_pointer_ids ) );
182
186
update_user_meta (
183
187
get_current_user_id (),
184
188
'dismissed_wp_pointers ' ,
185
189
implode ( ', ' , $ dismissed_pointer_ids )
186
190
);
187
191
}
188
192
193
+ // Determine which admin pointers we need.
189
194
$ new_install_pointer_id = 'perflab-admin-pointer ' ;
190
195
if ( ! in_array ( $ new_install_pointer_id , $ dismissed_pointer_ids , true ) ) {
191
196
$ needed_pointer_ids = array ( $ new_install_pointer_id );
192
197
} else {
193
- $ needed_pointer_ids = array_diff ( $ admin_pointer_ids, $ dismissed_pointer_ids ) ;
198
+ $ needed_pointer_ids = $ admin_pointer_ids ;
194
199
}
200
+ $ needed_pointer_ids = array_diff ( $ needed_pointer_ids , $ dismissed_pointer_ids );
195
201
196
202
// No admin pointers are needed, so abort.
197
203
if ( count ( $ needed_pointer_ids ) === 0 ) {
0 commit comments