From 9ead2367cca620fd1c540b928224b601ce9b0317 Mon Sep 17 00:00:00 2001 From: Katrina Tantay Date: Tue, 30 Jun 2026 10:20:57 -0500 Subject: [PATCH 1/2] Search Dashboard: Hide AI Agent Access on P2 sites --- .../changelog/remove-p2-ai-agent-access | 4 ++ .../src/dashboard/class-initial-state.php | 6 +-- .../search/tests/php/Initial_State_Test.php | 40 +++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 projects/packages/search/changelog/remove-p2-ai-agent-access diff --git a/projects/packages/search/changelog/remove-p2-ai-agent-access b/projects/packages/search/changelog/remove-p2-ai-agent-access new file mode 100644 index 000000000000..211966342fb1 --- /dev/null +++ b/projects/packages/search/changelog/remove-p2-ai-agent-access @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Search Dashboard: Hide AI Agent Access on P2 sites. diff --git a/projects/packages/search/src/dashboard/class-initial-state.php b/projects/packages/search/src/dashboard/class-initial-state.php index 657a496098b5..e6bdfa598424 100644 --- a/projects/packages/search/src/dashboard/class-initial-state.php +++ b/projects/packages/search/src/dashboard/class-initial-state.php @@ -9,6 +9,7 @@ use Automattic\Jetpack\Connection\Manager as Connection_Manager; use Automattic\Jetpack\Status; +use Automattic\Jetpack\Status\Host; use Jetpack_Options; /** @@ -220,13 +221,12 @@ protected function get_guidelines_url() { /** * Check whether the AI Agent Access toggle should be available. * - * Private sites are not eligible because external AI agents cannot read - * their public content. + * Private and P2 sites are not eligible for external AI agent access. * * @return bool */ protected function is_ai_agent_access_available() { - return ! $this->is_private_site(); + return ! $this->is_private_site() && ! ( new Host() )->is_p2_site(); } /** diff --git a/projects/packages/search/tests/php/Initial_State_Test.php b/projects/packages/search/tests/php/Initial_State_Test.php index e163bc16d532..5008dbe008e6 100644 --- a/projects/packages/search/tests/php/Initial_State_Test.php +++ b/projects/packages/search/tests/php/Initial_State_Test.php @@ -7,6 +7,7 @@ namespace Automattic\Jetpack\Search; +use Automattic\Jetpack\Constants; use Automattic\Jetpack\Search\TestCase as Search_TestCase; use PHPUnit\Framework\Attributes\CoversClass; @@ -139,6 +140,45 @@ public function test_ai_agent_access_available_is_false_for_private_sites() { $this->assertFalse( $state['siteData']['aiAgentAccessAvailable'] ); } + /** + * Test that the AI Agent Access toggle is unavailable on P2 sites. + */ + public function test_ai_agent_access_available_is_false_for_p2_sites() { + $original_blog_id = \Jetpack_Options::get_option( 'id' ); + $had_is_wpcom = Constants::is_defined( 'IS_WPCOM' ); + $original_is_wpcom = Constants::get_constant( 'IS_WPCOM' ); + $p2_stylesheet_filter = function () { + return 'pub/p2v2'; + }; + + \Jetpack_Options::update_option( 'id', 12345 ); + Constants::set_constant( 'IS_WPCOM', true ); + + try { + $state = ( new Initial_State() )->get_initial_state(); + + $this->assertTrue( $state['siteData']['aiAgentAccessAvailable'] ); + + add_filter( 'stylesheet', $p2_stylesheet_filter ); + + $state = ( new Initial_State() )->get_initial_state(); + + $this->assertFalse( $state['siteData']['aiAgentAccessAvailable'] ); + } finally { + remove_filter( 'stylesheet', $p2_stylesheet_filter ); + if ( false === $original_blog_id ) { + \Jetpack_Options::delete_option( 'id' ); + } else { + \Jetpack_Options::update_option( 'id', $original_blog_id ); + } + if ( $had_is_wpcom ) { + Constants::set_constant( 'IS_WPCOM', $original_is_wpcom ); + } else { + Constants::clear_single_constant( 'IS_WPCOM' ); + } + } + } + /** * Unregister the Guidelines admin page from the menu globals. */ From 7b1f844f6a971e7f66767b8b63ed158d0d295c72 Mon Sep 17 00:00:00 2001 From: Katrina Tantay Date: Tue, 30 Jun 2026 12:18:43 -0500 Subject: [PATCH 2/2] Fix Search initial state PHPCS alignment --- projects/packages/search/tests/php/Initial_State_Test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/packages/search/tests/php/Initial_State_Test.php b/projects/packages/search/tests/php/Initial_State_Test.php index 5008dbe008e6..a9a6fec5ad1d 100644 --- a/projects/packages/search/tests/php/Initial_State_Test.php +++ b/projects/packages/search/tests/php/Initial_State_Test.php @@ -144,10 +144,10 @@ public function test_ai_agent_access_available_is_false_for_private_sites() { * Test that the AI Agent Access toggle is unavailable on P2 sites. */ public function test_ai_agent_access_available_is_false_for_p2_sites() { - $original_blog_id = \Jetpack_Options::get_option( 'id' ); - $had_is_wpcom = Constants::is_defined( 'IS_WPCOM' ); - $original_is_wpcom = Constants::get_constant( 'IS_WPCOM' ); - $p2_stylesheet_filter = function () { + $original_blog_id = \Jetpack_Options::get_option( 'id' ); + $had_is_wpcom = Constants::is_defined( 'IS_WPCOM' ); + $original_is_wpcom = Constants::get_constant( 'IS_WPCOM' ); + $p2_stylesheet_filter = function () { return 'pub/p2v2'; };