Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
16 / 20 |
|
100.00% |
1 / 1 |
CRAP | n/a |
0 / 0 |
|
| Automattic\Jetpack\Extensions\Content_Lens\register_plugin | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Block Editor - AI Assistant plugin feature. |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Extensions\Content_Lens; |
| 9 | |
| 10 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 11 | use Automattic\Jetpack\Status; |
| 12 | use Automattic\Jetpack\Status\Host; |
| 13 | |
| 14 | if ( ! 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. |
| 21 | require_once __DIR__ . '/../../../_inc/lib/class-jetpack-ai-settings.php'; |
| 22 | |
| 23 | // Feature name. |
| 24 | const 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 | */ |
| 33 | function 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 | } |
| 48 | add_action( 'jetpack_register_gutenberg_extensions', __NAMESPACE__ . '\register_plugin' ); |
| 49 | |
| 50 | // Populate the available extensions with ai-content-lens. |
| 51 | add_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 | ); |