Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick commits for WP 6.5 RC 1 #59541

Merged
merged 25 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2e5c3e3
Site Logo: Update capitalization of Use as Site Icon toggle (#59383)
andrewserong Feb 26, 2024
30c4f7d
Avoid loading theme fonts again and assume they were already resolved…
matiasbenedetto Feb 28, 2024
df0c480
Font library: Update the spacing in the font collection panel heading…
carolinan Feb 28, 2024
87a55e2
Block Bindings: Don't show protected fields that are bound to blocks …
SantosGuillamot Feb 28, 2024
2bc516a
Block Hooks: Display toggle for hooked blocks added via filter (#59396)
ockham Feb 28, 2024
8f8f533
URLPopover: Fix a problem with the layout of link settings (#58906)
t-hamano Feb 28, 2024
e88f867
Block Bindings: do not use useSource hook conditionally (#59403)
retrofox Feb 28, 2024
bd2eeec
Font Library: Hide UI elements when user lacks permissions (#59332)
creativecoder Feb 28, 2024
b5f2b33
Font Library: fix infinite loop when calling wp_get_upload_dir in a f…
matiasbenedetto Feb 28, 2024
6c04972
Avoid creating font families without font faces. (#59436)
matiasbenedetto Feb 28, 2024
82a4572
Site Editor: Ensure ResizableFrame does not force Cover blocks within…
andrewserong Feb 28, 2024
b423ff5
Change default "Connected to a custom field" message in bindings (#59…
SantosGuillamot Feb 29, 2024
13e2c3f
List: copy wrapper when multi selecting items (#59460)
ellatrix Feb 29, 2024
9332cee
Use block naming for marking blocks as overridable in patterns (#59268)
talldan Mar 1, 2024
b60b97c
Site Logo: Update url for site icon settings with fallback for WP cor…
andrewserong Mar 1, 2024
43b12ee
Rich text: fix typing into empty flex element (#59473)
ellatrix Mar 1, 2024
77ba590
Fix inserting button block when pressing enter in a block with bound …
SantosGuillamot Mar 1, 2024
122d14c
Changed installFont to installFonts so that multiple font families ca…
pbking Mar 1, 2024
c3d8a4b
Rename data_wp_context_function (#59465)
cbravobernal Feb 29, 2024
af7ee16
Add visual indicator if a block is connected to block binding source …
michalczaplinski Feb 29, 2024
0f75d06
https://github.com/WordPress/gutenberg/pull/55091 updated the way tem…
ramonjd Feb 22, 2024
eef6c06
Performance tests: make site editor performance test backwards compat…
ramonjd Feb 22, 2024
8334c94
DataViews: set color for primary field/`a` element when focused (#58814)
oandregal Feb 29, 2024
89cd003
Data views: Use aria-disabled on disabled checkboxes (#59364)
jameskoster Mar 4, 2024
ebdf83d
InnerBlocks: Support insert before/after the block actions (#59162)
Mamaduka Feb 22, 2024
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
4 changes: 2 additions & 2 deletions docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1263,15 +1263,15 @@ Action that hides the insertion point.

### insertAfterBlock

Action that inserts an empty block after a given block.
Action that inserts a default block after a given block.

_Parameters_

- _clientId_ `string`:

### insertBeforeBlock

Action that inserts an empty block before a given block.
Action that inserts a default block before a given block.

_Parameters_

Expand Down
25 changes: 22 additions & 3 deletions lib/compat/wordpress-6.5/block-bindings/pattern-overrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,30 @@
* @return mixed The value computed for the source.
*/
function gutenberg_block_bindings_pattern_overrides_callback( $source_attrs, $block_instance, $attribute_name ) {
if ( empty( $block_instance->attributes['metadata']['id'] ) ) {
if ( ! isset( $block_instance->context['pattern/overrides'] ) ) {
return null;
}
$block_id = $block_instance->attributes['metadata']['id'];
return _wp_array_get( $block_instance->context, array( 'pattern/overrides', $block_id, 'values', $attribute_name ), null );

$override_content = $block_instance->context['pattern/overrides'];

// Back compat. Pattern overrides previously used a metadata `id` instead of `name`.
// We check first for the name, and if it exists, use that value.
if ( isset( $block_instance->attributes['metadata']['name'] ) ) {
$metadata_name = $block_instance->attributes['metadata']['name'];
if ( array_key_exists( $metadata_name, $override_content ) ) {
return _wp_array_get( $override_content, array( $metadata_name, $attribute_name ), null );
}
}

// Next check for the `id`.
if ( isset( $block_instance->attributes['metadata']['id'] ) ) {
$metadata_id = $block_instance->attributes['metadata']['id'];
if ( array_key_exists( $metadata_id, $override_content ) ) {
return _wp_array_get( $override_content, array( $metadata_id, $attribute_name ), null );
}
}

return null;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions lib/compat/wordpress-6.5/block-bindings/post-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ function gutenberg_block_bindings_post_meta_callback( $source_attrs, $block_inst
return null;
}

// Check if the meta field is protected.
if ( is_protected_meta( $source_attrs['key'], 'post' ) ) {
return null;
}

// Check if the meta field is registered to be shown in REST.
$meta_keys = get_registered_meta_keys( 'post', $block_instance->context['postType'] );
// Add fields registered for all subtypes.
$meta_keys = array_merge( $meta_keys, get_registered_meta_keys( 'post', '' ) );
if ( empty( $meta_keys[ $source_attrs['key'] ]['show_in_rest'] ) ) {
return null;
}

return get_post_meta( $post_id, $source_attrs['key'], true );
}

Expand Down
15 changes: 15 additions & 0 deletions lib/compat/wordpress-6.5/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ function array_is_list( $arr ) {
return true;
}
}

/**
* Sets a global JS variable used to flag whether to direct the Site Logo block's admin urls
* to the Customizer. This allows Gutenberg running on versions of WordPress < 6.5.0 to
* support the previous location for the Site Icon settings. This function should not be
* backported to core, and should be removed when the required WP core version for Gutenberg
* is >= 6.5.0.
*/
function gutenberg_add_use_customizer_site_logo_url_flag() {
if ( ! is_wp_version_compatible( '6.5' ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalUseCustomizerSiteLogoUrl = true', 'before' );
}
}

add_action( 'admin_init', 'gutenberg_add_use_customizer_site_logo_url_flag' );
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,21 @@ protected function sanitize_src( $value ) {
*/
protected function handle_font_file_upload( $file ) {
add_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) );
add_filter( 'upload_dir', 'wp_get_font_dir' );

/*
* Set the upload directory to the fonts directory.
*
* wp_get_font_dir() contains the 'font_dir' hook, whose callbacks are
* likely to call wp_get_upload_dir().
*
* To avoid an infinite loop, don't hook wp_get_font_dir() to 'upload_dir'.
* Instead, just pass its return value to the 'upload_dir' callback.
*/
$font_dir = wp_get_font_dir();
$set_upload_dir = function () use ( $font_dir ) {
return $font_dir;
};
add_filter( 'upload_dir', $set_upload_dir );

$overrides = array(
'upload_error_handler' => array( $this, 'handle_font_file_upload_error' ),
Expand All @@ -875,8 +889,7 @@ protected function handle_font_file_upload( $file ) {
);

$uploaded_file = wp_handle_upload( $file, $overrides );

remove_filter( 'upload_dir', 'wp_get_font_dir' );
remove_filter( 'upload_dir', $set_upload_dir );
remove_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) );

return $uploaded_file;
Expand Down
27 changes: 9 additions & 18 deletions lib/compat/wordpress-6.5/fonts/fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,6 @@ function gutenberg_register_font_collections() {
*
* @since 6.5.0
*
* @param array $defaults {
* Array of information about the upload directory.
*
* @type string $path Base directory and subdirectory or full path to the fonts upload directory.
* @type string $url Base URL and subdirectory or absolute URL to the fonts upload directory.
* @type string $subdir Subdirectory
* @type string $basedir Path without subdir.
* @type string $baseurl URL path without subdir.
* @type string|false $error False or error message.
* }
* @return array $defaults {
* Array of information about the upload directory.
*
Expand All @@ -189,19 +179,20 @@ function gutenberg_register_font_collections() {
* @type string|false $error False or error message.
* }
*/
function wp_get_font_dir( $defaults = array() ) {
function wp_get_font_dir() {
$site_path = '';
if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) {
$site_path = '/sites/' . get_current_blog_id();
}

// Sets the defaults.
$defaults['path'] = path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path;
$defaults['url'] = untrailingslashit( content_url( 'fonts' ) ) . $site_path;
$defaults['subdir'] = '';
$defaults['basedir'] = path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path;
$defaults['baseurl'] = untrailingslashit( content_url( 'fonts' ) ) . $site_path;
$defaults['error'] = false;
$defaults = array(
'path' => path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path,
'url' => untrailingslashit( content_url( 'fonts' ) ) . $site_path,
'subdir' => '',
'basedir' => path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path,
'baseurl' => untrailingslashit( content_url( 'fonts' ) ) . $site_path,
'error' => false,
);

/**
* Filters the fonts directory data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function wp_interactivity_config( string $store_namespace, array $config = array
}
}

if ( ! function_exists( 'data_wp_context' ) ) {
if ( ! function_exists( 'wp_interactivity_data_wp_context' ) ) {
/**
* Generates a `data-wp-context` directive attribute by encoding a context
* array.
Expand All @@ -162,7 +162,7 @@ function wp_interactivity_config( string $store_namespace, array $config = array
*
* Example:
*
* <div <?php echo data_wp_context( array( 'isOpen' => true, 'count' => 0 ) ); ?>>
* <div <?php echo wp_interactivity_data_wp_context( array( 'isOpen' => true, 'count' => 0 ) ); ?>>
*
* @since 6.5.0
*
Expand All @@ -171,7 +171,7 @@ function wp_interactivity_config( string $store_namespace, array $config = array
* @return string A complete `data-wp-context` directive with a JSON encoded value representing the context array and
* the store namespace if specified.
*/
function data_wp_context( array $context, string $store_namespace = '' ): string {
function wp_interactivity_data_wp_context( array $context, string $store_namespace = '' ): string {
return 'data-wp-context=\'' .
( $store_namespace ? $store_namespace . '::' : '' ) .
( empty( $context ) ? '{}' : wp_json_encode( $context, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ) ) .
Expand Down
6 changes: 2 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/base-styles/_default-custom-properties.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

// It is important to include these styles in all built stylesheets.
// This allows to CSS variables post CSS plugin to generate fallbacks.
// It also provides default CSS variables for npm package consumers.
:root {
@include admin-scheme(#007cba);
--wp-block-synced-color: #7a00df;
--wp-block-synced-color--rgb: #{hex-to-rgb(#7a00df)};
--wp-bound-block-color: #9747ff;
}
8 changes: 8 additions & 0 deletions packages/base-styles/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,14 @@
}
}

@mixin link-reset {
&:focus {
color: var(--wp-admin-theme-color--rgb);
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color, #007cba);
border-radius: $radius-block-ui;
}
}

// The editor input reset with increased specificity to avoid theme styles bleeding in.
@mixin editor-input-reset() {
font-family: $editor-html-font !important;
Expand Down
104 changes: 57 additions & 47 deletions packages/block-editor/src/components/block-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,55 @@ export default function BlockActions( {
children,
__experimentalUpdateSelection: updateSelection,
} ) {
const {
canInsertBlockType,
getBlockRootClientId,
getBlocksByClientId,
canMoveBlocks,
canRemoveBlocks,
} = useSelect( blockEditorStore );
const { getDefaultBlockName, getGroupingBlockName } =
useSelect( blocksStore );

const blocks = getBlocksByClientId( clientIds );
const rootClientId = getBlockRootClientId( clientIds[ 0 ] );

const canCopyStyles = blocks.every( ( block ) => {
return (
!! block &&
( hasBlockSupport( block.name, 'color' ) ||
hasBlockSupport( block.name, 'typography' ) )
);
} );

const canDuplicate = blocks.every( ( block ) => {
return (
!! block &&
hasBlockSupport( block.name, 'multiple', true ) &&
canInsertBlockType( block.name, rootClientId )
);
} );

const canInsertDefaultBlock = canInsertBlockType(
getDefaultBlockName(),
rootClientId
const selected = useSelect(
( select ) => {
const {
canInsertBlockType,
getBlockRootClientId,
getBlocksByClientId,
getDirectInsertBlock,
canMoveBlocks,
canRemoveBlocks,
} = select( blockEditorStore );

const blocks = getBlocksByClientId( clientIds );
const rootClientId = getBlockRootClientId( clientIds[ 0 ] );
const canInsertDefaultBlock = canInsertBlockType(
getDefaultBlockName(),
rootClientId
);
const directInsertBlock = rootClientId
? getDirectInsertBlock( rootClientId )
: null;

return {
canMove: canMoveBlocks( clientIds, rootClientId ),
canRemove: canRemoveBlocks( clientIds, rootClientId ),
canInsertBlock: canInsertDefaultBlock || !! directInsertBlock,
canCopyStyles: blocks.every( ( block ) => {
return (
!! block &&
( hasBlockSupport( block.name, 'color' ) ||
hasBlockSupport( block.name, 'typography' ) )
);
} ),
canDuplicate: blocks.every( ( block ) => {
return (
!! block &&
hasBlockSupport( block.name, 'multiple', true ) &&
canInsertBlockType( block.name, rootClientId )
);
} ),
};
},
[ clientIds, getDefaultBlockName ]
);
const { getBlocksByClientId, getBlocks } = useSelect( blockEditorStore );

const canMove = canMoveBlocks( clientIds, rootClientId );
const canRemove = canRemoveBlocks( clientIds, rootClientId );
const { canMove, canRemove, canInsertBlock, canCopyStyles, canDuplicate } =
selected;

const {
removeBlocks,
Expand All @@ -75,11 +88,9 @@ export default function BlockActions( {
return children( {
canCopyStyles,
canDuplicate,
canInsertDefaultBlock,
canInsertBlock,
canMove,
canRemove,
rootClientId,
blocks,
onDuplicate() {
return duplicateBlocks( clientIds, updateSelection );
},
Expand All @@ -104,44 +115,43 @@ export default function BlockActions( {
setBlockMovingClientId( clientIds[ 0 ] );
},
onGroup() {
if ( ! blocks.length ) {
if ( ! clientIds.length ) {
return;
}

const groupingBlockName = getGroupingBlockName();

// Activate the `transform` on `core/group` which does the conversion.
const newBlocks = switchToBlockType( blocks, groupingBlockName );
const newBlocks = switchToBlockType(
getBlocksByClientId( clientIds ),
groupingBlockName
);

if ( ! newBlocks ) {
return;
}
replaceBlocks( clientIds, newBlocks );
},
onUngroup() {
if ( ! blocks.length ) {
if ( ! clientIds.length ) {
return;
}

const innerBlocks = blocks[ 0 ].innerBlocks;

const innerBlocks = getBlocks( clientIds[ 0 ] );
if ( ! innerBlocks.length ) {
return;
}

replaceBlocks( clientIds, innerBlocks );
},
onCopy() {
const selectedBlockClientIds = blocks.map(
( { clientId } ) => clientId
);
if ( blocks.length === 1 ) {
flashBlock( selectedBlockClientIds[ 0 ] );
if ( clientIds.length === 1 ) {
flashBlock( clientIds[ 0 ] );
}
notifyCopy( 'copy', selectedBlockClientIds );
notifyCopy( 'copy', clientIds );
},
async onPasteStyles() {
await pasteStyles( blocks );
await pasteStyles( getBlocksByClientId( clientIds ) );
},
} );
}
Loading
Loading