lib/block-supports
anchor.php
1.4 KB
7 months ago
aria-label.php
1.6 KB
6 months ago
background.php
4.6 KB
5 months ago
block-style-variations.php
10.3 KB
7 months ago
block-visibility.php
5.4 KB
5 months ago
border.php
6.0 KB
1 year ago
colors.php
5.7 KB
5 months ago
custom-css.php
8.6 KB
4 months ago
dimensions.php
5.4 KB
4 months ago
duotone.php
12.3 KB
5 months ago
elements.php
8.8 KB
7 months ago
layout.php
45.7 KB
4 months ago
position.php
4.2 KB
2 years ago
settings.php
4.5 KB
1 year ago
shadow.php
2.0 KB
2 years ago
spacing.php
2.6 KB
7 months ago
typography.php
27.5 KB
6 months ago
aria-label.php in Gutenberg 23.2.0, at lib/block-supports/aria-label.php
| 1 | <?php |
| 2 | /** |
| 3 | * Aria label block support flag. |
| 4 | * |
| 5 | * @package gutenberg |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Registers the aria-label block attribute for block types that support it. |
| 10 | * |
| 11 | * @param WP_Block_Type $block_type Block Type. |
| 12 | */ |
| 13 | function gutenberg_register_aria_label_support( $block_type ) { |
| 14 | $has_aria_label_support = block_has_support( $block_type, array( 'ariaLabel' ), false ); |
| 15 | |
| 16 | if ( ! $has_aria_label_support ) { |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | if ( ! $block_type->attributes ) { |
| 21 | $block_type->attributes = array(); |
| 22 | } |
| 23 | |
| 24 | if ( ! array_key_exists( 'ariaLabel', $block_type->attributes ) ) { |
| 25 | $block_type->attributes['ariaLabel'] = array( |
| 26 | 'type' => 'string', |
| 27 | ); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Add the aria-label to the output. |
| 33 | * |
| 34 | * @param WP_Block_Type $block_type Block Type. |
| 35 | * @param array $block_attributes Block attributes. |
| 36 | * |
| 37 | * @return array Block aria-label. |
| 38 | */ |
| 39 | function gutenberg_apply_aria_label_support( $block_type, $block_attributes ) { |
| 40 | if ( ! $block_attributes ) { |
| 41 | return array(); |
| 42 | } |
| 43 | |
| 44 | $has_aria_label_support = block_has_support( $block_type, array( 'ariaLabel' ), false ); |
| 45 | if ( |
| 46 | ! $has_aria_label_support || |
| 47 | wp_should_skip_block_supports_serialization( $block_type, 'ariaLabel' ) |
| 48 | ) { |
| 49 | return array(); |
| 50 | } |
| 51 | |
| 52 | $has_aria_label = array_key_exists( 'ariaLabel', $block_attributes ); |
| 53 | if ( ! $has_aria_label ) { |
| 54 | return array(); |
| 55 | } |
| 56 | return array( 'aria-label' => $block_attributes['ariaLabel'] ); |
| 57 | } |
| 58 | |
| 59 | // Register the block support. |
| 60 | WP_Block_Supports::get_instance()->register( |
| 61 | 'aria-label', |
| 62 | array( |
| 63 | 'register_attribute' => 'gutenberg_register_aria_label_support', |
| 64 | 'apply' => 'gutenberg_apply_aria_label_support', |
| 65 | ) |
| 66 | ); |
| 67 |