Skip to content

Commit 19e7bd7

Browse files
committed
Prevent auto-dismissing Speculative Loading auth feature pointer
1 parent 1b22718 commit 19e7bd7

File tree

2 files changed

+42
-28
lines changed

2 files changed

+42
-28
lines changed

plugins/performance-lab/includes/admin/load.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,31 +88,37 @@ function perflab_get_dismissed_admin_pointer_ids(): array {
8888
*
8989
* @since n.e.x.t
9090
*
91-
* @return array<non-empty-string, array{ content: string, plugin?: non-empty-string }> Keys are the admin pointer IDs.
91+
* @return array<non-empty-string, array{ content: string, plugin: non-empty-string, dismiss_if_installed: bool }> Keys are the admin pointer IDs.
9292
*/
9393
function perflab_get_admin_pointers(): array {
9494
$pointers = array(
9595
'perflab-admin-pointer' => array(
96-
'content' => __( 'You can now test upcoming WordPress performance features.', 'performance-lab' ),
96+
'content' => __( 'You can now test upcoming WordPress performance features.', 'performance-lab' ),
97+
'plugin' => 'performance-lab',
98+
'dismiss_if_installed' => false,
9799
),
98100
'perflab-feature-view-transitions' => array(
99-
'content' => __( 'New <strong>View Transitions</strong> feature now available.', 'performance-lab' ),
100-
'plugin' => 'view-transitions',
101+
'content' => __( 'New <strong>View Transitions</strong> feature now available.', 'performance-lab' ),
102+
'plugin' => 'view-transitions',
103+
'dismiss_if_installed' => true,
101104
),
102105
'perflab-feature-nocache-bfcache' => array(
103-
'content' => __( 'New <strong>No-cache BFCache</strong> feature now available.', 'performance-lab' ),
104-
'plugin' => 'nocache-bfcache',
106+
'content' => __( 'New <strong>No-cache BFCache</strong> feature now available.', 'performance-lab' ),
107+
'plugin' => 'nocache-bfcache',
108+
'dismiss_if_installed' => true,
105109
),
106110
);
107111

112+
$installed_plugins = get_plugins();
108113
if (
109-
defined( 'SPECULATION_RULES_VERSION' )
114+
isset( $installed_plugins['speculation-rules/load.php']['Version'] )
110115
&&
111-
version_compare( SPECULATION_RULES_VERSION, '1.6.0', '>=' )
116+
version_compare( $installed_plugins['speculation-rules/load.php']['Version'], '1.6.0', '>=' )
112117
) {
113118
$pointers['perflab-feature-speculation-rules-auth'] = array(
114-
'content' => __( '<strong>Speculative Loading</strong> now includes an opt-in setting for logged-in users.', 'performance-lab' ),
115-
'plugin' => 'speculation-rules',
119+
'content' => __( '<strong>Speculative Loading</strong> now includes an opt-in setting for logged-in users.', 'performance-lab' ),
120+
'plugin' => 'speculative-loading',
121+
'dismiss_if_installed' => false,
116122
);
117123
}
118124

@@ -158,15 +164,15 @@ function perflab_admin_pointer( ?string $hook_suffix = '' ): void {
158164
}
159165

160166
// List of pointer IDs that are tied to feature plugin slugs.
161-
$plugin_dependent_pointers = array();
167+
$plugin_pointers_dismissed_if_installed = array();
162168
foreach ( $admin_pointers as $pointer_id => $admin_pointer ) {
163-
if ( isset( $admin_pointer['plugin'] ) ) {
164-
$plugin_dependent_pointers[ $pointer_id ] = $admin_pointer['plugin'];
169+
if ( $admin_pointer['dismiss_if_installed'] ) {
170+
$plugin_pointers_dismissed_if_installed[ $pointer_id ] = $admin_pointer['plugin'];
165171
}
166172
}
167173

168174
// Preemptively dismiss plugin-specific pointers for plugins which are already installed.
169-
$plugin_dependent_pointers_undismissed = array_diff( array_keys( $plugin_dependent_pointers ), $dismissed_pointer_ids );
175+
$plugin_dependent_pointers_undismissed = array_diff( array_keys( $plugin_pointers_dismissed_if_installed ), $dismissed_pointer_ids );
170176
if ( count( $plugin_dependent_pointers_undismissed ) > 0 ) {
171177
/**
172178
* Installed plugin slugs.
@@ -182,7 +188,7 @@ static function ( $name ) {
182188

183189
foreach ( $plugin_dependent_pointers_undismissed as $pointer_id ) {
184190
if (
185-
in_array( $plugin_dependent_pointers[ $pointer_id ], $installed_plugin_slugs, true ) &&
191+
in_array( $plugin_pointers_dismissed_if_installed[ $pointer_id ], $installed_plugin_slugs, true ) &&
186192
! in_array( $pointer_id, $dismissed_pointer_ids, true )
187193
) {
188194
$auto_dismissed_pointer_ids[] = $pointer_id;

plugins/performance-lab/tests/includes/admin/test-load.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,57 +127,65 @@ public function test_perflab_get_admin_pointers(): void {
127127
*/
128128
public function data_provider_test_perflab_admin_pointer(): array {
129129
return array(
130-
'null' => array(
130+
'null' => array(
131131
'initial_wp_pointers' => '',
132132
'hook_suffix' => null,
133133
'expected' => false,
134134
'dismissed_wp_pointers' => '',
135135
),
136-
'edit.php' => array(
136+
'edit.php' => array(
137137
'initial_wp_pointers' => '',
138138
'hook_suffix' => 'edit.php',
139139
'expected' => false,
140140
'dismissed_wp_pointers' => '',
141141
),
142-
'dashboard_not_dismissed' => array(
142+
'dashboard_not_dismissed' => array(
143143
'initial_wp_pointers' => '',
144144
'hook_suffix' => 'index.php',
145145
'expected' => true,
146146
'dismissed_wp_pointers' => 'perflab-feature-view-transitions',
147147
),
148-
'plugins_not_dismissed' => array(
148+
'plugins_not_dismissed' => array(
149149
'initial_wp_pointers' => '',
150150
'hook_suffix' => 'plugins.php',
151151
'expected' => true,
152152
'dismissed_wp_pointers' => 'perflab-feature-view-transitions',
153153
),
154-
'dashboard_new_dismissed' => array(
154+
'dashboard_new_dismissed' => array(
155155
// Note: If the No-cache BFCache plugin (not part of the monorepo) is installed, then this test will likely fail and it should be skipped.
156156
'initial_wp_pointers' => 'perflab-admin-pointer',
157157
'hook_suffix' => 'index.php',
158158
'expected' => true,
159159
'dismissed_wp_pointers' => 'perflab-admin-pointer,perflab-feature-view-transitions',
160160
),
161-
'dashboard_one_dismissed' => array(
161+
'dashboard_last_auto_dismissed' => array(
162162
// Note: The No-cache BFCache plugin is not part of the monorepo, so it is not automatically installed in the dev environment.
163-
'initial_wp_pointers' => 'perflab-admin-pointer,perflab-feature-nocache-bfcache',
163+
'initial_wp_pointers' => 'perflab-admin-pointer,perflab-feature-nocache-bfcache,perflab-feature-speculation-rules-auth',
164164
'hook_suffix' => 'index.php',
165165
'expected' => false,
166+
'dismissed_wp_pointers' => 'perflab-admin-pointer,perflab-feature-nocache-bfcache,perflab-feature-speculation-rules-auth,perflab-feature-view-transitions',
167+
),
168+
'dashboard_one_not_auto_dismissed' => array(
169+
// Note: The No-cache BFCache plugin is not part of the monorepo, so it is not automatically installed in the dev environment.
170+
// Note: The Speculative Loading admin pointer 'perflab-feature-speculation-rules-auth' does not get auto-dismissed because it is for a new feature of an existing feature plugin.
171+
'initial_wp_pointers' => 'perflab-admin-pointer,perflab-feature-nocache-bfcache',
172+
'hook_suffix' => 'index.php',
173+
'expected' => true,
166174
'dismissed_wp_pointers' => 'perflab-admin-pointer,perflab-feature-nocache-bfcache,perflab-feature-view-transitions',
167175
),
168-
'dashboard_all_dismissed' => array(
176+
'dashboard_all_dismissed' => array(
169177
'initial_wp_pointers' => implode( ',', array_keys( perflab_get_admin_pointers() ) ),
170178
'hook_suffix' => 'index.php',
171179
'expected' => false,
172180
'dismissed_wp_pointers' => implode( ',', array_keys( perflab_get_admin_pointers() ) ),
173181
),
174-
'perflab_screen_first_time' => array(
182+
'perflab_screen_first_time' => array(
175183
'initial_wp_pointers' => '',
176184
'hook_suffix' => 'settings_page_' . PERFLAB_SCREEN,
177185
'expected' => false,
178186
'dismissed_wp_pointers' => implode( ',', array_keys( perflab_get_admin_pointers() ) ),
179187
),
180-
'perflab_screen_second_time' => array(
188+
'perflab_screen_second_time' => array(
181189
'initial_wp_pointers' => 'perflab-admin-pointer',
182190
'hook_suffix' => 'settings_page_' . PERFLAB_SCREEN,
183191
'expected' => false,
@@ -207,14 +215,14 @@ public function test_perflab_admin_pointer( string $initial_wp_pointers, ?string
207215
if ( $script_dependency instanceof _WP_Dependency ) {
208216
$after_script = implode( "\n", array_filter( $script_dependency->extra['after'] ?? array() ) );
209217
}
218+
$this->assertSame( $dismissed_wp_pointers, get_user_meta( $user_id, 'dismissed_wp_pointers', true ) );
219+
$this->assertSame( $expected, wp_script_is( 'wp-pointer', 'enqueued' ) );
220+
$this->assertSame( $expected, wp_style_is( 'wp-pointer', 'enqueued' ) );
210221
if ( $expected ) {
211222
$this->assertStringContainsString( 'pointerIdsToDismiss', $after_script );
212223
} else {
213224
$this->assertStringNotContainsString( 'pointerIdsToDismiss', $after_script );
214225
}
215-
$this->assertSame( $expected, wp_script_is( 'wp-pointer', 'enqueued' ) );
216-
$this->assertSame( $expected, wp_style_is( 'wp-pointer', 'enqueued' ) );
217-
$this->assertSame( $dismissed_wp_pointers, get_user_meta( $user_id, 'dismissed_wp_pointers', true ) );
218226
}
219227

220228
/**

0 commit comments

Comments
 (0)