Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
15 / 18
66.67% covered (warning)
66.67%
2 / 3
CRAP
n/a
0 / 0
wpcomsh_jetpack_ai_module_seed_min_site_id
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
wpcomsh_jetpack_ai_module_seed_max_site_id
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
wpcomsh_seed_jetpack_ai_module
86.67% covered (warning)
86.67%
13 / 15
0.00% covered (danger)
0.00%
0 / 1
11.29
1<?php
2/**
3 * Turns the Jetpack AI module on, once, for sites transferred from Simple before the
4 * transfer seeded it. Delete this file and its require once the window has been covered.
5 *
6 * @package wpcomsh
7 */
8
9/**
10 * Sites below this got the module from the 16.2-a.3 upgrade (ATOMIC-1187, 25 Aug 2026).
11 *
12 * @return int
13 */
14function wpcomsh_jetpack_ai_module_seed_min_site_id() {
15    return 152102830;
16}
17
18/**
19 * Sites above this were seeded at transfer by wpcom #247252 (7 Oct 2026).
20 *
21 * @return int
22 */
23function wpcomsh_jetpack_ai_module_seed_max_site_id() {
24    return 152227154;
25}
26
27/**
28 * Activate the AI module once per site. A disconnected site or a refused activation
29 * leaves no marker and retries later; a reported activation is final.
30 *
31 * @param int|null $client_id Atomic client ID. Defaults to the site's own.
32 * @param int|null $site_id   Atomic site ID. Defaults to the site's own.
33 */
34function wpcomsh_seed_jetpack_ai_module( $client_id = null, $site_id = null ) {
35    if ( null === $client_id ) {
36        $client_id = wpcomsh_get_atomic_client_id();
37    }
38    if ( null === $site_id ) {
39        $site_id = wpcomsh_get_atomic_site_id();
40    }
41
42    // WoA only: e2e and Jurassic Ninja sites test the module's enforcement.
43    if ( WPCOMSH_WPCOM_ATOMIC_CLIENT_ID !== (int) $client_id ) {
44        return;
45    }
46
47    $site_id = (int) $site_id;
48    if ( $site_id < wpcomsh_jetpack_ai_module_seed_min_site_id() || $site_id > wpcomsh_jetpack_ai_module_seed_max_site_id() ) {
49        return;
50    }
51
52    if ( get_option( 'wpcomsh_jetpack_ai_module_seeded' ) ) {
53        return;
54    }
55
56    if ( ! class_exists( 'Jetpack' ) || ! Jetpack::is_connection_ready() ) {
57        return;
58    }
59
60    // A filter can hide the module after a successful activation; that is an override to respect, not a retry.
61    if ( Jetpack::is_module_active( 'ai' ) || Jetpack::activate_module( 'ai', false, false ) ) {
62        update_option( 'wpcomsh_jetpack_ai_module_seeded', true );
63    }
64}
65add_action( 'init', 'wpcomsh_seed_jetpack_ai_module', 0, 0 );