Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
95.45% covered (success)
95.45%
21 / 22
66.67% covered (warning)
66.67%
2 / 3
CRAP
n/a
0 / 0
Automattic\Jetpack\Jetpack_Mu_Wpcom\Jetpack_AI_Hub\configure
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
Automattic\Jetpack\Jetpack_Mu_Wpcom\Jetpack_AI_Hub\enable_scheduled_tasks
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
Automattic\Jetpack\Jetpack_Mu_Wpcom\Jetpack_AI_Hub\register
90.91% covered (success)
90.91%
10 / 11
0.00% covered (danger)
0.00%
0 / 1
5.02
1<?php
2/**
3 * WordPress.com Simple integration for the Jetpack AI Hub.
4 *
5 * @package automattic/jetpack-mu-wpcom
6 */
7
8namespace Automattic\Jetpack\Jetpack_Mu_Wpcom\Jetpack_AI_Hub;
9
10/**
11 * Point the upstream Hub at WordPress.com's native site-scoped MCP API.
12 *
13 * @param array $config Upstream AI Hub host configuration.
14 * @return array WordPress.com Simple configuration.
15 */
16function configure( $config ) {
17    $blog_id = get_current_blog_id();
18
19    $config['showGatedViews']  = false;
20    $config['isUserConnected'] = true;
21    $config['mcpSettingsApi']  = array(
22        'path'   => '/wpcom/v2/sites/' . $blog_id . '/mcp-abilities',
23        'format' => 'wpcom',
24    );
25
26    return $config;
27}
28
29/**
30 * Enable Scheduled tasks for sites with the Scheduled tasks sticker.
31 *
32 * @param bool $enabled Whether the flag is already enabled.
33 * @return bool Whether Scheduled tasks are enabled.
34 */
35function enable_scheduled_tasks( $enabled ) {
36    return $enabled || wpcom_has_blog_sticker( 'wpcom-agent-scheduled-tasks', get_wpcom_blog_id() );
37}
38
39add_filter( 'jetpack_feature_flag_enabled_ai-hub-scheduled-tasks', __NAMESPACE__ . '\\enable_scheduled_tasks' );
40
41/**
42 * Register the upstream AI Hub page on WordPress.com Simple.
43 */
44function register() {
45    if ( ! defined( 'JETPACK__PLUGIN_DIR' ) ) {
46        return;
47    }
48
49    $page_path = JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class-jetpack-ai-page.php';
50    if ( ! file_exists( $page_path ) ) {
51        return;
52    }
53
54    require_once $page_path;
55    // @phan-suppress-next-line PhanUndeclaredClassReference -- loaded from the sibling Jetpack plugin above and guarded at runtime.
56    if ( ! class_exists( '\Jetpack_AI_Page' ) || ! method_exists( '\Jetpack_AI_Page', 'add_actions' ) ) {
57        return;
58    }
59
60    add_filter( 'jetpack_ai_admin_config', __NAMESPACE__ . '\\configure' );
61
62    // @phan-suppress-next-line PhanUndeclaredClassMethod -- loaded from the sibling Jetpack plugin above and guarded at runtime.
63    $page = new \Jetpack_AI_Page();
64    // @phan-suppress-next-line PhanUndeclaredClassInCallable -- loaded from the sibling Jetpack plugin above and guarded at runtime.
65    add_action( 'admin_menu', array( $page, 'add_actions' ), 998 );
66}
67
68register();