From e8311f3e79b00faf0d4bdfa649ffe9d779c8b591 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Thu, 29 Jun 2023 17:16:45 +1200 Subject: [PATCH 1/4] Expose new wp_block sync_status as top level rest property instead of postmeta --- .../rest-api/endpoints/class-wp-rest-posts-controller.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 76ca226c59156..db58267dd442d 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -1931,10 +1931,15 @@ public function prepare_item_for_response( $item, $request ) { } } - if ( rest_is_field_included( 'meta', $fields ) ) { + if ( rest_is_field_included( 'meta', $fields ) && 'wp_block' !== $this->post_type ) { $data['meta'] = $this->meta->get_value( $post->ID, $request ); } + if ( 'wp_block' === $this->post_type ) { + $wp_block_meta = $this->meta->get_value( $post->ID, $request ); + $data['sync_status'] = $wp_block_meta['sync_status']; + } + $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); foreach ( $taxonomies as $taxonomy ) { From 9acd6dc4273dee1531ad624a9bab994f37416fb0 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Thu, 29 Jun 2023 17:28:23 +1200 Subject: [PATCH 2/4] Only move the sync_status field so plugins can still add additional postmeta --- .../rest-api/endpoints/class-wp-rest-posts-controller.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index db58267dd442d..babbacda407a1 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -1931,11 +1931,12 @@ public function prepare_item_for_response( $item, $request ) { } } - if ( rest_is_field_included( 'meta', $fields ) && 'wp_block' !== $this->post_type ) { + if ( rest_is_field_included( 'meta', $fields )) { $data['meta'] = $this->meta->get_value( $post->ID, $request ); } if ( 'wp_block' === $this->post_type ) { + unset($data['meta']['sync_status']); $wp_block_meta = $this->meta->get_value( $post->ID, $request ); $data['sync_status'] = $wp_block_meta['sync_status']; } From 626f8fe3084445c5ffe5c36633ef9405bfc49e68 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Thu, 29 Jun 2023 17:29:35 +1200 Subject: [PATCH 3/4] add missing space --- .../rest-api/endpoints/class-wp-rest-posts-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index babbacda407a1..f4dca6c97c8c4 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -1931,7 +1931,7 @@ public function prepare_item_for_response( $item, $request ) { } } - if ( rest_is_field_included( 'meta', $fields )) { + if ( rest_is_field_included( 'meta', $fields ) ) { $data['meta'] = $this->meta->get_value( $post->ID, $request ); } From b2bb9ecedd38b81d6ea350094a41d4fb9dbda531 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Thu, 29 Jun 2023 17:37:44 +1200 Subject: [PATCH 4/4] fix linting issues --- .../rest-api/endpoints/class-wp-rest-posts-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index f4dca6c97c8c4..0656a2f3a4296 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -1936,7 +1936,7 @@ public function prepare_item_for_response( $item, $request ) { } if ( 'wp_block' === $this->post_type ) { - unset($data['meta']['sync_status']); + unset( $data['meta']['sync_status'] ); $wp_block_meta = $this->meta->get_value( $post->ID, $request ); $data['sync_status'] = $wp_block_meta['sync_status']; }