Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.00% covered (warning)
80.00%
16 / 20
100.00% covered (success)
100.00%
1 / 1
CRAP
n/a
0 / 0
Automattic\Jetpack\Extensions\Content_Lens\register_plugin
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
6
1<?php
2/**
3 * Block Editor - AI Assistant plugin feature.
4 *
5 * @package automattic/jetpack
6 */
7
8namespace Automattic\Jetpack\Extensions\Content_Lens;
9
10use Automattic\Jetpack\Connection\Manager as Connection_Manager;
11use Automattic\Jetpack\Status;
12use Automattic\Jetpack\Status\Host;
13
14if ( ! defined( 'ABSPATH' ) ) {
15    exit( 0 );
16}
17
18// Required directly rather than relying on the plugin bootstrap: on
19// WordPress.com Simple the extension files load through wpcom's own loader
20// and load-jetpack.php never runs.
21require_once __DIR__ . '/../../../_inc/lib/class-jetpack-ai-settings.php';
22
23// Feature name.
24const FEATURE_NAME = 'ai-content-lens';
25
26/**
27 * Register the AI Content Lens plugin.
28 * The feature is only available on sites
29 * with a working connection to WordPress.com.
30 *
31 * @return void
32 */
33function register_plugin() {
34    // Connection check, plus the AI master switch and the writing toggle that
35    // owns the excerpt generator on the AI settings page.
36    if (
37        (
38            ( new Host() )->is_wpcom_simple()
39            || ( ( new Connection_Manager( 'jetpack' ) )->has_connected_owner() && ! ( new Status() )->is_offline_mode() )
40        )
41        && \Jetpack_AI_Settings::is_ai_enabled()
42        && \Jetpack_AI_Settings::is_feature_enabled( 'writing_assistant' )
43    ) {
44        // Register AI Content lens plugin.
45        \Jetpack_Gutenberg::set_extension_available( FEATURE_NAME );
46    }
47}
48add_action( 'jetpack_register_gutenberg_extensions', __NAMESPACE__ . '\register_plugin' );
49
50// Populate the available extensions with ai-content-lens.
51add_filter(
52    'jetpack_set_available_extensions',
53    function ( $extensions ) {
54        return array_merge(
55            (array) $extensions,
56            array(
57                FEATURE_NAME,
58            )
59        );
60    }
61);