Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
95.24% covered (success)
95.24%
20 / 21
50.00% covered (danger)
50.00%
1 / 2
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\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// Scheduled tasks are a WordPress.com-backed experience and should be visible
30// whenever the AI Hub integration is loaded on Simple sites.
31add_filter( 'jetpack_feature_flag_enabled_ai-hub-scheduled-tasks', '__return_true' );
32
33/**
34 * Register the upstream AI Hub page on WordPress.com Simple.
35 */
36function register() {
37    if ( ! defined( 'JETPACK__PLUGIN_DIR' ) ) {
38        return;
39    }
40
41    $page_path = JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class-jetpack-ai-page.php';
42    if ( ! file_exists( $page_path ) ) {
43        return;
44    }
45
46    require_once $page_path;
47    // @phan-suppress-next-line PhanUndeclaredClassReference -- loaded from the sibling Jetpack plugin above and guarded at runtime.
48    if ( ! class_exists( '\Jetpack_AI_Page' ) || ! method_exists( '\Jetpack_AI_Page', 'add_actions' ) ) {
49        return;
50    }
51
52    add_filter( 'jetpack_ai_admin_config', __NAMESPACE__ . '\\configure' );
53
54    // @phan-suppress-next-line PhanUndeclaredClassMethod -- loaded from the sibling Jetpack plugin above and guarded at runtime.
55    $page = new \Jetpack_AI_Page();
56    // @phan-suppress-next-line PhanUndeclaredClassInCallable -- loaded from the sibling Jetpack plugin above and guarded at runtime.
57    add_action( 'admin_menu', array( $page, 'add_actions' ), 998 );
58}
59
60register();