PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 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 All 507 releases
← All changes | extensions/blocks/ai-chat/ai-chat.php +26 -13 16.3-a.3 → 16.3-beta View file →
@@ -9,14 +9,11 @@
9 9
10 10 namespace Automattic\Jetpack\Extensions\AIChat;
11 11
12 12 use Automattic\Jetpack\Blocks;
13 -use Automattic\Jetpack\Connection\Manager as Connection_Manager;
14 13 use Automattic\Jetpack\Search\Module_Control as Search_Module_Control;
15 14 use Automattic\Jetpack\Search\Plan as Search_Plan;
16 15 use Automattic\Jetpack\Search\Search_Blocks;
17 -use Automattic\Jetpack\Status;
18 -use Automattic\Jetpack\Status\Host;
19 16 use Jetpack_Gutenberg;
20 17
21 18 if ( ! defined( 'ABSPATH' ) ) {
22 19 exit( 0 );
@@ -33,18 +30,28 @@
33 30 * This is done via an action so that we can disable
34 31 * registration if we need to.
35 32 */
36 33 function register_block() {
37 - if (
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()
43 - ) {
44 - Blocks::jetpack_register_block(
45 - __DIR__,
46 - array( 'render_callback' => __NAMESPACE__ . '\load_assets' )
34 + if ( ! \Jetpack_AI_Settings::site_is_connected() ) {
35 + return;
36 + }
37 +
38 + // The block stays registered while Jetpack AI is off so the render callback
39 + // runs and can output nothing. Otherwise WordPress echoes the saved markup,
40 + // an empty div, wherever the block sits.
41 + Blocks::jetpack_register_block(
42 + __DIR__,
43 + array( 'render_callback' => __NAMESPACE__ . '\load_assets' )
44 + );
45 +
46 + // Registration queues its own "available" mark on this action, so run after it.
47 + if ( ! \Jetpack_AI_Settings::is_ai_enabled() ) {
48 + add_action(
49 + 'jetpack_register_gutenberg_extensions',
50 + static function () {
51 + Jetpack_Gutenberg::set_extension_unavailable( 'ai-chat', 'ai_disabled' );
52 + },
53 + 20
47 54 );
48 55 }
49 56 }
50 57 add_action( 'init', __NAMESPACE__ . '\register_block' );
@@ -56,8 +63,14 @@
56 63 *
57 64 * @return string
58 65 */
59 66 function load_assets( $attr ) {
67 + // With Jetpack AI off there is nothing to ask, so render nothing rather
68 + // than an empty container.
69 + if ( ! \Jetpack_AI_Settings::is_ai_enabled() ) {
70 + return '';
71 + }
72 +
60 73 /*
61 74 * Enqueue necessary scripts and styles.
62 75 */
63 76 Jetpack_Gutenberg::load_assets_as_required( __DIR__ );