Skip to content

Commit e7679f1

Browse files
Merge branch 'WordPress:trunk' into trunk
2 parents 52f809e + c3ca59b commit e7679f1

File tree

74 files changed

+1688
-2295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1688
-2295
lines changed

backport-changelog/6.8/7069.md

-6
This file was deleted.

backport-changelog/6.8/8031.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
https://github.com/WordPress/wordpress-develop/pull/8031
2+
3+
* https://github.com/WordPress/gutenberg/pull/66675
4+
* https://github.com/WordPress/gutenberg/pull/68243

docs/explanations/architecture/styles.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ The user may change the state of this block by applying different styles: a text
3737
After some user modifications to the block, the initial markup may become something like this:
3838

3939
```html
40-
<p
41-
class="has-color has-green-color has-font-size has-small-font-size my-custom-class"
42-
style="line-height: 1em"
43-
></p>
40+
<p class="has-color has-green-color has-font-size has-small-font-size my-custom-class"
41+
style="line-height: 1em"></p>
4442
```
4543

4644
This is what we refer to as "user-provided block styles", also know as "local styles" or "serialized styles". Essentially, each tool (font size, color, etc) ends up adding some classes and/or inline styles to the block markup. The CSS styling for these classes is part of the block, global, or theme stylesheets.
@@ -125,7 +123,7 @@ The block supports API only serializes the font size value to the wrapper, resul
125123

126124
This is an active area of work you can follow [in the tracking issue](https://github.com/WordPress/gutenberg/issues/38167). The linked proposal is exploring a different way to serialize the user changes: instead of each block support serializing its own data (for example, classes such as `has-small-font-size`, `has-green-color`) the idea is the block would get a single class instead (for example, `wp-style-UUID`) and the CSS styling for that class will be generated in the server by WordPress.
127125

128-
While work continues in that proposal, there's an escape hatch, an experimental option block authors can use. Any block support can skip the serialization to HTML markup by using `skipSerialization`. For example:
126+
While work continues in that proposal, there's an escape hatch, an experimental option block authors can use. Any block support can skip the serialization to HTML markup by using `__experimentalSkipSerialization`. For example:
129127

130128
```json
131129
{
@@ -134,15 +132,15 @@ While work continues in that proposal, there's an escape hatch, an experimental
134132
"supports": {
135133
"typography": {
136134
"fontSize": true,
137-
"skipSerialization": true
135+
"__experimentalSkipSerialization": true
138136
}
139137
}
140138
}
141139
```
142140

143141
This means that the typography block support will do all of the things (create a UI control, bind the block attribute to the control, etc) except serializing the user values into the HTML markup. The classes and inline styles will not be automatically applied to the wrapper and it is the block author's responsibility to implement this in the `edit`, `save`, and `render_callback` functions. See [this issue](https://github.com/WordPress/gutenberg/issues/28913) for examples of how it was done for some blocks provided by WordPress.
144142

145-
Note that, if `skipSerialization` is enabled for a group (typography, color, spacing) it affects _all_ block supports within this group. In the example above _all_ the properties within the `typography` group will be affected (e.g. `fontSize`, `lineHeight`, `fontFamily` .etc).
143+
Note that, if `__experimentalSkipSerialization` is enabled for a group (typography, color, spacing) it affects _all_ block supports within this group. In the example above _all_ the properties within the `typography` group will be affected (e.g. `fontSize`, `lineHeight`, `fontFamily` .etc).
146144

147145
To enable for a _single_ property only, you may use an array to declare which properties are to be skipped. In the example below, only `fontSize` will skip serialization, leaving other items within the `typography` group (e.g. `lineHeight`, `fontFamily` .etc) unaffected.
148146

@@ -154,7 +152,7 @@ To enable for a _single_ property only, you may use an array to declare which pr
154152
"typography": {
155153
"fontSize": true,
156154
"lineHeight": true,
157-
"skipSerialization": [ "fontSize" ]
155+
"__experimentalSkipSerialization": [ "fontSize" ]
158156
}
159157
}
160158
}
@@ -475,7 +473,7 @@ If blocks do this, they need to be registered in the server using the `block.jso
475473

476474
Every chunk of styles can only use a single selector.
477475

478-
This is particularly relevant if the block is using `skipSerialization` to serialize the different style properties to different nodes other than the wrapper. See "Current limitations of blocks supports" for more.
476+
This is particularly relevant if the block is using `__experimentalSkipSerialization` to serialize the different style properties to different nodes other than the wrapper. See "Current limitations of blocks supports" for more.
479477

480478
#### 3. **Only a single property per block**
481479

docs/getting-started/fundamentals/javascript-in-the-block-editor.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The diagram below provides an overview of the build process when using the `wp-s
2626

2727
- **Production Mode (`npm run build`):** In this mode, `wp-scripts` compiles your JavaScript, minifying the output to reduce file size and improve loading times in the browser. This is ideal for deploying your code to a live site.
2828

29-
- **Development Mode (`npm run start`):** This mode is tailored for active development. It skips minification for easier debugging, generates source maps for better error tracking, and watches your source files for changes. When a change is detected, it automatically rebuilds the affected files, allowing you to see updates in real-time.
29+
- **Development Mode (`npm start`):** This mode is tailored for active development. It skips minification for easier debugging, generates source maps for better error tracking, and watches your source files for changes. When a change is detected, it automatically rebuilds the affected files, allowing you to see updates in real-time.
3030

3131
The `wp-scripts` package also facilitates the use of JavaScript modules, allowing code distribution across multiple files and resulting in a streamlined bundle after the build process. The [block-development-example](https://github.com/WordPress/block-development-examples/tree/trunk/plugins/data-basics-59c8f8) GitHub repository provides some good examples.
3232

docs/reference-guides/block-api/block-edit-save.md

+26-1
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,34 @@ save: ( { attributes } ) => {
183183
```
184184

185185

186-
187186
When saving your block, you want to save the attributes in the same format specified by the attribute source definition. If no attribute source is specified, the attribute will be saved to the block's comment delimiter. See the [Block Attributes documentation](/docs/reference-guides/block-api/block-attributes.md) for more details.
188187

188+
### innerBlocks
189+
190+
There is a second property in the props passed to the `save` function, `innerBlocks`. This property is typically used for internal operations, and there are very few scenarios where you would need to use it.
191+
192+
`innerBlocks`, when initialized, is an array containing object representations of nested blocks. In those rare cases where you might use this property,
193+
it can help you adjust how a block is rendered. For example, you could render a block differently based on the number of nested blocks or if a specific block type is present..
194+
195+
196+
```jsx
197+
save: ( { attributes, innerBlocks } ) => {
198+
const { className, ...rest } = useBlockProps.save();
199+
200+
// innerBlocks could also be an object - react element during initialization
201+
const numberOfInnerBlocks = innerBlocks?.length;
202+
if ( numberOfInnerBlocks > 1 ) {
203+
className = className + ( className ? ' ' : '' ) + 'more-than-one';
204+
};
205+
const blockProps = { ...rest, className };
206+
207+
return <div { ...blockProps }>{ attributes.content }</div>;
208+
};
209+
```
210+
211+
212+
Here, an additional class is added to the block if number of inner blocks is greater than one, allowing for different styling of the block.
213+
189214
## Examples
190215
191216
Here are a couple examples of using attributes, edit, and save all together.

lib/block-supports/border.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function gutenberg_register_border_support( $block_type ) {
1717
$block_type->attributes = array();
1818
}
1919

20-
if ( block_has_support( $block_type, array( 'border' ) ) && ! array_key_exists( 'style', $block_type->attributes ) ) {
20+
if ( block_has_support( $block_type, array( '__experimentalBorder' ) ) && ! array_key_exists( 'style', $block_type->attributes ) ) {
2121
$block_type->attributes['style'] = array(
2222
'type' => 'object',
2323
);
@@ -52,7 +52,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
5252
if (
5353
gutenberg_has_border_feature_support( $block_type, 'radius' ) &&
5454
isset( $block_attributes['style']['border']['radius'] ) &&
55-
! wp_should_skip_block_supports_serialization( $block_type, 'border', 'radius' )
55+
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'radius' )
5656
) {
5757
$border_radius = $block_attributes['style']['border']['radius'];
5858

@@ -67,7 +67,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
6767
if (
6868
gutenberg_has_border_feature_support( $block_type, 'style' ) &&
6969
isset( $block_attributes['style']['border']['style'] ) &&
70-
! wp_should_skip_block_supports_serialization( $block_type, 'border', 'style' )
70+
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' )
7171
) {
7272
$border_block_styles['style'] = $block_attributes['style']['border']['style'];
7373
}
@@ -76,7 +76,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
7676
if (
7777
$has_border_width_support &&
7878
isset( $block_attributes['style']['border']['width'] ) &&
79-
! wp_should_skip_block_supports_serialization( $block_type, 'border', 'width' )
79+
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' )
8080
) {
8181
$border_width = $block_attributes['style']['border']['width'];
8282

@@ -91,7 +91,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
9191
// Border color.
9292
if (
9393
$has_border_color_support &&
94-
! wp_should_skip_block_supports_serialization( $block_type, 'border', 'color' )
94+
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' )
9595
) {
9696
$preset_border_color = array_key_exists( 'borderColor', $block_attributes ) ? "var:preset|color|{$block_attributes['borderColor']}" : null;
9797
$custom_border_color = $block_attributes['style']['border']['color'] ?? null;
@@ -103,9 +103,9 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
103103
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) {
104104
$border = $block_attributes['style']['border'][ $side ] ?? null;
105105
$border_side_values = array(
106-
'width' => isset( $border['width'] ) && ! wp_should_skip_block_supports_serialization( $block_type, 'border', 'width' ) ? $border['width'] : null,
107-
'color' => isset( $border['color'] ) && ! wp_should_skip_block_supports_serialization( $block_type, 'border', 'color' ) ? $border['color'] : null,
108-
'style' => isset( $border['style'] ) && ! wp_should_skip_block_supports_serialization( $block_type, 'border', 'style' ) ? $border['style'] : null,
106+
'width' => isset( $border['width'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) ? $border['width'] : null,
107+
'color' => isset( $border['color'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) ? $border['color'] : null,
108+
'style' => isset( $border['style'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ) ? $border['style'] : null,
109109
);
110110
$border_block_styles[ $side ] = $border_side_values;
111111
}
@@ -129,9 +129,9 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
129129
/**
130130
* Checks whether the current block type supports the border feature requested.
131131
*
132-
* If the `border` support flag is a boolean `true` all border
132+
* If the `__experimentalBorder` support flag is a boolean `true` all border
133133
* support features are available. Otherwise, the specific feature's support
134-
* flag nested under `border` must be enabled for the feature
134+
* flag nested under `experimentalBorder` must be enabled for the feature
135135
* to be opted into.
136136
*
137137
* @param WP_Block_Type $block_type Block type to check for support.
@@ -141,17 +141,17 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
141141
* @return boolean Whether or not the feature is supported.
142142
*/
143143
function gutenberg_has_border_feature_support( $block_type, $feature, $default_value = false ) {
144-
// Check if all border support features have been opted into via `"border": true`.
144+
// Check if all border support features have been opted into via `"__experimentalBorder": true`.
145145
if ( $block_type instanceof WP_Block_Type ) {
146-
$block_type_supports_border = $block_type->supports['border'] ?? $default_value;
146+
$block_type_supports_border = $block_type->supports['__experimentalBorder'] ?? $default_value;
147147
if ( true === $block_type_supports_border ) {
148148
return true;
149149
}
150150
}
151151

152152
// Check if the specific feature has been opted into individually
153-
// via nested flag under `border`.
154-
return block_has_support( $block_type, array( 'border', $feature ), $default_value );
153+
// via nested flag under `__experimentalBorder`.
154+
return block_has_support( $block_type, array( '__experimentalBorder', $feature ), $default_value );
155155
}
156156

157157
// Register the block support.

lib/block-supports/elements.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,12 @@ function gutenberg_render_elements_class_name( $block_content, $block ) {
255255
}
256256

257257
// Remove deprecated WordPress core filters.
258-
remove_filter( 'render_block', 'wp_render_elements_support', 10, 2 );
259-
remove_filter( 'pre_render_block', 'wp_render_elements_support_styles', 10, 2 );
258+
remove_filter( 'render_block', 'wp_render_elements_support', 10 );
259+
remove_filter( 'pre_render_block', 'wp_render_elements_support_styles', 10 );
260260

261261
// Remove WordPress core filters to avoid rendering duplicate elements stylesheet & attaching classes twice.
262-
remove_filter( 'render_block', 'wp_render_elements_class_name', 10, 2 );
263-
remove_filter( 'render_block_data', 'wp_render_elements_support_styles', 10, 1 );
262+
remove_filter( 'render_block', 'wp_render_elements_class_name', 10 );
263+
remove_filter( 'render_block_data', 'wp_render_elements_support_styles', 10 );
264264

265265
add_filter( 'render_block', 'gutenberg_render_elements_class_name', 10, 2 );
266266
add_filter( 'render_block_data', 'gutenberg_render_elements_support_styles', 10, 1 );

lib/block-supports/layout.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1055,8 +1055,8 @@ static function ( $matches ) {
10551055
}
10561056

10571057
if ( function_exists( 'wp_restore_group_inner_container' ) ) {
1058-
remove_filter( 'render_block', 'wp_restore_group_inner_container', 10, 2 );
1059-
remove_filter( 'render_block_core/group', 'wp_restore_group_inner_container', 10, 2 );
1058+
remove_filter( 'render_block', 'wp_restore_group_inner_container', 10 );
1059+
remove_filter( 'render_block_core/group', 'wp_restore_group_inner_container', 10 );
10601060
}
10611061
add_filter( 'render_block_core/group', 'gutenberg_restore_group_inner_container', 10, 2 );
10621062

@@ -1118,6 +1118,6 @@ function gutenberg_restore_image_outer_container( $block_content, $block ) {
11181118
}
11191119

11201120
if ( function_exists( 'wp_restore_image_outer_container' ) ) {
1121-
remove_filter( 'render_block_core/image', 'wp_restore_image_outer_container', 10, 2 );
1121+
remove_filter( 'render_block_core/image', 'wp_restore_image_outer_container', 10 );
11221122
}
11231123
add_filter( 'render_block_core/image', 'gutenberg_restore_image_outer_container', 10, 2 );

lib/block-supports/settings.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function _gutenberg_add_block_level_preset_styles( $pre_render, $block ) {
128128
return null;
129129
}
130130
// Remove WordPress core filter to avoid rendering duplicate settings style blocks.
131-
remove_filter( 'render_block', '_wp_add_block_level_presets_class', 10, 2 );
132-
remove_filter( 'pre_render_block', '_wp_add_block_level_preset_styles', 10, 2 );
131+
remove_filter( 'render_block', '_wp_add_block_level_presets_class', 10 );
132+
remove_filter( 'pre_render_block', '_wp_add_block_level_preset_styles', 10 );
133133
add_filter( 'render_block', '_gutenberg_add_block_level_presets_class', 10, 2 );
134134
add_filter( 'pre_render_block', '_gutenberg_add_block_level_preset_styles', 10, 2 );

lib/block-supports/typography.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ function gutenberg_register_typography_support( $block_type ) {
2020
return;
2121
}
2222

23-
$has_font_family_support = $typography_supports['fontFamily'] ?? false;
23+
$has_font_family_support = $typography_supports['__experimentalFontFamily'] ?? false;
2424
$has_font_size_support = $typography_supports['fontSize'] ?? false;
25-
$has_font_style_support = $typography_supports['fontStyle'] ?? false;
26-
$has_font_weight_support = $typography_supports['fontWeight'] ?? false;
27-
$has_letter_spacing_support = $typography_supports['letterSpacing'] ?? false;
25+
$has_font_style_support = $typography_supports['__experimentalFontStyle'] ?? false;
26+
$has_font_weight_support = $typography_supports['__experimentalFontWeight'] ?? false;
27+
$has_letter_spacing_support = $typography_supports['__experimentalLetterSpacing'] ?? false;
2828
$has_line_height_support = $typography_supports['lineHeight'] ?? false;
2929
$has_text_align_support = $typography_supports['textAlign'] ?? false;
3030
$has_text_columns_support = $typography_supports['textColumns'] ?? false;
31-
$has_text_decoration_support = $typography_supports['textDecoration'] ?? false;
32-
$has_text_transform_support = $typography_supports['textTransform'] ?? false;
31+
$has_text_decoration_support = $typography_supports['__experimentalTextDecoration'] ?? false;
32+
$has_text_transform_support = $typography_supports['__experimentalTextTransform'] ?? false;
3333
$has_writing_mode_support = $typography_supports['__experimentalWritingMode'] ?? false;
3434

3535
$has_typography_support = $has_font_family_support
@@ -91,16 +91,16 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
9191
return array();
9292
}
9393

94-
$has_font_family_support = $typography_supports['fontFamily'] ?? false;
94+
$has_font_family_support = $typography_supports['__experimentalFontFamily'] ?? false;
9595
$has_font_size_support = $typography_supports['fontSize'] ?? false;
96-
$has_font_style_support = $typography_supports['fontStyle'] ?? false;
97-
$has_font_weight_support = $typography_supports['fontWeight'] ?? false;
98-
$has_letter_spacing_support = $typography_supports['letterSpacing'] ?? false;
96+
$has_font_style_support = $typography_supports['__experimentalFontStyle'] ?? false;
97+
$has_font_weight_support = $typography_supports['__experimentalFontWeight'] ?? false;
98+
$has_letter_spacing_support = $typography_supports['__experimentalLetterSpacing'] ?? false;
9999
$has_line_height_support = $typography_supports['lineHeight'] ?? false;
100100
$has_text_align_support = $typography_supports['textAlign'] ?? false;
101101
$has_text_columns_support = $typography_supports['textColumns'] ?? false;
102-
$has_text_decoration_support = $typography_supports['textDecoration'] ?? false;
103-
$has_text_transform_support = $typography_supports['textTransform'] ?? false;
102+
$has_text_decoration_support = $typography_supports['__experimentalTextDecoration'] ?? false;
103+
$has_text_transform_support = $typography_supports['__experimentalTextTransform'] ?? false;
104104
$has_writing_mode_support = $typography_supports['__experimentalWritingMode'] ?? false;
105105

106106
// Whether to skip individual block support features.

lib/class-wp-duotone-gutenberg.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ private static function get_global_styles_presets( $sources ) {
640640
*
641641
* @param string $block_name The block name.
642642
*
643-
* @return string The CSS selector or null if there is no support.
643+
* @return ?string The CSS selector or null if there is no support.
644644
*/
645645
private static function get_selector( $block_name ) {
646646
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name );
@@ -669,6 +669,8 @@ private static function get_selector( $block_name ) {
669669
// Regular filter.duotone support uses filter.duotone selectors with fallbacks.
670670
return wp_get_block_css_selector( $block_type, array( 'filter', 'duotone' ), true );
671671
}
672+
673+
return null;
672674
}
673675

674676
/**

0 commit comments

Comments
 (0)