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 WordPress 6.5. Beta 2 #59197

Merged
merged 29 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f2a5323
Revert #55219 fix/block-settings-origins (#58951)
ajlende Feb 14, 2024
de9eb98
Font Library: fixes installed font families not rendering in the edit…
matiasbenedetto Feb 14, 2024
3f62ea1
Patterns: Check we are not within a pattern instance before running b…
glendaviesnz Feb 15, 2024
4d94d57
Fix wrong commas (#59029)
cbravobernal Feb 15, 2024
331f046
do not match firefox for ios because it's not Gecko but webkit. (#59037)
matiasbenedetto Feb 15, 2024
b348e5c
useEntityBlockEditor: Update 'content' type check (#59058)
Mamaduka Feb 15, 2024
6e5a64f
Enter editing mode via Enter or Spacebar (#58795)
jeryj Feb 15, 2024
ecb9f52
Fix logic error in #58951 (#59101)
matiasbenedetto Feb 15, 2024
27a9a28
Navigation: Avoid using embedded records from fallback API (#59076)
Mamaduka Feb 16, 2024
97eb1e1
Allow editing of image block alt and title attributes in content only…
talldan Feb 16, 2024
7b589f9
Elements: Fix block instance element styles for links applying to but…
aaronrobertshaw Feb 16, 2024
a2f73e6
DataViews: Correctly display featured image that don't have image siz…
t-hamano Feb 16, 2024
3a6fad4
Block Bindings: Add block context needed for bindings in PHP (#58554)
SantosGuillamot Feb 16, 2024
54b7e41
After Enter transform, skip other onEnter actions like splitting (#59…
jsnajdr Feb 16, 2024
e109bed
Fix status control display (#58775)
jameskoster Feb 16, 2024
35f7226
Make 'All pages' view label consistent with template and patterns (#5…
jameskoster Feb 16, 2024
07eaea9
Font Library: adds the ability to use generic() in font family names.…
matiasbenedetto Feb 16, 2024
9cf215c
fix wrong (unprefixed) function name for variation_callback (#59126)
gaambo Feb 16, 2024
245b544
Update: Increate footnotes meta priority and separate footnotes meta …
jorgefilipecosta Feb 16, 2024
e14c1d9
Make command palette string transatables (#59133)
MarieComet Feb 17, 2024
234fb7d
Global style changes: refactor output for a more flexible UI and grou…
ramonjd Feb 19, 2024
5044d4c
No need for first argument (#59160)
ramonjd Feb 19, 2024
1605148
Modules API: Script Modules add deregister option. (#58830)
cbravobernal Feb 19, 2024
302d96f
Block Hooks: Fix in Navigation block (#59021)
ockham Feb 19, 2024
27da58c
Revert "Navigation: Refactor mobile overlay breakpoints to JS (#57520…
cbravobernal Feb 19, 2024
4fcb480
Fix upload button on overriden empty image block in patterns (#59169)
kevin940726 Feb 20, 2024
245d24e
Fix missing source for binding attributes (#59194)
kevin940726 Feb 20, 2024
0a92dc2
Image: Mark connected controls as 'readyonly' (#59059)
Mamaduka Feb 15, 2024
e69818e
Revert footer in pages list with DataViews (#59151)
ntsekouras Feb 19, 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
5 changes: 3 additions & 2 deletions lib/block-supports/elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ function gutenberg_render_elements_support_styles( $pre_render, $block ) {
'skip' => $skip_button_color_serialization,
),
'link' => array(
'selector' => ".$class_name a",
'hover_selector' => ".$class_name a:hover",
// :where(:not) matches theme.json selector.
'selector' => ".$class_name a:where(:not(.wp-element-button))",
'hover_selector' => ".$class_name a:where(:not(.wp-element-button)):hover",
'skip' => $skip_link_color_serialization,
),
'heading' => array(
Expand Down
23 changes: 12 additions & 11 deletions lib/compat/wordpress-6.5/block-bindings/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@
* @param array $source_properties {
* The array of arguments that are used to register a source.
*
* @type string $label The label of the source.
* @type callback $get_value_callback A callback executed when the source is processed during block rendering.
* The callback should have the following signature:
* @type string $label The label of the source.
* @type callback $get_value_callback A callback executed when the source is processed during block rendering.
* The callback should have the following signature:
*
* `function ($source_args, $block_instance,$attribute_name): mixed`
* - @param array $source_args Array containing source arguments
* used to look up the override value,
* i.e. {"key": "foo"}.
* - @param WP_Block $block_instance The block instance.
* - @param string $attribute_name The name of an attribute .
* The callback has a mixed return type; it may return a string to override
* the block's original value, null, false to remove an attribute, etc.
* `function ($source_args, $block_instance,$attribute_name): mixed`
* - @param array $source_args Array containing source arguments
* used to look up the override value,
* i.e. {"key": "foo"}.
* - @param WP_Block $block_instance The block instance.
* - @param string $attribute_name The name of an attribute .
* The callback has a mixed return type; it may return a string to override
* the block's original value, null, false to remove an attribute, etc.
* @type array $uses_context (optional) Array of values to add to block `uses_context` needed by the source.
* }
* @return WP_Block_Bindings_Source|false Source when the registration was successful, or `false` on failure.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ final class WP_Block_Bindings_Registry {
*/
private static $instance = null;

/**
* Supported source properties that can be passed to the registered source.
*
* @since 6.5.0
* @var array
*/
private $allowed_source_properties = array(
'label',
'get_value_callback',
'uses_context',
);

/**
* Supported blocks that can use the block bindings API.
*
* @since 6.5.0
* @var array
*/
private $supported_blocks = array(
'core/paragraph',
'core/heading',
'core/image',
'core/button',
);

/**
* Registers a new block bindings source.
*
Expand All @@ -48,18 +73,19 @@ final class WP_Block_Bindings_Registry {
* @param array $source_properties {
* The array of arguments that are used to register a source.
*
* @type string $label The label of the source.
* @type callback $get_value_callback A callback executed when the source is processed during block rendering.
* The callback should have the following signature:
*
* `function ($source_args, $block_instance,$attribute_name): mixed`
* - @param array $source_args Array containing source arguments
* used to look up the override value,
* i.e. {"key": "foo"}.
* - @param WP_Block $block_instance The block instance.
* - @param string $attribute_name The name of the target attribute.
* The callback has a mixed return type; it may return a string to override
* the block's original value, null, false to remove an attribute, etc.
* @type string $label The label of the source.
* @type callback $get_value_callback A callback executed when the source is processed during block rendering.
* The callback should have the following signature:
*
* `function ($source_args, $block_instance,$attribute_name): mixed`
* - @param array $source_args Array containing source arguments
* used to look up the override value,
* i.e. {"key": "foo"}.
* - @param WP_Block $block_instance The block instance.
* - @param string $attribute_name The name of the target attribute.
* The callback has a mixed return type; it may return a string to override
* the block's original value, null, false to remove an attribute, etc.
* @type array $uses_context (optional) Array of values to add to block `uses_context` needed by the source.
* }
* @return WP_Block_Bindings_Source|false Source when the registration was successful, or `false` on failure.
*/
Expand Down Expand Up @@ -102,7 +128,7 @@ public function register( string $source_name, array $source_properties ) {
return false;
}

/* Validate that the source properties contain the label */
// Validate that the source properties contain the label.
if ( ! isset( $source_properties['label'] ) ) {
_doing_it_wrong(
__METHOD__,
Expand All @@ -112,7 +138,7 @@ public function register( string $source_name, array $source_properties ) {
return false;
}

/* Validate that the source properties contain the get_value_callback */
// Validate that the source properties contain the get_value_callback.
if ( ! isset( $source_properties['get_value_callback'] ) ) {
_doing_it_wrong(
__METHOD__,
Expand All @@ -122,7 +148,7 @@ public function register( string $source_name, array $source_properties ) {
return false;
}

/* Validate that the get_value_callback is a valid callback */
// Validate that the get_value_callback is a valid callback.
if ( ! is_callable( $source_properties['get_value_callback'] ) ) {
_doing_it_wrong(
__METHOD__,
Expand All @@ -132,13 +158,49 @@ public function register( string $source_name, array $source_properties ) {
return false;
}

// Validate that the uses_context parameter is an array.
if ( isset( $source_properties['uses_context'] ) && ! is_array( $source_properties['uses_context'] ) ) {
_doing_it_wrong(
__METHOD__,
__( 'The "uses_context" parameter must be an array.' ),
'6.5.0'
);
return false;
}

// Validate that the source properties contain only allowed properties.
if ( ! empty( array_diff( array_keys( $source_properties ), $this->allowed_source_properties ) ) ) {
_doing_it_wrong(
__METHOD__,
__( 'The $source_properties array contains invalid properties.' ),
'6.5.0'
);
return false;
}

$source = new WP_Block_Bindings_Source(
$source_name,
$source_properties
);

$this->sources[ $source_name ] = $source;

// Add `uses_context` defined by block bindings sources.
add_filter(
'register_block_type_args',
function ( $args, $block_name ) use ( $source ) {
if ( ! in_array( $block_name, $this->supported_blocks, true ) || empty( $source->uses_context ) ) {
return $args;
}
$original_use_context = isset( $args['uses_context'] ) ? $args['uses_context'] : array();
// Use array_values to reset the array keys.
$args['uses_context'] = array_values( array_unique( array_merge( $original_use_context, $source->uses_context ) ) );

return $args;
},
10,
2
);
return $source;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ final class WP_Block_Bindings_Source {
*/
private $get_value_callback;

/**
* The context added to the blocks needed by the source.
*
* @since 6.5.0
* @var array|null
*/
public $uses_context = null;

/**
* Constructor.
*
Expand All @@ -58,9 +66,10 @@ final class WP_Block_Bindings_Source {
* @param array $source_properties The properties of the source.
*/
public function __construct( string $name, array $source_properties ) {
$this->name = $name;
$this->label = $source_properties['label'];
$this->get_value_callback = $source_properties['get_value_callback'];
$this->name = $name;
foreach ( $source_properties as $property_name => $property_value ) {
$this->$property_name = $property_value;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function gutenberg_register_block_bindings_pattern_overrides_source() {
array(
'label' => _x( 'Pattern Overrides', 'block bindings source' ),
'get_value_callback' => 'gutenberg_block_bindings_pattern_overrides_callback',
'uses_context' => array( 'pattern/overrides' ),
)
);
}
Expand Down
20 changes: 9 additions & 11 deletions lib/compat/wordpress-6.5/block-bindings/post-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@
/**
* Gets value for Post Meta source.
*
* @param array $source_args Array containing source arguments used to look up the override value.
* Example: array( "key" => "foo" ).
* @param array $source_args Array containing source arguments used to look up the override value.
* Example: array( "key" => "foo" ).
* @param WP_Block $block_instance The block instance.
* @return mixed The value computed for the source.
*/
function gutenberg_block_bindings_post_meta_callback( $source_attrs ) {
if ( ! isset( $source_attrs['key'] ) ) {
function gutenberg_block_bindings_post_meta_callback( $source_attrs, $block_instance ) {
if ( empty( $source_attrs['key'] ) ) {
return null;
}

// Use the postId attribute if available
if ( isset( $source_attrs['postId'] ) ) {
$post_id = $source_attrs['postId'];
} else {
// I tried using $block_instance->context['postId'] but it wasn't available in the image block.
$post_id = get_the_ID();
if ( empty( $block_instance->context['postId'] ) ) {
return null;
}

$post_id = $block_instance->context['postId'];
// If a post isn't public, we need to prevent unauthorized users from accessing the post meta.
$post = get_post( $post_id );
if ( ( ! is_post_publicly_viewable( $post ) && ! current_user_can( 'read_post', $post_id ) ) || post_password_required( $post ) ) {
Expand All @@ -47,6 +44,7 @@ function gutenberg_register_block_bindings_post_meta_source() {
array(
'label' => _x( 'Post Meta', 'block bindings source' ),
'get_value_callback' => 'gutenberg_block_bindings_post_meta_callback',
'uses_context' => array( 'postId', 'postType' ),
)
);
}
Expand Down
16 changes: 7 additions & 9 deletions lib/compat/wordpress-6.5/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function gutenberg_register_metadata_attribute( $args ) {
*/
function gutenberg_block_bindings_replace_html( $block_content, $block_name, string $attribute_name, $source_value ) {
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name );
if ( ! isset( $block_type->attributes[ $attribute_name ] ) ) {
if ( ! isset( $block_type->attributes[ $attribute_name ]['source'] ) ) {
return $block_content;
}

Expand Down Expand Up @@ -157,18 +157,16 @@ function gutenberg_block_bindings_replace_html( $block_content, $block_name, str
* @param WP_Block $block_instance The block instance.
*/
function gutenberg_process_block_bindings( $block_content, $parsed_block, $block_instance ) {
// Allowed blocks that support block bindings.
// TODO: Look for a mechanism to opt-in for this. Maybe adding a property to block attributes?
$allowed_blocks = array(
$supported_block_attrs = array(
'core/paragraph' => array( 'content' ),
'core/heading' => array( 'content' ),
'core/image' => array( 'url', 'title', 'alt' ),
'core/image' => array( 'id', 'url', 'title', 'alt' ),
'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ),
);

// If the block doesn't have the bindings property or isn't one of the allowed block types, return.
// If the block doesn't have the bindings property or isn't one of the supported block types, return.
if (
! isset( $allowed_blocks[ $block_instance->name ] ) ||
! isset( $supported_block_attrs[ $block_instance->name ] ) ||
empty( $parsed_block['attrs']['metadata']['bindings'] ) ||
! is_array( $parsed_block['attrs']['metadata']['bindings'] )
) {
Expand All @@ -192,8 +190,8 @@ function gutenberg_process_block_bindings( $block_content, $parsed_block, $block

$modified_block_content = $block_content;
foreach ( $parsed_block['attrs']['metadata']['bindings'] as $attribute_name => $block_binding ) {
// If the attribute is not in the allowed list, process next attribute.
if ( ! in_array( $attribute_name, $allowed_blocks[ $block_instance->name ], true ) ) {
// If the attribute is not in the supported list, process next attribute.
if ( ! in_array( $attribute_name, $supported_block_attrs[ $block_instance->name ], true ) ) {
continue;
}
// If no source is provided, or that source is not registered, process next attribute.
Expand Down
12 changes: 12 additions & 0 deletions lib/compat/wordpress-6.5/class-wp-script-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ public function dequeue( string $id ) {
unset( $this->enqueued_before_registered[ $id ] );
}

/**
* Removes a registered script module.
*
* @since 6.5.0
*
* @param string $id The identifier of the script module.
*/
public function deregister( string $id ) {
unset( $this->registered[ $id ] );
unset( $this->enqueued_before_registered[ $id ] );
}

/**
* Adds the hooks to print the import map, enqueued script modules and script
* module preloads.
Expand Down
6 changes: 4 additions & 2 deletions lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,10 @@ private static function get_sanitization_schema() {
array(
'font_family_settings' => array(
'name' => 'sanitize_text_field',
'slug' => 'sanitize_title',
'fontFamily' => 'sanitize_text_field',
'slug' => static function ( $value ) {
return _wp_to_kebab_case( sanitize_title( $value ) );
},
'fontFamily' => 'WP_Font_Utils::sanitize_font_family',
'preview' => 'sanitize_url',
'fontFace' => array(
array(
Expand Down
Loading
Loading