Skip to content

Commit 7fbb6cf

Browse files
paulopmt1claude
andcommitted
Use Status\Host::is_p2_site() instead of a new helper
Survicate calls the canonical Automattic\Jetpack\Status\Host::is_p2_site() in src/features/survicate/class-survicate.php directly. Drops the short-lived wpcom_is_p2_site() helper from src/utils.php — the same package already wraps Status\Host for is_woa_site() but the dedicated P2 helper makes its own wrapper unnecessary. Status\Host::is_p2_site() short-circuits to false when there is no wpcom site id, so the P2 stylesheet/WPForTeams tests now define IS_WPCOM in their isolated process to route get_wpcom_site_id() through get_current_blog_id() (matching the pattern in projects/packages/status/tests/php/Host_Test.php). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a88ac97 commit 7fbb6cf

3 files changed

Lines changed: 20 additions & 26 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private function should_load() {
6161
}
6262

6363
// Atomic powers Automattic's internal P2s; surveys must never reach them.
64-
if ( wpcom_is_p2_site() ) {
64+
if ( ( new \Automattic\Jetpack\Status\Host() )->is_p2_site() ) {
6565
return false;
6666
}
6767

projects/packages/jetpack-mu-wpcom/src/utils.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,3 @@ function wpcom_has_blog_sticker( $blog_sticker, $blog_id ) {
213213
}
214214
return false;
215215
}
216-
217-
/**
218-
* Whether the current site is a P2.
219-
*
220-
* @return bool
221-
*/
222-
function wpcom_is_p2_site() {
223-
if ( str_contains( get_stylesheet(), 'pub/p2' ) ) {
224-
return true;
225-
}
226-
227-
if ( function_exists( '\WPForTeams\is_wpforteams_site' ) ) {
228-
return \WPForTeams\is_wpforteams_site( get_current_blog_id() );
229-
}
230-
231-
return false;
232-
}

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,26 @@ public function test_should_load_returns_true_for_english_locales( $locale ) {
219219

220220
/**
221221
* Tests that should_load returns false on a P2 site detected via stylesheet.
222+
*
223+
* Status\Host::is_p2_site() short-circuits to false unless get_wpcom_site_id()
224+
* returns a value, so define IS_WPCOM to route through get_current_blog_id().
225+
*
226+
* @runInSeparateProcess
227+
* @preserveGlobalState disabled
222228
*/
229+
#[RunInSeparateProcess]
230+
#[PreserveGlobalState( false )]
223231
public function test_should_load_returns_false_on_p2_site_via_stylesheet() {
232+
if ( ! defined( 'IS_WPCOM' ) ) {
233+
define( 'IS_WPCOM', true );
234+
}
235+
236+
add_filter( 'stylesheet', static fn () => 'pub/p2-2020' );
237+
224238
$this->set_admin_context();
225239
$this->create_and_login_user();
226240

227-
$stylesheet_filter = static fn () => 'pub/p2-2020';
228-
add_filter( 'stylesheet', $stylesheet_filter );
229-
230-
try {
231-
$this->assertFalse( $this->call_private_method( 'should_load' ) );
232-
} finally {
233-
remove_filter( 'stylesheet', $stylesheet_filter );
234-
}
241+
$this->assertFalse( $this->call_private_method( 'should_load' ) );
235242
}
236243

237244
/**
@@ -243,6 +250,10 @@ public function test_should_load_returns_false_on_p2_site_via_stylesheet() {
243250
#[RunInSeparateProcess]
244251
#[PreserveGlobalState( false )]
245252
public function test_should_load_returns_false_on_p2_site_via_wpforteams() {
253+
if ( ! defined( 'IS_WPCOM' ) ) {
254+
define( 'IS_WPCOM', true );
255+
}
256+
246257
require_once __DIR__ . '/fixtures/wpforteams-stub.php';
247258

248259
$this->set_admin_context();

0 commit comments

Comments
 (0)