diff --git a/wp-includes/block-supports/aria-label.php b/wp-includes/block-supports/aria-label.php new file mode 100644 index 0000000000..aa559bcacd --- /dev/null +++ b/wp-includes/block-supports/aria-label.php @@ -0,0 +1,70 @@ +attributes ) { + $block_type->attributes = array(); + } + + if ( ! array_key_exists( 'ariaLabel', $block_type->attributes ) ) { + $block_type->attributes['ariaLabel'] = array( + 'type' => 'string', + ); + } +} + +/** + * Add the aria-label to the output. + * + * @since 6.8.0 + * @access private + * + * @param WP_Block_Type $block_type Block Type. + * @param array $block_attributes Block attributes. + * + * @return array Block aria-label. + */ +function wp_apply_aria_label_support( $block_type, $block_attributes ) { + if ( ! $block_attributes ) { + return array(); + } + + $has_aria_label_support = block_has_support( $block_type, array( 'ariaLabel' ), false ); + if ( ! $has_aria_label_support ) { + return array(); + } + + $has_aria_label = array_key_exists( 'ariaLabel', $block_attributes ); + if ( ! $has_aria_label ) { + return array(); + } + return array( 'aria-label' => $block_attributes['ariaLabel'] ); +} + +// Register the block support. +WP_Block_Supports::get_instance()->register( + 'aria-label', + array( + 'register_attribute' => 'wp_register_aria_label_support', + 'apply' => 'wp_apply_aria_label_support', + ) +); diff --git a/wp-includes/class-wp-block-supports.php b/wp-includes/class-wp-block-supports.php index 71d6b49691..ec5bc9c8d6 100644 --- a/wp-includes/class-wp-block-supports.php +++ b/wp-includes/class-wp-block-supports.php @@ -181,7 +181,7 @@ function get_block_wrapper_attributes( $extra_attributes = array() ) { // This is hardcoded on purpose. // We only support a fixed list of attributes. - $attributes_to_merge = array( 'style', 'class', 'id' ); + $attributes_to_merge = array( 'style', 'class', 'id', 'aria-label' ); $attributes = array(); foreach ( $attributes_to_merge as $attribute_name ) { if ( empty( $new_attributes[ $attribute_name ] ) && empty( $extra_attributes[ $attribute_name ] ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 42a917a33f..a0043a8738 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.8-alpha-59924'; +$wp_version = '6.8-alpha-59925'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-settings.php b/wp-settings.php index 8f835bc31b..f5a0929db8 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -387,6 +387,7 @@ require ABSPATH . WPINC . '/block-supports/duotone.php'; require ABSPATH . WPINC . '/block-supports/shadow.php'; require ABSPATH . WPINC . '/block-supports/background.php'; require ABSPATH . WPINC . '/block-supports/block-style-variations.php'; +require ABSPATH . WPINC . '/block-supports/aria-label.php'; require ABSPATH . WPINC . '/style-engine.php'; require ABSPATH . WPINC . '/style-engine/class-wp-style-engine.php'; require ABSPATH . WPINC . '/style-engine/class-wp-style-engine-css-declarations.php';