array( 'type' => 'string', 'description' => __( 'Module slug, e.g. "analytics-4", "search-console", "tagmanager". List them with site-kit/list-modules.', 'acrossai-abilities-manager' ), ), 'settings' => array( 'type' => 'object', 'additionalProperties' => true, 'description' => __( 'The keys to change and their new values. Only keys the module already stores are written; the rest are reported as ignored. Read the writable set with site-kit/get-module-settings.', 'acrossai-abilities-manager' ), ), ); } protected function output_properties(): array { return array( 'slug' => array( 'type' => 'string' ), 'changed' => array( 'type' => 'array', 'description' => __( 'One entry per setting that actually moved, each with its name and its old and new value read back from Site Kit after the write.', 'acrossai-abilities-manager' ), ), 'unchanged' => array( 'type' => 'array', 'description' => __( 'Keys that were written but held the same value, or whose value Site Kit\'s own sanitiser rejected.', 'acrossai-abilities-manager' ), ), 'ignored' => array( 'type' => 'array', 'description' => __( 'Keys that do not exist on this module and were not written. Usually a typo.', 'acrossai-abilities-manager' ), ), 'owner_changed' => array( 'type' => 'boolean' ), 'owner_id' => array( 'type' => array( 'integer', 'null' ) ), 'settings' => array( 'type' => 'object' ), ); } /** * 'confirm' is intentionally absent — see Base_Site_Kit_Ability::ability(). */ protected function required_input(): array { return array( 'module', 'settings' ); } 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 ( ! isset( $input['settings'] ) || ! is_array( $input['settings'] ) ) { return new WP_Error( 'invalid_input', __( 'settings must be an object of keys to change.', 'acrossai-abilities-manager' ) ); } $result = Settings_Writer::update( $slug, $input['settings'] ); if ( is_wp_error( $result ) ) { return $result; } $parts = array(); $parts[] = array() === $result['changed'] ? sprintf( /* translators: %s: module slug */ __( 'Nothing changed on the Site Kit "%s" module — every key already held the value given.', 'acrossai-abilities-manager' ), $slug ) : sprintf( /* translators: 1: number of keys changed, 2: module slug, 3: comma-separated key names */ __( 'Changed %1$d setting(s) on the Site Kit "%2$s" module: %3$s.', 'acrossai-abilities-manager' ), count( $result['changed'] ), $slug, implode( ', ', array_column( $result['changed'], 'setting' ) ) ); if ( array() !== $result['ignored'] ) { $parts[] = sprintf( /* translators: %s: comma-separated list of ignored keys */ __( 'Ignored %s — no such setting on this module.', 'acrossai-abilities-manager' ), implode( ', ', $result['ignored'] ) ); } if ( $result['owner_changed'] ) { $parts[] = __( 'Site Kit moved this module\'s owner to the current user, because a connection setting changed. Anyone reading this module through a shared dashboard now does so with that user\'s Google credentials.', 'acrossai-abilities-manager' ); } $result['message'] = implode( ' ', $parts ); return $result; } }