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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Agents Manager: Add `agents_manager_enqueue_in_block_editor` filter to allow preventing enqueue in block editor contexts.
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,23 @@ private function get_variant() {
* @return bool
*/
private function is_enabled() {
// Allow environments (e.g. CIAB) to prevent loading in block editor contexts
// where agents-manager is already running from the parent page.
/**
* Filter whether to enqueue Agents Manager assets inside the block editor iframe.
*
* This allows environments that already run Agents Manager from the parent page
* to disable enqueueing a second instance within the block editor context.
*
* @param bool $enqueue_in_block_editor Whether to enqueue Agents Manager assets
* in the block editor iframe. Default true.
*
* @return bool Whether to enqueue Agents Manager assets in the block editor iframe.
*/
if ( $this->is_block_editor() && ! apply_filters( 'agents_manager_enqueue_in_block_editor', true ) ) {
return false;
Comment on lines +327 to +328
Copy link
Member

@jom jom Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In https://github.com/Automattic/big-sky-plugin/pull/5700/ and https://github.com/Automattic/big-sky-plugin/pull/5700/, I was going to add a filter, but I think I could make this approach here work if we adjust it like this.

Never mind! I'm going to switch it to agents_manager_enabled_in_block_editor for my filter because it serves a different purpose and then it'll complement this nicely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that an approval then? 🍏 ? @jom

}

// Full unified experience: Agents Manager with support guides, Help Center takeover, etc.
if ( apply_filters( 'agents_manager_use_unified_experience', false ) ) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,44 @@ public function test_should_enqueue_script_preview_check_takes_precedence_over_u
$this->assertFalse( $result );
}

/**
* Tests that should_enqueue_script returns false in block editor when
* agents_manager_enqueue_in_block_editor filter returns false.
*
* This allows environments like CIAB to prevent duplicate loading when
* agents-manager is already running from the parent page.
*/
public function test_should_enqueue_script_returns_false_in_block_editor_when_filter_disables_it() {
require_once ABSPATH . 'wp-admin/includes/screen.php';

// Set up block editor context.
set_current_screen( 'post' );
$screen = get_current_screen();

// Use reflection to set the is_block_editor property.
$reflection = new \ReflectionClass( $screen );
$property = $reflection->getProperty( 'is_block_editor' );
if ( PHP_VERSION_ID < 80100 ) {
$property->setAccessible( true );
}
$property->setValue( $screen, true );

$_SERVER['REQUEST_URI'] = '/wp-admin/post.php';

// Enable unified experience so should_enqueue_script() would otherwise return true,
// ensuring this test actually exercises the agents_manager_enqueue_in_block_editor filter.
add_filter( 'agents_manager_use_unified_experience', '__return_true', 20 );
// Disable enqueue in block editor via the new filter.
add_filter( 'agents_manager_enqueue_in_block_editor', '__return_false' );

$result = $this->call_should_enqueue_script();

remove_filter( 'agents_manager_use_unified_experience', '__return_true', 20 );
remove_filter( 'agents_manager_enqueue_in_block_editor', '__return_false' );

$this->assertFalse( $result );
}

/**
* Helper to call the private get_current_user_data method via reflection.
*
Expand Down