Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.00% covered (warning)
80.00%
4 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
n/a
0 / 0
wpcom_agents_manager_is_wordpress_agent_enabled
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
wpcom_agents_manager_enable_in_block_editor
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Loads the Agents Manager in the block editor on WordPress.com sites with the WordPress Agent enabled.
4 *
5 * The Agents Manager package is a neutral loader: it only mounts in the block
6 * editor when a host answers the `agents_manager_enabled_in_block_editor`
7 * filter. This is the WordPress.com answer, so it no longer depends on the
8 * Big Sky plugin being loaded.
9 *
10 * @package automattic/jetpack-mu-wpcom
11 */
12
13/**
14 * Whether the WordPress Agent is enabled on this site.
15 *
16 * The `big_sky_enable` option is read on both platforms, but it means
17 * different things. On Simple it is the admin's opt-out under Settings >
18 * Writing, so it defaults to on and the platform's `big_sky_is_enabled()`
19 * (blog sticker, Garden sites, AI-assembler onboarding) owns the site-level
20 * setting. On Atomic it is the site-level setting itself: WordPress.com writes
21 * it to the site when the WordPress Agent is switched on, and the plugin
22 * clears it on deactivation. The `big-sky-enabled` blog sticker is not synced
23 * to Atomic, so it cannot be used there.
24 *
25 * @return bool
26 */
27function wpcom_agents_manager_is_wordpress_agent_enabled(): bool {
28    if ( function_exists( 'big_sky_is_enabled' ) ) {
29        // @phan-suppress-next-line PhanUndeclaredFunction -- Provided by WPCOM's Big Sky mu-plugin; guarded by function_exists() above.
30        return (bool) get_option( 'big_sky_enable', '1' ) && (bool) big_sky_is_enabled();
31    }
32
33    return (bool) get_option( 'big_sky_enable', '0' );
34}
35
36/**
37 * Enable the Agents Manager in the block editor when the WordPress Agent is on.
38 *
39 * Preserves an existing true so other integrations (such as the Jetpack AI
40 * Sidebar) can request the shell independently.
41 *
42 * @param mixed $enabled Whether an earlier filter already enabled it.
43 * @return bool
44 */
45function wpcom_agents_manager_enable_in_block_editor( $enabled ): bool {
46    return (bool) $enabled || wpcom_agents_manager_is_wordpress_agent_enabled();
47}
48add_filter( 'agents_manager_enabled_in_block_editor', 'wpcom_agents_manager_enable_in_block_editor' );