Skip to content

Commit 119f67a

Browse files
Merge branch 'trunk' into note-position-alignment
2 parents aff4c7e + 163b654 commit 119f67a

215 files changed

Lines changed: 52801 additions & 2473 deletions

File tree

Some content is hidden

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

backport-changelog/6.9/10054.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
https://github.com/WordPress/wordpress-develop/pull/10054
2+
3+
* https://github.com/WordPress/gutenberg/pull/73029

backport-changelog/7.0/10248.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
https://github.com/WordPress/wordpress-develop/pull/10248
2+
3+
* https://github.com/WordPress/gutenberg/pull/72988

docs/manifest.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,12 @@
14451445
"markdown_source": "../packages/api-fetch/README.md",
14461446
"parent": "packages"
14471447
},
1448+
{
1449+
"title": "@wordpress/asset-loader",
1450+
"slug": "packages-asset-loader",
1451+
"markdown_source": "../packages/asset-loader/README.md",
1452+
"parent": "packages"
1453+
},
14481454
{
14491455
"title": "@wordpress/autop",
14501456
"slug": "packages-autop",
@@ -1811,6 +1817,12 @@
18111817
"markdown_source": "../packages/latex-to-mathml/README.md",
18121818
"parent": "packages"
18131819
},
1820+
{
1821+
"title": "@wordpress/lazy-editor",
1822+
"slug": "packages-lazy-editor",
1823+
"markdown_source": "../packages/lazy-editor/README.md",
1824+
"parent": "packages"
1825+
},
18141826
{
18151827
"title": "@wordpress/lazy-import",
18161828
"slug": "packages-lazy-import",
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
/**
3+
* REST API: Gutenberg_REST_Attachments_Controller_6_9 class
4+
*
5+
* @package gutenberg
6+
*/
7+
8+
/**
9+
* Controller which provides REST endpoint for retrieving attachments.
10+
* This overrides the core WP_REST_Attachments_Controller to provide
11+
* support for filtering by multiple media types.
12+
*
13+
* @since 6.9.0
14+
*
15+
* @see WP_REST_Attachments_Controller
16+
*/
17+
class Gutenberg_REST_Attachments_Controller_6_9 extends WP_REST_Attachments_Controller {
18+
19+
/**
20+
* Determines the allowed query_vars for a get_items() response and
21+
* prepares for WP_Query.
22+
*
23+
* This overrides the parent method to add support for filtering by
24+
* multiple media types, which was added in WordPress 6.9.
25+
*
26+
* @since 4.7.0
27+
* @since 6.9.0 Added orderby_mime_type filter to add custom ordering.
28+
* @since 6.9.0 Extends the `media_type` and `mime_type` request arguments to support array values.
29+
*
30+
* @param array $prepared_args Optional. Array of prepared arguments. Default empty array.
31+
* @param WP_REST_Request $request Optional. Request to prepare items for.
32+
* @return array Array of query arguments.
33+
*/
34+
protected function prepare_items_query( $prepared_args = array(), $request = null ) {
35+
// Store array parameters that we'll handle separately.
36+
$media_type_array = null;
37+
$mime_type_array = null;
38+
39+
if ( ! empty( $request['media_type'] ) && is_array( $request['media_type'] ) ) {
40+
$media_type_array = $request['media_type'];
41+
unset( $request['media_type'] );
42+
}
43+
44+
if ( ! empty( $request['mime_type'] ) && is_array( $request['mime_type'] ) ) {
45+
$mime_type_array = $request['mime_type'];
46+
unset( $request['mime_type'] );
47+
}
48+
49+
$query_args = parent::prepare_items_query( $prepared_args, $request );
50+
51+
// Restore the array parameters to the request.
52+
if ( null !== $media_type_array ) {
53+
$request['media_type'] = $media_type_array;
54+
}
55+
56+
if ( null !== $mime_type_array ) {
57+
$request['mime_type'] = $mime_type_array;
58+
}
59+
60+
if ( empty( $query_args['post_status'] ) ) {
61+
$query_args['post_status'] = 'inherit';
62+
}
63+
64+
$all_mime_types = array();
65+
$media_types = $this->get_media_types();
66+
67+
if ( null !== $media_type_array ) {
68+
foreach ( $media_type_array as $type ) {
69+
if ( isset( $media_types[ $type ] ) ) {
70+
$all_mime_types = array_merge( $all_mime_types, $media_types[ $type ] );
71+
}
72+
}
73+
}
74+
75+
if ( null !== $mime_type_array ) {
76+
foreach ( $mime_type_array as $mime_type ) {
77+
$parts = explode( '/', $mime_type );
78+
if ( isset( $media_types[ $parts[0] ] ) && in_array( $mime_type, $media_types[ $parts[0] ], true ) ) {
79+
$all_mime_types[] = $mime_type;
80+
}
81+
}
82+
}
83+
84+
if ( ! empty( $all_mime_types ) ) {
85+
$query_args['post_mime_type'] = array_values( array_unique( $all_mime_types ) );
86+
}
87+
88+
// Filter query clauses to include filenames.
89+
if ( isset( $query_args['s'] ) ) {
90+
add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );
91+
}
92+
93+
return $query_args;
94+
}
95+
96+
/**
97+
* Retrieves the query params for collections of attachments.
98+
*
99+
* @since 4.7.0
100+
* @since 6.9.0 Extends the `media_type` and `mime_type` request arguments to support array values.
101+
*
102+
* @return array Query parameters for the attachment collection as an array.
103+
*/
104+
public function get_collection_params() {
105+
$params = parent::get_collection_params();
106+
$params['status']['default'] = 'inherit';
107+
$params['status']['items']['enum'] = array( 'inherit', 'private', 'trash' );
108+
$media_types = array_keys( $this->get_media_types() );
109+
110+
$params['media_type'] = array(
111+
'default' => null,
112+
'description' => __( 'Limit result set to attachments of a particular media type or media types.' ),
113+
'type' => 'array',
114+
'items' => array(
115+
'type' => 'string',
116+
'enum' => $media_types,
117+
),
118+
);
119+
120+
$params['mime_type'] = array(
121+
'default' => null,
122+
'description' => __( 'Limit result set to attachments of a particular MIME type or MIME types.' ),
123+
'type' => 'array',
124+
'items' => array(
125+
'type' => 'string',
126+
),
127+
);
128+
129+
return $params;
130+
}
131+
}

lib/compat/wordpress-6.9/rest-api.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,22 @@ function gutenberg_rest_theme_export_link_rel( $response, $theme ) {
2929
return $response;
3030
}
3131
add_filter( 'rest_prepare_theme', 'gutenberg_rest_theme_export_link_rel', 10, 2 );
32+
33+
/**
34+
* Overrides the REST controller for the attachment post type to add support
35+
* for filtering by multiple media types.
36+
*
37+
* Only applies if the experimental media processing feature is not enabled,
38+
* as that feature includes this functionality and more.
39+
*
40+
* @param array $args Array of arguments for registering a post type.
41+
* @param string $post_type Post type key.
42+
* @return array Modified array of arguments.
43+
*/
44+
function gutenberg_override_attachments_rest_controller( $args, $post_type ) {
45+
if ( 'attachment' === $post_type && ! gutenberg_is_experiment_enabled( 'gutenberg-media-processing' ) ) {
46+
$args['rest_controller_class'] = 'Gutenberg_REST_Attachments_Controller_6_9';
47+
}
48+
return $args;
49+
}
50+
add_filter( 'register_post_type_args', 'gutenberg_override_attachments_rest_controller', 10, 2 );
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
/**
3+
* Compatibility shims for block APIs for WordPress 7.0.
4+
*
5+
* @package gutenberg
6+
*/
7+
8+
if ( ! function_exists( 'gutenberg_resolve_pattern_blocks' ) ) {
9+
/**
10+
* Replaces patterns in a block tree with their content.
11+
*
12+
* @since 6.6.0
13+
* @since 7.0.0 Adds metadata to attributes of single-pattern container blocks.
14+
*
15+
* @param array $blocks An array blocks.
16+
*
17+
* @return array An array of blocks with patterns replaced by their content.
18+
*/
19+
function gutenberg_resolve_pattern_blocks( $blocks ) {
20+
static $inner_content;
21+
// Keep track of seen references to avoid infinite loops.
22+
static $seen_refs = array();
23+
$i = 0;
24+
while ( $i < count( $blocks ) ) {
25+
if ( 'core/pattern' === $blocks[ $i ]['blockName'] ) {
26+
$attrs = $blocks[ $i ]['attrs'];
27+
28+
if ( empty( $attrs['slug'] ) ) {
29+
++$i;
30+
continue;
31+
}
32+
33+
$slug = $attrs['slug'];
34+
35+
if ( isset( $seen_refs[ $slug ] ) ) {
36+
// Skip recursive patterns.
37+
array_splice( $blocks, $i, 1 );
38+
continue;
39+
}
40+
41+
$registry = WP_Block_Patterns_Registry::get_instance();
42+
$pattern = $registry->get_registered( $slug );
43+
44+
// Skip unknown patterns.
45+
if ( ! $pattern ) {
46+
++$i;
47+
continue;
48+
}
49+
//////////////////////////////
50+
// START CORE MODIFICATIONS //
51+
//////////////////////////////
52+
$blocks_to_insert = parse_blocks( trim( $pattern['content'] ) );
53+
54+
/*
55+
* For single-root patterns, add the pattern name to make this a pattern instance in the editor.
56+
* If the pattern has metadata, merge it with the existing metadata.
57+
*/
58+
if ( count( $blocks_to_insert ) === 1 ) {
59+
$block_metadata = $blocks_to_insert[0]['attrs']['metadata'] ?? array();
60+
$block_metadata['patternName'] = $slug;
61+
62+
/*
63+
* Merge pattern metadata with existing block metadata.
64+
* Pattern metadata takes precedence, but existing block metadata
65+
* is preserved as a fallback when the pattern doesn't define that field.
66+
* Only the defined fields (name, description, categories) are updated;
67+
* other metadata keys are preserved.
68+
*/
69+
foreach ( array(
70+
'name' => 'title', // 'title' is the field in the pattern object 'name' is the field in the block metadata.
71+
'description' => 'description',
72+
'categories' => 'categories',
73+
) as $key => $pattern_key ) {
74+
$value = $pattern[ $pattern_key ] ?? $block_metadata[ $key ] ?? null;
75+
if ( $value ) {
76+
$block_metadata[ $key ] = 'categories' === $key && is_array( $value )
77+
? array_map( 'sanitize_text_field', $value )
78+
: sanitize_text_field( $value );
79+
}
80+
}
81+
82+
$blocks_to_insert[0]['attrs']['metadata'] = $block_metadata;
83+
}
84+
//////////////////////////////
85+
// END CORE MODIFICATIONS //
86+
//////////////////////////////
87+
88+
$seen_refs[ $slug ] = true;
89+
$prev_inner_content = $inner_content;
90+
$inner_content = null;
91+
$blocks_to_insert = gutenberg_resolve_pattern_blocks( $blocks_to_insert );
92+
$inner_content = $prev_inner_content;
93+
unset( $seen_refs[ $slug ] );
94+
array_splice( $blocks, $i, 1, $blocks_to_insert );
95+
96+
// If we have inner content, we need to insert nulls in the
97+
// inner content array, otherwise serialize_blocks will skip
98+
// blocks.
99+
if ( $inner_content ) {
100+
$null_indices = array_keys( $inner_content, null, true );
101+
$content_index = $null_indices[ $i ];
102+
$nulls = array_fill( 0, count( $blocks_to_insert ), null );
103+
array_splice( $inner_content, $content_index, 1, $nulls );
104+
}
105+
106+
// Skip inserted blocks.
107+
$i += count( $blocks_to_insert );
108+
} else {
109+
if ( ! empty( $blocks[ $i ]['innerBlocks'] ) ) {
110+
$prev_inner_content = $inner_content;
111+
$inner_content = $blocks[ $i ]['innerContent'];
112+
$blocks[ $i ]['innerBlocks'] = gutenberg_resolve_pattern_blocks(
113+
$blocks[ $i ]['innerBlocks']
114+
);
115+
$blocks[ $i ]['innerContent'] = $inner_content;
116+
$inner_content = $prev_inner_content;
117+
}
118+
++$i;
119+
}
120+
}
121+
return $blocks;
122+
}
123+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* WordPress 7.0 compatibility functions for the Gutenberg
4+
* editor plugin changes related to REST API.
5+
*
6+
* @package gutenberg
7+
*/
8+
9+
/**
10+
* Retrieves a single unified template object using its id.
11+
* Parses pattern blocks in the template content.
12+
*
13+
* @param WP_Block_Template|null $block_template The found block template, or null if there isn't one.
14+
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
15+
* @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
16+
*/
17+
function gutenberg_parse_pattern_blocks_in_block_template( $block_template, $id, $template_type ) {
18+
if ( 'wp_template' !== $template_type ) {
19+
return $block_template;
20+
}
21+
22+
if ( ! empty( $block_template->content ) ) {
23+
$blocks = parse_blocks( $block_template->content );
24+
if ( ! empty( $blocks ) ) {
25+
$blocks = gutenberg_resolve_pattern_blocks( $blocks );
26+
$block_template->content = serialize_blocks( $blocks );
27+
}
28+
}
29+
return $block_template;
30+
}
31+
32+
add_filter( 'get_block_template', 'gutenberg_parse_pattern_blocks_in_block_template', 10, 3 );
33+
add_filter( 'get_block_file_template', 'gutenberg_parse_pattern_blocks_in_block_template', 10, 3 );
34+
35+
/**
36+
* Retrieves a list of unified template objects based on a query.
37+
* Parses pattern blocks in the template content items.
38+
*
39+
* @param WP_Block_Template[] $query_result Array of found block templates.
40+
* @param array $query {
41+
* Arguments to retrieve templates. All arguments are optional.
42+
*
43+
* @type string[] $slug__in List of slugs to include.
44+
* @type int $wp_id Post ID of customized template.
45+
* @type string $area A 'wp_template_part_area' taxonomy value to filter by (for 'wp_template_part' template type only).
46+
* @type string $post_type Post type to get the templates for.
47+
* }
48+
* @param string $template_type wp_template or wp_template_part.
49+
*/
50+
function gutenberg_parse_pattern_blocks_in_block_templates( $query_result, $query, $template_type ) {
51+
if ( 'wp_template' !== $template_type ) {
52+
return $query_result;
53+
}
54+
55+
if ( ! empty( $query_result ) ) {
56+
foreach ( $query_result as $template ) {
57+
$blocks = parse_blocks( $template->content );
58+
if ( ! empty( $blocks ) ) {
59+
$blocks = gutenberg_resolve_pattern_blocks( $blocks );
60+
$template->content = serialize_blocks( $blocks );
61+
}
62+
}
63+
}
64+
return $query_result;
65+
}
66+
67+
add_filter( 'get_block_templates', 'gutenberg_parse_pattern_blocks_in_block_templates', 10, 3 );

0 commit comments

Comments
 (0)