diff --git a/lib/blocks.php b/lib/blocks.php index 8185567db1b804..e98f711b5c85a5 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -372,3 +372,31 @@ function gutenberg_register_legacy_social_link_blocks() { } add_action( 'init', 'gutenberg_register_legacy_social_link_blocks' ); + +/** + * Migrate the legacy `sync_status` meta key (added 16.1) to the new `wp_pattern_sync_status` meta key (16.1.1). + * + * This filter is INTENTIONALLY left out of core as the meta key was fist introduced to core in 6.3 as `wp_pattern_sync_status`. + * see https://github.com/WordPress/gutenberg/pull/52232 + * + * @param mixed $value The value to return, either a single metadata value or an array of values depending on the value of $single. + * @param int $object_id ID of the object metadata is for. + * @param string $meta_key Metadata key. + * @param bool $single Whether to return only the first value of the specified $meta_key. + */ +function gutenberg_legacy_wp_block_post_meta( $value, $object_id, $meta_key, $single ) { + if ( 'wp_pattern_sync_status' !== $meta_key ) { + return $value; + } + + $sync_status = get_post_meta( $object_id, 'sync_status', $single ); + + if ( $single && 'unsynced' === $sync_status ) { + return $sync_status; + } elseif ( isset( $sync_status[0] ) && 'unsynced' === $sync_status[0] ) { + return $sync_status; + } + + return $value; +} +add_filter( 'default_post_metadata', 'gutenberg_legacy_wp_block_post_meta', 10, 4 ); diff --git a/lib/compat/wordpress-6.3/blocks.php b/lib/compat/wordpress-6.3/blocks.php index b338d0a2467096..a3a46f3f545f45 100644 --- a/lib/compat/wordpress-6.3/blocks.php +++ b/lib/compat/wordpress-6.3/blocks.php @@ -89,7 +89,7 @@ function gutenberg_add_custom_fields_to_wp_block( $args, $post_type ) { add_filter( 'register_post_type_args', 'gutenberg_add_custom_fields_to_wp_block', 10, 2 ); /** - * Adds sync_status meta fields to the wp_block post type so an unsynced option can be added. + * Adds wp_pattern_sync_status meta fields to the wp_block post type so an unsynced option can be added. * * Note: This should be removed when the minimum required WP version is >= 6.3. * @@ -101,7 +101,7 @@ function gutenberg_wp_block_register_post_meta() { $post_type = 'wp_block'; register_post_meta( $post_type, - 'sync_status', + 'wp_pattern_sync_status', array( 'auth_callback' => function() { return current_user_can( 'edit_posts' ); @@ -113,7 +113,7 @@ function gutenberg_wp_block_register_post_meta() { 'schema' => array( 'type' => 'string', 'properties' => array( - 'sync_status' => array( + 'wp_pattern_sync_status' => array( 'type' => 'string', ), ), @@ -123,7 +123,7 @@ function gutenberg_wp_block_register_post_meta() { ); } /** - * Sanitizes the array of wp_block post meta sync_status string. + * Sanitizes the array of wp_block post meta wp_pattern_sync_status string. * * Note: This should be removed when the minimum required WP version is >= 6.3. * diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 1ab3606ba68963..616e81135d6821 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -2045,11 +2045,13 @@ export const getInserterItems = createSelector( ? getReusableBlocks( state ) .filter( ( reusableBlock ) => - syncStatus === reusableBlock.meta?.sync_status || + syncStatus === + reusableBlock.meta?.wp_pattern_sync_status || ( ! syncStatus && - ( reusableBlock.meta?.sync_status === '' || - reusableBlock.meta?.sync_status === - 'fully' ) ) // Only reusable blocks added via site editor in release 16.1 will have sync_status of 'fully'. + ( reusableBlock.meta?.wp_pattern_sync_status === + '' || + reusableBlock.meta + ?.wp_pattern_sync_status === 'fully' ) ) // Only reusable blocks added via site editor in release 16.1 will have wp_pattern_sync_status of 'fully'. ) .map( buildReusableBlockInserterItem ) : []; diff --git a/packages/edit-site/src/components/create-pattern-modal/index.js b/packages/edit-site/src/components/create-pattern-modal/index.js index 5180ad5d870684..4be54b12ab030b 100644 --- a/packages/edit-site/src/components/create-pattern-modal/index.js +++ b/packages/edit-site/src/components/create-pattern-modal/index.js @@ -56,7 +56,7 @@ export default function CreatePatternModal( { status: 'publish', meta: syncType === SYNC_TYPES.unsynced - ? { sync_status: syncType } + ? { wp_pattern_sync_status: syncType } : undefined, }, { throwOnError: true } diff --git a/packages/edit-site/src/components/page-library/use-patterns.js b/packages/edit-site/src/components/page-library/use-patterns.js index 6f3b7407e917dd..507417021688a7 100644 --- a/packages/edit-site/src/components/page-library/use-patterns.js +++ b/packages/edit-site/src/components/page-library/use-patterns.js @@ -145,7 +145,7 @@ const reusableBlockToPattern = ( reusableBlock ) => ( { categories: reusableBlock.wp_pattern, id: reusableBlock.id, name: reusableBlock.slug, - syncStatus: reusableBlock.meta?.sync_status || SYNC_TYPES.full, + syncStatus: reusableBlock.meta?.wp_pattern_sync_status || SYNC_TYPES.full, title: reusableBlock.title.raw, type: reusableBlock.type, reusableBlock, diff --git a/packages/editor/src/components/post-sync-status/index.js b/packages/editor/src/components/post-sync-status/index.js index c384fd234c7a34..a3a1896f1093ee 100644 --- a/packages/editor/src/components/post-sync-status/index.js +++ b/packages/editor/src/components/post-sync-status/index.js @@ -21,7 +21,7 @@ export default function PostSyncStatus() { if ( postType !== 'wp_block' ) { return null; } - const syncStatus = meta?.sync_status; + const syncStatus = meta?.wp_pattern_sync_status; const isFullySynced = ! syncStatus; return ( diff --git a/packages/reusable-blocks/src/store/actions.js b/packages/reusable-blocks/src/store/actions.js index aae706adfab36a..17a2e83d5e776a 100644 --- a/packages/reusable-blocks/src/store/actions.js +++ b/packages/reusable-blocks/src/store/actions.js @@ -52,7 +52,7 @@ export const __experimentalConvertBlocksToReusable = const meta = syncType === 'unsynced' ? { - sync_status: syncType, + wp_pattern_sync_status: syncType, } : undefined;