array( 'type' => 'string', 'description' => __( 'Module slug, e.g. "analytics-4", "adsense", "tagmanager". List them with site-kit/list-modules.', 'acrossai-abilities-manager' ), ), 'active' => array( 'type' => 'boolean', 'description' => __( 'True to activate, false to deactivate.', 'acrossai-abilities-manager' ), ), ); } protected function output_properties(): array { return array( 'slug' => array( 'type' => 'string' ), 'active' => array( 'type' => 'boolean' ), 'changed' => array( 'type' => 'boolean' ), 'connected' => array( 'type' => 'boolean' ), ); } /** * 'confirm' is intentionally absent — see Base_Site_Kit_Ability::ability(). */ protected function required_input(): array { return array( 'module', 'active' ); } protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => true ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { $slug = isset( $input['module'] ) ? sanitize_key( (string) $input['module'] ) : ''; if ( '' === $slug ) { return new WP_Error( 'invalid_input', __( 'module is required. List the available slugs with site-kit/list-modules.', 'acrossai-abilities-manager' ) ); } if ( ! array_key_exists( 'active', $input ) ) { return new WP_Error( 'invalid_input', __( 'active is required: true to activate the module, false to deactivate it.', 'acrossai-abilities-manager' ) ); } $result = Module_Repository::set_module_state( $slug, (bool) $input['active'] ); if ( is_wp_error( $result ) ) { return $result; } if ( ! $result['changed'] ) { $result['message'] = sprintf( /* translators: 1: module slug, 2: state word */ __( 'The Site Kit "%1$s" module was already %2$s. Nothing changed.', 'acrossai-abilities-manager' ), $slug, $result['active'] ? __( 'active', 'acrossai-abilities-manager' ) : __( 'inactive', 'acrossai-abilities-manager' ) ); } elseif ( $result['active'] ) { $result['message'] = $result['connected'] ? sprintf( /* translators: %s: module slug */ __( 'Activated the Site Kit "%s" module. It is connected and can return data.', 'acrossai-abilities-manager' ), $slug ) : sprintf( /* translators: %s: module slug */ __( 'Activated the Site Kit "%s" module, but it is not connected yet — an administrator must choose its account and property at Site Kit → Settings before it returns data.', 'acrossai-abilities-manager' ), $slug ); } else { $result['message'] = sprintf( /* translators: %s: module slug */ __( 'Deactivated the Site Kit "%s" module. If it placed a tag on the site, that tag has stopped rendering and measurement stops from now.', 'acrossai-abilities-manager' ), $slug ); } return $result; } }