array( 'type' => 'integer', 'minimum' => 1, 'description' => __( 'Post holding the block.', 'acrossai-abilities-manager' ), ), 'path' => array( 'type' => 'array', 'items' => array( 'type' => 'integer' ), 'description' => __( 'Block path as reported by blocks/outline-post-blocks, e.g. [2] or [1, 0].', 'acrossai-abilities-manager' ), ), 'data' => array( 'type' => 'object', 'description' => __( 'Field name => new value.', 'acrossai-abilities-manager' ), ), 'replace' => array( 'type' => 'boolean', 'default' => false, 'description' => __( 'Replace the whole data payload rather than merging into it.', 'acrossai-abilities-manager' ), ), ); } protected function required_input(): array { return array( 'post_id', 'path', 'data', ); } protected function output_properties(): array { return array( 'post_id' => array( 'type' => 'integer' ), 'data' => array( 'type' => 'object' ), ); } protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => true, ); } protected function run( array $input ) { $post_id = (int) $input['post_id']; $path = isset( $input['path'] ) && is_array( $input['path'] ) ? array_map( 'intval', $input['path'] ) : array(); $data = isset( $input['data'] ) && is_array( $input['data'] ) ? $input['data'] : array(); $replace = ! empty( $input['replace'] ); $updated = Block_Repository::update_data( $post_id, $path, (array) Slash_Input::slash( $data, $input ), $replace ); if ( is_wp_error( $updated ) ) { return $updated; } return array( 'post_id' => $post_id, 'data' => $updated, 'message' => sprintf( /* translators: 1: post id, 2: block path */ __( 'Updated the ACF block at path [%2$s] in post %1$d.', 'acrossai-abilities-manager' ), $post_id, implode( ', ', array_map( 'strval', $path ) ) ), ); } }