Skip to content

Commit

Permalink
Merge branch 'trunk' into try/simplify-navigate-regions-shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
stokesman authored Sep 18, 2024
2 parents dfb5f6d + 07c6a1f commit 2a9aa4c
Show file tree
Hide file tree
Showing 71 changed files with 1,303 additions and 594 deletions.
1 change: 1 addition & 0 deletions backport-changelog/6.7/7139.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
https://github.com/WordPress/wordpress-develop/pull/7139

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

* https://github.com/WordPress/gutenberg/pull/65071
8 changes: 4 additions & 4 deletions docs/getting-started/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ To complete this tutorial, you will need:
If you don't have one or more of these items, the [Block Development Environment](https://developer.wordpress.org/block-editor/getting-started/devenv/) documentation will help you get started. Come back here once you are all set up.

<div class="callout callout-info">
This tutorial uses <a href="https://developer.wordpress.org/block-editor/getting-started/devenv/get-started-with-wp-env/"><code>wp-env</code></a> to create a local WordPress development environment. However, feel free to use alternate local development tools if you already have one that you prefer.
This tutorial uses <a href="https://developer.wordpress.org/block-editor/getting-started/devenv/get-started-with-wp-env/"><code>wp-env</code></a> to create a local WordPress development environment. However, feel free to use any development environment that meets the abovementioned prerequisites.
</div>

## Scaffolding the block
Expand Down Expand Up @@ -250,7 +250,7 @@ At this point, the block's icon and description are correct, and block supports

### Updating edit.js

The [`edit.js`](https://developer.wordpress.org/block-editor/getting-started/fundamentals/file-structure-of-a-block/#edit-js) file controls how the block functions and appears in the Editor. Right now, the user sees the message " Copyright Date Block – hello from the editor!". Let's change that.
The [`edit.js`](https://developer.wordpress.org/block-editor/getting-started/fundamentals/file-structure-of-a-block/#edit-js) file controls how the block functions and appears in the Editor. Right now, the user sees the message "Copyright Date Block – hello from the editor!". Let's change that.

Open the file and see that the `Edit()` function returns a paragraph tag with the default message.

Expand Down Expand Up @@ -647,10 +647,10 @@ While the Editor looks great, the starting year functionality has yet to be adde
Start by adding a variable called `$display_date` and replicate what you did in the `Edit()` function above.
This variable should display the value of the `startingYear` attribute and the `$current_year` variable separated by an em dash, or just the `$current_year` is the `showStartingYear` attribute is `false`.
This variable should display the value of the `startingYear` attribute and the `$current_year` variable separated by an em dash, or just the `$current_year` if the `showStartingYear` attribute is `false`.
<div class="callout callout-tip">
<p>Three variables are exposed in the <code>render.php</code>, which you can use to customize the block's output:</p>
<p>Three variables are exposed in <code>render.php</code>, which you can use to customize the block's output:</p>
<ul>
<li><code>$attributes</code> (array): The block attributes.</li>
<li><code>$content</code> (string): The block default content.</li>
Expand Down
6 changes: 3 additions & 3 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ A calendar of your site’s posts. ([Source](https://github.com/WordPress/gutenb
- **Supports:** align, color (background, link, text), interactivity (clientNavigation), typography (fontSize, lineHeight)
- **Attributes:** month, year

## Categories List
## Terms List

Display a list of all categories. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/categories))
Display a list of all terms of a given taxonomy. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/categories))

- **Name:** core/categories
- **Category:** widgets
- **Supports:** align, interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** displayAsDropdown, label, showEmpty, showHierarchy, showLabel, showOnlyTopLevel, showPostCounts
- **Attributes:** displayAsDropdown, label, showEmpty, showHierarchy, showLabel, showOnlyTopLevel, showPostCounts, taxonomy

## Code

Expand Down
51 changes: 24 additions & 27 deletions lib/class-wp-rest-global-styles-controller-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,27 +532,39 @@ public function get_item_schema() {
* Checks if a given request has access to read a single theme global styles config.
*
* @since 5.9.0
* @since 6.7.0 Allow users with edit post capabilities to view theme global styles.
*
* @param WP_REST_Request $request Full details about the request.
* @return true|WP_Error True if the request has read access for the item, WP_Error object otherwise.
*/
public function get_theme_item_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
/*
* Verify if the current user has edit_posts capability.
*/
if ( current_user_can( 'edit_posts' ) ) {
return true;
}

foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
if ( current_user_can( $post_type->cap->edit_posts ) ) {
return true;
}
}

/*
* Verify if the current user has edit_theme_options capability.
* This capability is required to edit/view/delete global styles.
*/
if ( ! current_user_can( 'edit_theme_options' ) ) {
return new WP_Error(
'rest_cannot_manage_global_styles',
__( 'Sorry, you are not allowed to access the global styles on this site.', 'gutenberg' ),
array(
'status' => rest_authorization_required_code(),
)
);
if ( current_user_can( 'edit_theme_options' ) ) {
return true;
}

return true;
return new WP_Error(
'rest_cannot_read_global_styles',
__( 'Sorry, you are not allowed to access the global styles on this site.', 'gutenberg' ),
array(
'status' => rest_authorization_required_code(),
)
);
}

/**
Expand Down Expand Up @@ -616,23 +628,8 @@ public function get_theme_item( $request ) {
* @param WP_REST_Request $request Full details about the request.
* @return true|WP_Error True if the request has read access for the item, WP_Error object otherwise.
*/
public function get_theme_items_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable

/*
* Verify if the current user has edit_theme_options capability.
* This capability is required to edit/view/delete global styles.
*/
if ( ! current_user_can( 'edit_theme_options' ) ) {
return new WP_Error(
'rest_cannot_manage_global_styles',
__( 'Sorry, you are not allowed to access the global styles on this site.', 'gutenberg' ),
array(
'status' => rest_authorization_required_code(),
)
);
}

return true;
public function get_theme_items_permissions_check( $request ) {
return $this->get_theme_item_permissions_check( $request );
}

/**
Expand Down
38 changes: 27 additions & 11 deletions lib/compat/wordpress-6.7/class-gutenberg-rest-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,33 @@ public static function get_response_links( $response ) {
continue;
}

$match = $server->match_request_to_handler( $request );
if ( ! is_wp_error( $match ) ) {
$response = new WP_REST_Response();
$response->set_matched_route( $match[0] );
$response->set_matched_handler( $match[1] );
$headers = rest_send_allow_header( $response, $server, $request )->get_headers();

foreach ( $headers as $name => $value ) {
$name = WP_REST_Request::canonicalize_header_name( $name );
$attributes['targetHints'][ $name ] = array_map( 'trim', explode( ',', $value ) );
}
$matched = $server->match_request_to_handler( $request );

if ( is_wp_error( $matched ) ) {
$data[ $rel ][] = $attributes;
continue;
}

if ( is_wp_error( $request->has_valid_params() ) ) {
$data[ $rel ][] = $attributes;
continue;
}

if ( is_wp_error( $request->sanitize_params() ) ) {
$data[ $rel ][] = $attributes;
continue;
}

list( $route, $handler ) = $matched;

$response = new WP_REST_Response();
$response->set_matched_route( $route );
$response->set_matched_handler( $handler );
$headers = rest_send_allow_header( $response, $server, $request )->get_headers();

foreach ( $headers as $name => $value ) {
$name = WP_REST_Request::canonicalize_header_name( $name );
$attributes['targetHints'][ $name ] = array_map( 'trim', explode( ',', $value ) );
}

$data[ $rel ][] = $attributes;
Expand Down
23 changes: 23 additions & 0 deletions lib/compat/wordpress-6.7/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,26 @@ function gutenberg_override_default_rest_server() {
return 'Gutenberg_REST_Server';
}
add_filter( 'wp_rest_server_class', 'gutenberg_override_default_rest_server', 1 );


/**
* Filters the arguments for registering a wp_global_styles post type.
* Note when syncing to Core: the capabilities should be updates for `wp_global_styles` in the wp-includes/post.php.
*
* @since 6.7.0
*
* @param array $args Array of arguments for registering a post type.
* See the register_post_type() function for accepted arguments.
* @param string $post_type Post type key.
*
* @return array Array of arguments for registering a post type.
*/
function gutenberg_register_post_type_args_for_wp_global_styles( $args, $post_type ) {
if ( 'wp_global_styles' === $post_type ) {
$args['capabilities']['read'] = 'edit_posts';
}

return $args;
}

add_filter( 'register_post_type_args', 'gutenberg_register_post_type_args_for_wp_global_styles', 10, 2 );
49 changes: 42 additions & 7 deletions lib/experimental/script-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,45 @@ function gutenberg_dequeue_module( $module_identifier ) {
wp_script_modules()->dequeue( $module_identifier );
}

/**
* Prints HTML for the a11y Script Module.
*
* a11y relies on some DOM elements to use as ARIA live regions.
* Ideally, these elements are part of the initial HTML of the page
* so that accessibility tools can find them and observe updates.
*/
function gutenberg_a11y_script_module_html() {
$a11y_module_available = false;

$get_marked_for_enqueue = new ReflectionMethod( 'WP_Script_Modules', 'get_marked_for_enqueue' );
$get_marked_for_enqueue->setAccessible( true );
$get_import_map = new ReflectionMethod( 'WP_Script_Modules', 'get_import_map' );
$get_import_map->setAccessible( true );

foreach ( array_keys( $get_marked_for_enqueue->invoke( wp_script_modules() ) ) as $id ) {
if ( '@wordpress/a11y' === $id ) {
$a11y_module_available = true;
break;
}
}
if ( ! $a11y_module_available ) {
foreach ( array_keys( $get_import_map->invoke( wp_script_modules() )['imports'] ) as $id ) {
if ( '@wordpress/a11y' === $id ) {
$a11y_module_available = true;
break;
}
}
}
if ( ! $a11y_module_available ) {
return;
}
echo '<div style="position:absolute;margin:-1px;padding:0;height:1px;width:1px;overflow:hidden;clip-path:inset(50%);border:0;word-wrap:normal !important;">'
. '<p id="a11y-speak-intro-text" class="a11y-speak-intro-text" hidden>' . esc_html__( 'Notifications', 'default' ) . '</p>'
. '<div id="a11y-speak-assertive" class="a11y-speak-region" aria-live="assertive" aria-relevant="additions text" aria-atomic="true"></div>'
. '<div id="a11y-speak-polite" class="a11y-speak-region" aria-live="polite" aria-relevant="additions text" aria-atomic="true"></div>'
. '</div>';
}

/**
* Registers Gutenberg Script Modules.
*
Expand All @@ -218,12 +257,8 @@ function gutenberg_register_script_modules() {
array(),
$default_version
);
add_filter(
'script_module_data_@wordpress/a11y',
function ( $data ) {
$data['i18n'] = array( 'Notifications' => __( 'Notifications', 'default' ) );
return $data;
}
);

add_action( 'wp_footer', 'gutenberg_a11y_script_module_html' );
add_action( 'admin_footer', 'gutenberg_a11y_script_module_html' );
}
add_action( 'init', 'gutenberg_register_script_modules' );
36 changes: 34 additions & 2 deletions lib/interactivity-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,41 @@ function gutenberg_reregister_interactivity_script_modules() {
wp_register_script_module(
'@wordpress/interactivity-router',
gutenberg_url( '/build-module/interactivity-router/index.min.js' ),
array( '@wordpress/interactivity' ),
array(
array(
'id' => '@wordpress/a11y',
'import' => 'dynamic',
),
'@wordpress/interactivity',
),
$default_version
);
}

add_action( 'init', 'gutenberg_reregister_interactivity_script_modules' );

/**
* Adds script data to the interactivity-router script module.
*
* This filter is registered conditionally anticipating a WordPress Core change to add the script module data.
* The filter runs on 'after_setup_theme' (when Core registers Interactivity and Script Modules hooks)
* to ensure that the conditional registration happens after Core and correctly determine whether
* the filter should be added.
*
* @see https://github.com/WordPress/wordpress-develop/pull/7304
*/
function gutenberg_register_interactivity_script_module_data_hooks() {
if ( ! has_filter( 'script_module_data_@wordpress/interactivity-router', array( wp_interactivity(), 'filter_script_module_interactivity_router_data' ) ) ) {
add_filter(
'script_module_data_@wordpress/interactivity-router',
function ( $data ) {
if ( ! isset( $data['i18n'] ) ) {
$data['i18n'] = array();
}
$data['i18n']['loading'] = __( 'Loading page, please wait.', 'default' );
$data['i18n']['loaded'] = __( 'Page Loaded.', 'default' );
return $data;
}
);
}
}
add_action( 'after_setup_theme', 'gutenberg_register_interactivity_script_module_data_hooks', 20 );
2 changes: 2 additions & 0 deletions package-lock.json

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

25 changes: 22 additions & 3 deletions packages/a11y/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,37 @@
* WordPress dependencies
*/
import domReady from '@wordpress/dom-ready';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { makeSetupFunction } from './shared/index';
import addContainer from './script/add-container';
import addIntroText from './script/add-intro-text';

export { speak } from './shared/index';

/**
* Create the live regions.
*/
export const setup = makeSetupFunction( __( 'Notifications' ) );
export function setup() {
const introText = document.getElementById( 'a11y-speak-intro-text' );
const containerAssertive = document.getElementById(
'a11y-speak-assertive'
);
const containerPolite = document.getElementById( 'a11y-speak-polite' );

if ( introText === null ) {
addIntroText();
}

if ( containerAssertive === null ) {
addContainer( 'assertive' );
}

if ( containerPolite === null ) {
addContainer( 'polite' );
}
}

/**
* Run setup on domReady.
Expand Down
22 changes: 4 additions & 18 deletions packages/a11y/src/module/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
/**
* Internal dependencies
*/
import { makeSetupFunction } from '../shared/index';
export { speak } from '../shared/index';

// Without an i18n Script Module, "Notifications" (the only localized text used in this module)
// will be translated on the server and provided as script-module data.
let notificationsText = 'Notifications';
try {
const textContent = document.getElementById(
'wp-script-module-data-@wordpress/a11y'
)?.textContent;
if ( textContent ) {
const parsed = JSON.parse( textContent );
notificationsText = parsed?.i18n?.Notifications ?? notificationsText;
}
} catch {}

/**
* Create the live regions.
* This no-op function is exported to provide compatibility with the `wp-a11y` Script.
*
* Filters should inject the relevant HTML on page load instead of requiring setup.
*/
export const setup = makeSetupFunction( notificationsText );

setup();
export const setup = () => {};
File renamed without changes.
Loading

0 comments on commit 2a9aa4c

Please sign in to comment.