Skip to content

Commit 79aa948

Browse files
paulopmt1claude
andcommitted
Survicate: skip network and user admin pages
is_admin() returns true for /wp-admin/network/* and /wp-admin/user/* too, so the existing should_load() guard was still enqueuing Survicate on wpcom's network admin (e.g. wordpress.com/wp-admin/network/admin.php) — an internal tools surface that the P2 check doesn't cover because the main wpcom blog isn't a P2. Adds an is_network_admin() || is_user_admin() short-circuit and tests that route through WP_Screen via the -network / -user hook suffix, since the screen-based branch of is_network_admin() takes precedence over the WP_NETWORK_ADMIN define once a current_screen is set. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7fbb6cf commit 79aa948

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Significance: patch
22
Type: changed
33

4-
Survicate: skip loading on internal P2 sites and emit an is_big_sky_site visitor trait so Big Sky users can be excluded via Survicate's targeting UI.
4+
Survicate: skip loading on internal P2 sites and network/user admin pages, and emit an is_big_sky_site visitor trait so Big Sky users can be excluded via Survicate's targeting UI.

projects/packages/jetpack-mu-wpcom/src/features/survicate/class-survicate.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ private function should_load() {
5555
return false;
5656
}
5757

58+
// Network and user admin pages on wpcom are internal tools surfaces; surveys must never reach them.
59+
if ( is_network_admin() || is_user_admin() ) {
60+
return false;
61+
}
62+
5863
// Only load for English locale users.
5964
if ( strpos( strtolower( get_user_locale() ), 'en' ) !== 0 ) {
6065
return false;

projects/packages/jetpack-mu-wpcom/tests/php/features/survicate/Survicate_Test.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,34 @@ public function test_should_load_returns_true_for_english_locales( $locale ) {
217217
$this->assertTrue( $this->call_private_method( 'should_load' ) );
218218
}
219219

220+
/**
221+
* Tests that should_load returns false on network admin pages.
222+
*
223+
* Note: is_network_admin() reads $GLOBALS['current_screen']->in_admin( 'network' )
224+
* when a screen is set, so we set a -network-suffixed hook to put WP_Screen
225+
* into network admin mode.
226+
*/
227+
public function test_should_load_returns_false_on_network_admin() {
228+
require_once ABSPATH . 'wp-admin/includes/screen.php';
229+
set_current_screen( 'dashboard-network' );
230+
$this->create_and_login_user();
231+
232+
$this->assertTrue( is_network_admin() );
233+
$this->assertFalse( $this->call_private_method( 'should_load' ) );
234+
}
235+
236+
/**
237+
* Tests that should_load returns false on user admin pages.
238+
*/
239+
public function test_should_load_returns_false_on_user_admin() {
240+
require_once ABSPATH . 'wp-admin/includes/screen.php';
241+
set_current_screen( 'dashboard-user' );
242+
$this->create_and_login_user();
243+
244+
$this->assertTrue( is_user_admin() );
245+
$this->assertFalse( $this->call_private_method( 'should_load' ) );
246+
}
247+
220248
/**
221249
* Tests that should_load returns false on a P2 site detected via stylesheet.
222250
*

0 commit comments

Comments
 (0)