PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
← All changes | extensions/blocks/ai-chat/ai-chat.php +26 -6 13.2.4 → 16.3-a.5 View file →
@@ -12,12 +12,23 @@
12 12 use Automattic\Jetpack\Blocks;
13 13 use Automattic\Jetpack\Connection\Manager as Connection_Manager;
14 14 use Automattic\Jetpack\Search\Module_Control as Search_Module_Control;
15 15 use Automattic\Jetpack\Search\Plan as Search_Plan;
16 +use Automattic\Jetpack\Search\Search_Blocks;
16 17 use Automattic\Jetpack\Status;
17 18 use Automattic\Jetpack\Status\Host;
18 19 use Jetpack_Gutenberg;
19 20
21 +if ( ! defined( 'ABSPATH' ) ) {
22 + exit( 0 );
23 +}
24 +
25 +// Required directly rather than relying on the plugin bootstrap: on
26 +// WordPress.com Simple the extension files load through wpcom's own loader
27 +// and load-jetpack.php never runs. Without it the is_ai_enabled() master-gate
28 +// check below would fatal there.
29 +require_once __DIR__ . '/../../../_inc/lib/class-jetpack-ai-settings.php';
30 +
20 31 /**
21 32 * Registers our block for use in Gutenberg
22 33 * This is done via an action so that we can disable
23 34 * registration if we need to.
@@ -23,10 +34,13 @@
23 34 * registration if we need to.
24 35 */
25 36 function register_block() {
26 37 if (
27 - ( new Host() )->is_wpcom_simple()
28 - || ( ( new Connection_Manager( 'jetpack' ) )->has_connected_owner() && ! ( new Status() )->is_offline_mode() )
38 + (
39 + ( new Host() )->is_wpcom_simple()
40 + || ( ( new Connection_Manager( 'jetpack' ) )->has_connected_owner() && ! ( new Status() )->is_offline_mode() )
41 + )
42 + && \Jetpack_AI_Settings::is_ai_enabled()
29 43 ) {
30 44 Blocks::jetpack_register_block(
31 45 __DIR__,
32 46 array( 'render_callback' => __NAMESPACE__ . '\load_assets' )
@@ -47,10 +61,10 @@
47 61 * Enqueue necessary scripts and styles.
48 62 */
49 63 Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
50 64
51 - $ask_button_label = isset( $attr['askButtonLabel'] ) ? $attr['askButtonLabel'] : __( 'Ask', 'jetpack' );
52 - $placeholder = isset( $attr['placeholder'] ) ? $attr['placeholder'] : __( 'Ask a question about this site.', 'jetpack' );
65 + $ask_button_label = $attr['askButtonLabel'] ?? __( 'Ask', 'jetpack' );
66 + $placeholder = $attr['placeholder'] ?? __( 'Ask a question about this site.', 'jetpack' );
53 67
54 68 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
55 69 $blog_id = get_current_blog_id();
56 70 $type = 'wpcom'; // WPCOM simple sites.
@@ -83,15 +97,21 @@
83 97 $search = new Search_Module_Control();
84 98 $plan = new Search_Plan();
85 99 $initial_state = array(
86 100 'jetpackSettings' => array(
101 + // `module_active` reflects whether the Jetpack Search module is on, which is
102 + // what controls site indexing — independent of the chosen front-end experience
103 + // (Overlay / Theme / Inline / Embedded). The AI Chat block only needs the
104 + // index, so it gates on this rather than on `instant_search_enabled`.
105 + 'module_active' => $search->is_active(),
87 106 'instant_search_enabled' => $search->is_instant_search_enabled(),
88 107 'plan_supports_search' => $plan->supports_instant_search(),
108 + 'supports_paid_search' => Search_Blocks::supports_paid_search(),
89 109 ),
90 110 );
91 111 wp_add_inline_script(
92 112 'jetpack-blocks-editor',
93 - 'var Jetpack_AIChatBlock = ' . wp_json_encode( $initial_state, JSON_HEX_TAG | JSON_HEX_AMP ) . ';',
113 + 'var Jetpack_AIChatBlock = ' . wp_json_encode( $initial_state, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';',
94 114 'before'
95 115 );
96 116 }
97 -add_action( 'enqueue_block_assets', __NAMESPACE__ . '\add_ai_chat_block_data' );
117 +add_action( 'enqueue_block_assets', __NAMESPACE__ . '\add_ai_chat_block_data', 11 );