Skip to content

Commit

Permalink
Editor: rename sync_status and move it to top level.
Browse files Browse the repository at this point in the history
Renames sync_status to wp_pattern_sync_status and moves it to top level field of wp_block post type.

Props glendaviesnz, aaronrobertshaw, mukesh27, peterwilsoncc.
Fixes 58677.


git-svn-id: https://develop.svn.wordpress.org/trunk@56160 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
tellthemachines committed Jul 7, 2023
1 parent f47b9a2 commit 7035b61
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -8041,14 +8041,14 @@ function use_block_editor_for_post_type( $post_type ) {
/**
* Registers any additional post meta fields.
*
* @since 6.3.0 Adds sync_status meta field to the wp_block post type so an unsynced option can be added.
* @since 6.3.0 Adds `wp_pattern_sync_status` meta field to the wp_block post type so an unsynced option can be added.
*
* @link https://github.com/WordPress/gutenberg/pull/51144
*/
function wp_create_initial_post_meta() {
register_post_meta(
'wp_block',
'sync_status',
'wp_pattern_sync_status',
array(
'sanitize_callback' => 'sanitize_text_field',
'single' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function check_read_permission( $post ) {
* Filters a response based on the context defined in the schema.
*
* @since 5.0.0
* @since 6.3 Adds the `wp_pattern_sync_status` postmeta property to the top level of response.
*
* @param array $data Response data to filter.
* @param string $context Context defined in the schema.
Expand All @@ -56,6 +57,9 @@ public function filter_response_by_context( $data, $context ) {
unset( $data['title']['rendered'] );
unset( $data['content']['rendered'] );

// Add the core wp_pattern_sync_status meta as top level property to the response.
$data['wp_pattern_sync_status'] = isset( $data['meta']['wp_pattern_sync_status'] ) ? $data['meta']['wp_pattern_sync_status'] : '';
unset( $data['meta']['wp_pattern_sync_status'] );
return $data;
}

Expand Down
35 changes: 35 additions & 0 deletions tests/phpunit/tests/rest-api/rest-blocks-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,39 @@ public function test_content() {
$data['content']
);
}

/**
* Check that the `wp_pattern_sync_status` postmeta is moved from meta array to top
* level of response.
*
* @ticket 58677
*/
public function test_wp_patterns_sync_status_post_meta() {
register_post_meta(
'wp_block',
'wp_pattern_sync_status',
array(
'single' => true,
'type' => 'string',
'show_in_rest' => array(
'schema' => array(
'type' => 'string',
'properties' => array(
'sync_status' => array(
'type' => 'string',
),
),
),
),
)
);
wp_set_current_user( self::$user_ids['author'] );

$request = new WP_REST_Request( 'GET', '/wp/v2/blocks/' . self::$post_id );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();

$this->assertArrayHasKey( 'wp_pattern_sync_status', $data );
$this->assertArrayNotHasKey( 'wp_pattern_sync_status', $data['meta'] );
}
}

0 comments on commit 7035b61

Please sign in to comment.