array( 'type' => 'string', 'enum' => array( 'post', 'term' ), 'default' => 'post', 'description' => __( 'Whether the ids are posts or terms.', 'acrossai-abilities-manager' ), ), 'rows' => array( 'type' => 'object', 'description' => __( 'Object id => { column: value }. Allowed columns: focus_keyword, title, description, image_alt, image_title.', 'acrossai-abilities-manager' ), 'additionalProperties' => true, ), ); } protected function output_properties(): array { return array( 'object_type' => array( 'type' => 'string' ), 'processed' => array( 'type' => 'array' ), 'skipped' => array( 'type' => 'array' ), ); } protected function required_input(): array { return array( 'rows' ); } protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => true ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { if ( ! isset( $input['rows'] ) || ! is_array( $input['rows'] ) ) { return new WP_Error( 'invalid_input', __( 'rows must be an object keyed by object id.', 'acrossai-abilities-manager' ) ); } $result = Post_Meta_Repository::bulk_update_meta( isset( $input['object_type'] ) ? sanitize_key( (string) $input['object_type'] ) : 'post', $input['rows'] ); if ( is_wp_error( $result ) ) { return $result; } $result['message'] = sprintf( /* translators: 1: number applied, 2: number skipped */ __( 'Applied %1$d rows, skipped %2$d.', 'acrossai-abilities-manager' ), count( $result['processed'] ), count( $result['skipped'] ) ); return $result; } }