Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions projects/packages/search/changelog/remove-p2-ai-agent-access
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Search Dashboard: Hide AI Agent Access on P2 sites.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Status;
use Automattic\Jetpack\Status\Host;
use Jetpack_Options;

/**
Expand Down Expand Up @@ -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();
}

/**
Expand Down
40 changes: 40 additions & 0 deletions projects/packages/search/tests/php/Initial_State_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
*/
Expand Down
Loading