Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c845c41
add hint to show template part move (#52395)
SaxonF Jul 7, 2023
e36aae1
Page Content Focus: Ignore page content within a Query Loop block (#5…
noisysocks Jul 7, 2023
089d7fd
Patterns: stop endless snackbars appearing (#52012)
glendaviesnz Jul 6, 2023
ef51622
Patterns: Distinguish between theme patterns and template parts in ca…
jameskoster Jul 6, 2023
02fb4a7
Allow opt out of auto-creation of Navigation fallback (#52319)
getdave Jul 6, 2023
1fe426f
Update welcome guide copy (#52282)
jameskoster Jul 5, 2023
c522b12
Patterns: Update pattern copy (#52340)
jameskoster Jul 6, 2023
d376ba9
Post Title: The changes should be reflected when previewing a post (#…
Mamaduka Jul 6, 2023
7398771
Update fixed block toolbar (#52123)
draganescu Jul 5, 2023
5af8f46
Drop PHP 5.6 CI jobs (#52345)
hellofromtonya Jul 5, 2023
cc3841c
Patterns: Add handling of sync status to the wp-admin patterns list p…
glendaviesnz Jul 6, 2023
b9b4bfa
Exit template focus when opening the W menu (#52235)
noisysocks Jul 5, 2023
eb94b26
wrap buttons (#52249)
jameskoster Jul 5, 2023
ed76244
Update the behavior of the cached undo/redo stack (#51644)
youknowriad Jul 5, 2023
f060b18
Adjust top position (#52248)
jameskoster Jul 5, 2023
14bb146
Patterns: add a hint about the rename of reusable blocks to menu and …
glendaviesnz Jul 5, 2023
8dab0a0
Site Editor: update headings hierarchy in the 'Manage all' screens (#…
ramonjd Jul 5, 2023
d98464c
Check randomizer experiment is enabled before rendering button (#52306)
tellthemachines Jul 5, 2023
cd5be56
Hide parent selector when parent is 'disabled' or 'contentOnly' (#52264)
noisysocks Jul 5, 2023
4795e31
Fix incorrect aria-describedby attributes for theme patterns (#52263)
kevin940726 Jul 5, 2023
9e40ea9
Patterns: rename sync_status and move to top level field on rest retu…
glendaviesnz Jul 5, 2023
f03487a
Fix default block dimensions visibility (#52256)
Jul 4, 2023
9a99dd0
Patterns: Display all custom template part areas in sidebar nav (#52355)
aaronrobertshaw Jul 7, 2023
9dc955e
Revert phpcs back to PHP 5.6 (#52384)
hellofromtonya Jul 6, 2023
09a4abe
Check if experiment enabled fr this time (#52315)
tellthemachines Jul 5, 2023
ce56765
Navigation: Remove one preloaded endpoint (#52115)
scruffian Jul 4, 2023
a0bdd09
default to showing status (#52226)
SaxonF Jul 4, 2023
91a3458
Command palette: rename (#52153)
stokesman Jul 3, 2023
2930ef4
Image block and behaviors: Fix some warnings (#52109)
cbravobernal Jun 29, 2023
859112d
Turn off DFM for style book and style editing (#52117)
draganescu Jul 3, 2023
41cecb5
Add confirmation step when deleting a Template (#52236)
ntsekouras Jul 3, 2023
a20e265
[Command Palette]: Remove suggestion for deleting templates/parts (#5…
ntsekouras Jul 3, 2023
df103c2
Update stepper styling in Home template details panel (#51972)
jameskoster Jun 27, 2023
b776600
[Edit Post]: Add toggle fullscreen mode and list view commands (#52184)
ntsekouras Jul 3, 2023
621aa95
Style Book: Show tabs and make blocks clickable when entering edit mo…
t-hamano Jul 5, 2023
150b10c
!important (#52025)
jameskoster Jun 28, 2023
1f60798
Navigation in Site View: Readd the edit button (#52111)
scruffian Jun 30, 2023
a300af3
Fix UnitControl crashing on regex control characters.
TimothyBJacobs Jul 3, 2023
17ae96f
Patterns: rename wp_block sync_status postmeta to wp_pattern_sync_sta…
glendaviesnz Jul 4, 2023
0afd8ed
Site Editor Frame: Ignore Spotlight in view mode (#52262)
ntsekouras Jul 4, 2023
5ab9b67
Guide: Place focus on the guide's container instead of its first tabb…
noisysocks Jul 5, 2023
838485c
Post editor: Require confirmation before removing Footnotes (#52277)
mcsf Jul 5, 2023
d03a89e
Fix react-dropdown-menu version to avoid breaking change from one of …
tellthemachines Jul 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Patterns: rename sync_status and move to top level field on rest retu…
…rn instead of a meta field (#52146)
  • Loading branch information
glendaviesnz authored and tellthemachines committed Jul 7, 2023
commit 9e40ea99bf8e77ac00218f90faf7e09a572701d1
28 changes: 28 additions & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
29 changes: 6 additions & 23 deletions lib/compat/wordpress-6.3/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function gutenberg_rename_reusable_block_cpt_to_pattern( $args, $post_type ) {
$args['labels']['item_reverted_to_draft'] = __( 'Pattern reverted to draft.' );
$args['labels']['item_scheduled'] = __( 'Pattern scheduled.' );
$args['labels']['item_updated'] = __( 'Pattern updated.' );
$args['rest_controller_class'] = 'Gutenberg_REST_Blocks_Controller';
}

return $args;
Expand Down Expand Up @@ -89,7 +90,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.
*
Expand All @@ -101,39 +102,21 @@ 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' );
},
'sanitize_callback' => 'gutenberg_wp_block_sanitize_post_meta',
'sanitize_callback' => 'sanitize_text_field',
'single' => true,
'type' => 'string',
'show_in_rest' => array(
'schema' => array(
'type' => 'string',
'properties' => array(
'sync_status' => array(
'type' => 'string',
),
),
'type' => 'string',
'enum' => array( 'partial', 'unsynced' ),
),
),
)
);
}
/**
* Sanitizes the array of wp_block post meta sync_status string.
*
* Note: This should be removed when the minimum required WP version is >= 6.3.
*
* @see https://github.com/WordPress/gutenberg/pull/51144
*
* @param array $meta_value String to sanitize.
*
* @return array Sanitized string.
*/
function gutenberg_wp_block_sanitize_post_meta( $meta_value ) {
return sanitize_text_field( $meta_value );
}
add_action( 'init', 'gutenberg_wp_block_register_post_meta' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Reusable blocks REST API: WP_REST_Blocks_Controller class
*
* @package WordPress
* @subpackage REST_API
* @since 5.0.0
*/

/**
* Controller which provides a REST endpoint for the editor to read, create,
* edit and delete reusable blocks. Blocks are stored as posts with the wp_block
* post type.
*
* @since 5.0.0
*
* @see WP_REST_Posts_Controller
* @see WP_REST_Controller
*/
class Gutenberg_REST_Blocks_Controller extends WP_REST_Blocks_Controller {
/**
* Filters a response based on the context defined in the schema.
*
* @since 5.0.0
* @since 6.3 Adds the `wp_pattern_sync_status` property to the response.
*
* @param array $data Response data to filter.
* @param string $context Context defined in the schema.
* @return array Filtered response.
*/
public function filter_response_by_context( $data, $context ) {
$data = parent::filter_response_by_context( $data, $context );

/*
* Remove `title.rendered` and `content.rendered` from the response. It
* doesn't make sense for a reusable block to have rendered content on its
* own, since rendering a block requires it to be inside a post or a page.
*/
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;
}
}
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require_once __DIR__ . '/compat/wordpress-6.3/navigation-block-preloading.php';
require_once __DIR__ . '/compat/wordpress-6.3/link-template.php';
require_once __DIR__ . '/compat/wordpress-6.3/block-patterns.php';
require_once __DIR__ . '/compat/wordpress-6.3/class-gutenberg-rest-blocks-controller.php';

// Experimental.
if ( ! class_exists( 'WP_Rest_Customizer_Nonces' ) ) {
Expand Down
15 changes: 9 additions & 6 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2034,11 +2034,13 @@ export const getInserterItems = createSelector(
? getReusableBlocks( state )
.filter(
( reusableBlock ) =>
// Filter to either fully synced patterns (sync_status === 'fully'),
// or old school reusable blocks (sync_status === '').
reusableBlock.meta?.sync_status === 'fully' ||
reusableBlock.meta?.sync_status === '' ||
! reusableBlock.meta?.sync_status
// Reusable blocks that are fully synced should have no sync status set
// for backwards compat between patterns and old reusable blocks, but
// some in release 16.1 may have had sync status inadvertantly set to
// 'fully' if created in the site editor.
reusableBlock.wp_pattern_sync_status === 'fully' ||
reusableBlock.wp_pattern_sync_status === '' ||
! reusableBlock.wp_pattern_sync_status
)
.map( buildReusableBlockInserterItem )
: [];
Expand Down Expand Up @@ -2313,7 +2315,8 @@ function getUnsyncedPatterns( state ) {

return reusableBlocks
.filter(
( reusableBlock ) => reusableBlock.meta?.sync_status === 'unsynced'
( reusableBlock ) =>
reusableBlock.wp_pattern_sync_status === 'unsynced'
)
.map( ( reusableBlock ) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const reusableBlockToPattern = ( reusableBlock ) => ( {
categories: reusableBlock.wp_pattern,
id: reusableBlock.id,
name: reusableBlock.slug,
syncStatus: reusableBlock.meta?.sync_status || SYNC_TYPES.full,
syncStatus: reusableBlock.wp_pattern_sync_status || SYNC_TYPES.full,
title: reusableBlock.title.raw,
type: reusableBlock.type,
reusableBlock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function usePatternDetails( postType, postId ) {
details.push( {
label: __( 'Syncing' ),
value:
record.meta?.sync_status === 'unsynced'
record.wp_pattern_sync_status === 'unsynced'
? __( 'Not synced' )
: __( 'Fully synced' ),
} );
Expand Down
6 changes: 3 additions & 3 deletions packages/editor/src/components/post-sync-status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import { PanelRow } from '@wordpress/components';
import { store as editorStore } from '../../store';

export default function PostSyncStatus() {
const { meta, postType } = useSelect( ( select ) => {
const { syncStatus, postType } = useSelect( ( select ) => {
const { getEditedPostAttribute } = select( editorStore );
return {
meta: getEditedPostAttribute( 'meta' ),
syncStatus: getEditedPostAttribute( 'wp_pattern_sync_status' ),
postType: getEditedPostAttribute( 'type' ),
};
}, [] );
if ( postType !== 'wp_block' ) {
return null;
}
const syncStatus = meta?.sync_status;

const isFullySynced = ! syncStatus;

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/reusable-blocks/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const __experimentalConvertBlocksToReusable =
const meta =
syncType === 'unsynced'
? {
sync_status: syncType,
wp_pattern_sync_status: syncType,
}
: undefined;

Expand Down