Skip to content

Commit

Permalink
Merge branch 'trunk' into focal-point-40px
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Aug 14, 2024
2 parents e44c4ba + c202737 commit e6ba38e
Show file tree
Hide file tree
Showing 182 changed files with 3,391 additions and 1,345 deletions.
24 changes: 23 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ module.exports = {
},
},
{
// Temporary rules until we're ready to officially deprecate the bottom margins.
files: [ 'packages/*/src/**/*.[tj]s?(x)' ],
excludedFiles: [
'packages/components/src/**/@(test|stories)/**',
Expand All @@ -289,7 +288,9 @@ module.exports = {
'error',
...restrictedSyntax,
...restrictedSyntaxComponents,
// Temporary rules until we're ready to officially deprecate the bottom margins.
...[
'BaseControl',
'CheckboxControl',
'ComboboxControl',
'DimensionControl',
Expand All @@ -308,6 +309,27 @@ module.exports = {
componentName +
' should have the `__nextHasNoMarginBottom` prop to opt-in to the new margin-free styles.',
} ) ),
// Temporary rules until we're ready to officially default to the new size.
...[
'BorderBoxControl',
'BorderControl',
'DimensionControl',
'FontSizePicker',
].map( ( componentName ) => ( {
// Falsy `__next40pxDefaultSize` without a non-default `size` prop.
selector: `JSXOpeningElement[name.name="${ componentName }"]:not(:has(JSXAttribute[name.name="__next40pxDefaultSize"][value.expression.value!=false])):not(:has(JSXAttribute[name.name="size"][value.value!="default"]))`,
message:
componentName +
' should have the `__next40pxDefaultSize` prop to opt-in to the new default size.',
} ) ),
// Temporary rules until all existing components have the `__next40pxDefaultSize` prop.
...[ 'TextControl' ].map( ( componentName ) => ( {
// Not strict. Allows pre-existing __next40pxDefaultSize={ false } usage until they are all manually updated.
selector: `JSXOpeningElement[name.name="${ componentName }"]:not(:has(JSXAttribute[name.name="__next40pxDefaultSize"])):not(:has(JSXAttribute[name.name="size"]))`,
message:
componentName +
' should have the `__next40pxDefaultSize` prop to opt-in to the new default size.',
} ) ),
],
},
},
Expand Down
3 changes: 3 additions & 0 deletions backport-changelog/6.6/7145.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/7145

* https://github.com/WordPress/gutenberg/pull/64076
3 changes: 3 additions & 0 deletions backport-changelog/6.7/7125.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/7125

* https://github.com/WordPress/gutenberg/pull/61577
5 changes: 5 additions & 0 deletions backport-changelog/6.7/7179.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
https://github.com/WordPress/wordpress-develop/pull/7179

* https://github.com/WordPress/gutenberg/pull/64401
* https://github.com/WordPress/gutenberg/pull/64459
* https://github.com/WordPress/gutenberg/pull/64477
2 changes: 1 addition & 1 deletion docs/getting-started/fundamentals/block-wrapper.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ The [example block](https://github.com/WordPress/block-development-examples/tree

## Dynamic render markup

In dynamic blocks, where the font-end markup is rendered server-side, you can utilize the [`get_block_wrapper_attributes()`](https://developer.wordpress.org/reference/functions/get_block_wrapper_attributes/) function to output the necessary classes and attributes just like you would use `useBlockProps.save()` in the `save` function. (See [example](https://github.com/WordPress/block-development-examples/blob/f68640f42d993f0866d1879f67c73910285ca114/plugins/block-dynamic-rendering-64756b/src/render.php#L11))
In dynamic blocks, where the front-end markup is rendered server-side, you can utilize the [`get_block_wrapper_attributes()`](https://developer.wordpress.org/reference/functions/get_block_wrapper_attributes/) function to output the necessary classes and attributes just like you would use `useBlockProps.save()` in the `save` function. (See [example](https://github.com/WordPress/block-development-examples/blob/f68640f42d993f0866d1879f67c73910285ca114/plugins/block-dynamic-rendering-64756b/src/render.php#L11))

```php
<p <?php echo get_block_wrapper_attributes(); ?>>
Expand Down
8 changes: 4 additions & 4 deletions docs/reference-guides/filters/block-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ The following PHP filters are available to change the output of a block on the f

### `render_block`

Filters the font-end content of any block. This filter has no impact on the behavior of blocks in the Editor.
Filters the front-end content of any block. This filter has no impact on the behavior of blocks in the Editor.

The callback function for this filter receives three parameters:

- `$block_content` (`string`): The block content.
- `block` (`array`): The full block, including name and attributes.
- `$block` (`array`): The full block, including name and attributes.
- `$instance` (`WP_Block`): The block instance.

In the following example, the class `example-class` is added to all Paragraph blocks on the front end. Here the [HTML API](https://make.wordpress.org/core/2023/03/07/introducing-the-html-api-in-wordpress-6-2/) is used to easily add the class instead of relying on regex.
Expand Down Expand Up @@ -172,12 +172,12 @@ add_filter( 'render_block', 'example_add_custom_class_to_paragraph_block', 10, 2

### `render_block_{namespace/block}`

Filters the font-end content of the defined block. This is just a simpler form of `render_block` when you only need to modify a specific block type.
Filters the front-end content of the defined block. This is just a simpler form of `render_block` when you only need to modify a specific block type.

The callback function for this filter receives three parameters:

- `$block_content` (`string`): The block content.
- `block` (`array`): The full block, including name and attributes.
- `$block` (`array`): The full block, including name and attributes.
- `$instance` (`WP_Block`): The block instance.

In the following example, the class `example-class` is added to all Paragraph blocks on the front end. Notice that compared to the `render_block` example above, you no longer need to check the block type before modifying the content. Again, the [HTML API](https://make.wordpress.org/core/2023/03/07/introducing-the-html-api-in-wordpress-6-2/) is used instead of regex.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference-guides/interactivity-api/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ Actions are just regular JavaScript functions. Usually triggered by the `data-wp
```ts
const { state, actions } = store("myPlugin", {
actions: {
selectItem: (id?: number) => {
selectItem: ( id ) => {
const context = getContext();
// `id` is optional here, so this action can be used in a directive.
state.selected = id || context.id;
Expand Down
2 changes: 1 addition & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Printing since 1440. This is the development plugin for the block editor, site editor, and other future WordPress core functionality.
* Requires at least: 6.5
* Requires PHP: 7.2
* Version: 19.0.0-rc.1
* Version: 19.0.0
* Author: Gutenberg Team
* Text Domain: gutenberg
*
Expand Down
2 changes: 1 addition & 1 deletion lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,7 @@ protected function get_layout_styles( $block_metadata, $types = array() ) {
$spacing_rule['selector']
);
} else {
$format = static::ROOT_BLOCK_SELECTOR === $selector ? '.%2$s %3$s' : '%1$s-%2$s %3$s';
$format = static::ROOT_BLOCK_SELECTOR === $selector ? ':root :where(.%2$s)%3$s' : ':root :where(%1$s-%2$s)%3$s';
$layout_selector = sprintf(
$format,
$selector,
Expand Down
41 changes: 41 additions & 0 deletions lib/compat/wordpress-6.7/block-templates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Block template functions.
*
* @package gutenberg
*/

if ( ! function_exists( 'wp_register_block_template' ) ) {
/**
* Register a template.
*
* @param string $template_name Template name in the form of `plugin_uri//template_name`.
* @param array|string $args Object type or array of object types with which the taxonomy should be associated.
* @param array|string $args {
* @type string $title Optional. Title of the template as it will be shown in the Site Editor
* and other UI elements.
* @type string $description Optional. Description of the template as it will be shown in the Site
* Editor.
* @type string $content Optional. Default content of the template that will be used when the
* template is rendered or edited in the editor.
* @type string[] $post_types Optional. Array of post types to which the template should be available.
* @type string $plugin Uri of the plugin that registers the template.
* }
* @return WP_Block_Template|WP_Error The registered template object on success, WP_Error object on failure.
*/
function wp_register_block_template( $template_name, $args = array() ) {
return WP_Block_Templates_Registry::get_instance()->register( $template_name, $args );
}
}

if ( ! function_exists( 'wp_unregister_block_template' ) ) {
/**
* Unregister a template.
*
* @param string $template_name Template name in the form of `plugin_uri//template_name`.
* @return true|WP_Error True on success, WP_Error on failure or if the template doesn't exist.
*/
function wp_unregister_block_template( $template_name ) {
return WP_Block_Templates_Registry::get_instance()->unregister( $template_name );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
<?php
/**
* REST API: Gutenberg_REST_Templates_Controller_6_7 class
*
* @package gutenberg
*/

/**
* Gutenberg_REST_Templates_Controller_6_7 class
*
*/
class Gutenberg_REST_Templates_Controller_6_7 extends Gutenberg_REST_Templates_Controller_6_6 {
/**
* Returns the given template
*
* @param WP_REST_Request $request The request instance.
* @return WP_REST_Response|WP_Error
*/
public function get_item( $request ) {
if ( isset( $request['source'] ) && ( 'theme' === $request['source'] || 'plugin' === $request['source'] ) ) {
$template = get_block_file_template( $request['id'], $this->post_type );
} else {
$template = get_block_template( $request['id'], $this->post_type );
}

if ( ! $template ) {
return new WP_Error( 'rest_template_not_found', __( 'No templates exist with that id.' ), array( 'status' => 404 ) );
}

return $this->prepare_item_for_response( $template, $request );
}

/**
* Prepare a single template output for response
*
* @param WP_Block_Template $item Template instance.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response Response object.
*/
// @core-merge: Fix wrong author in plugin templates.
public function prepare_item_for_response( $item, $request ) {
$template = $item;

$fields = $this->get_fields_for_response( $request );

if ( 'plugin' !== $item->origin ) {
return parent::prepare_item_for_response( $item, $request );
}
$cloned_item = clone $item;
// Set the origin as theme when calling the previous `prepare_item_for_response()` to prevent warnings when generating the author text.
$cloned_item->origin = 'theme';
$response = parent::prepare_item_for_response( $cloned_item, $request );
$data = $response->data;

if ( rest_is_field_included( 'origin', $fields ) ) {
$data['origin'] = 'plugin';
}

if ( rest_is_field_included( 'plugin', $fields ) ) {
$registered_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $cloned_item->slug );
if ( $registered_template ) {
$data['plugin'] = $registered_template->plugin;
}
}

if ( rest_is_field_included( 'author_text', $fields ) ) {
$data['author_text'] = $this->get_wp_templates_author_text_field( $template );
}

if ( rest_is_field_included( 'original_source', $fields ) ) {
$data['original_source'] = $this->get_wp_templates_original_source_field( $template );
}

$response = rest_ensure_response( $data );

if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) {
$links = $this->prepare_links( $template->id );
$response->add_links( $links );
if ( ! empty( $links['self']['href'] ) ) {
$actions = $this->get_available_actions();
$self = $links['self']['href'];
foreach ( $actions as $rel ) {
$response->add_link( $rel, $self );
}
}
}

return $response;
}

/**
* Returns the source from where the template originally comes from.
*
* @param WP_Block_Template $template_object Template instance.
* @return string Original source of the template one of theme, plugin, site, or user.
*/
// @core-merge: Changed the comments format (from inline to multi-line) in the entire function.
private static function get_wp_templates_original_source_field( $template_object ) {
if ( 'wp_template' === $template_object->type || 'wp_template_part' === $template_object->type ) {
/*
* Added by theme.
* Template originally provided by a theme, but customized by a user.
* Templates originally didn't have the 'origin' field so identify
* older customized templates by checking for no origin and a 'theme'
* or 'custom' source.
*/
if ( $template_object->has_theme_file &&
( 'theme' === $template_object->origin || (
empty( $template_object->origin ) && in_array(
$template_object->source,
array(
'theme',
'custom',
),
true
) )
)
) {
return 'theme';
}

// Added by plugin.
// @core-merge: Removed `$template_object->has_theme_file` check from this if clause.
if ( 'plugin' === $template_object->origin ) {
return 'plugin';
}

/*
* Added by site.
* Template was created from scratch, but has no author. Author support
* was only added to templates in WordPress 5.9. Fallback to showing the
* site logo and title.
*/
if ( empty( $template_object->has_theme_file ) && 'custom' === $template_object->source && empty( $template_object->author ) ) {
return 'site';
}
}

// Added by user.
return 'user';
}

/**
* Returns a human readable text for the author of the template.
*
* @param WP_Block_Template $template_object Template instance.
* @return string Human readable text for the author.
*/
private static function get_wp_templates_author_text_field( $template_object ) {
$original_source = self::get_wp_templates_original_source_field( $template_object );
switch ( $original_source ) {
case 'theme':
$theme_name = wp_get_theme( $template_object->theme )->get( 'Name' );
return empty( $theme_name ) ? $template_object->theme : $theme_name;
case 'plugin':
// @core-merge: Prioritize plugin name instead of theme name for plugin-registered templates.
if ( ! function_exists( 'get_plugins' ) || ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if ( isset( $template_object->plugin ) ) {
$plugins = wp_get_active_and_valid_plugins();

foreach ( $plugins as $plugin_file ) {
$plugin_basename = plugin_basename( $plugin_file );
// Split basename by '/' to get the plugin slug.
list( $plugin_slug, ) = explode( '/', $plugin_basename );

if ( $plugin_slug === $template_object->plugin ) {
$plugin_data = get_plugin_data( $plugin_file );

if ( ! empty( $plugin_data['Name'] ) ) {
return $plugin_data['Name'];
}

break;
}
}
}

/*
* Fall back to the theme name if the plugin is not defined. That's needed to keep backwards
* compatibility with templates that were registered before the plugin attribute was added.
*/
$plugins = get_plugins();
$plugin_basename = plugin_basename( sanitize_text_field( $template_object->theme . '.php' ) );
if ( isset( $plugins[ $plugin_basename ] ) && isset( $plugins[ $plugin_basename ]['Name'] ) ) {
return $plugins[ $plugin_basename ]['Name'];
}
return isset( $template_object->plugin ) ?
$template_object->plugin :
$template_object->theme;
// @core-merge: End of changes to merge in core.
case 'site':
return get_bloginfo( 'name' );
case 'user':
$author = get_user_by( 'id', $template_object->author );
if ( ! $author ) {
return __( 'Unknown author' );
}
return $author->get( 'display_name' );
}
}
}
Loading

0 comments on commit e6ba38e

Please sign in to comment.