[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/block-supports/ -> aria-label.php (source)

   1  <?php
   2  /**
   3   * Aria label block support flag.
   4   *
   5   * @package WordPress
   6   * @since 6.8.0
   7   */
   8  
   9  /**
  10   * Registers the aria-label block attribute for block types that support it.
  11   *
  12   * @since 6.8.0
  13   * @access private
  14   *
  15   * @param WP_Block_Type $block_type Block Type.
  16   */
  17  function wp_register_aria_label_support( $block_type ) {
  18      $has_aria_label_support = block_has_support( $block_type, array( 'ariaLabel' ), false );
  19  
  20      if ( ! $has_aria_label_support ) {
  21          return;
  22      }
  23  
  24      if ( ! $block_type->attributes ) {
  25          $block_type->attributes = array();
  26      }
  27  
  28      if ( ! array_key_exists( 'ariaLabel', $block_type->attributes ) ) {
  29          $block_type->attributes['ariaLabel'] = array(
  30              'type' => 'string',
  31          );
  32      }
  33  }
  34  
  35  /**
  36   * Add the aria-label to the output.
  37   *
  38   * @since 6.8.0
  39   * @access private
  40   *
  41   * @param WP_Block_Type $block_type       Block Type.
  42   * @param array         $block_attributes Block attributes.
  43   * @return array Block aria-label.
  44   */
  45  function wp_apply_aria_label_support( $block_type, $block_attributes ) {
  46      if ( ! $block_attributes ) {
  47          return array();
  48      }
  49  
  50      $has_aria_label_support = block_has_support( $block_type, array( 'ariaLabel' ), false );
  51      if (
  52          ! $has_aria_label_support ||
  53          wp_should_skip_block_supports_serialization( $block_type, 'ariaLabel' )
  54      ) {
  55          return array();
  56      }
  57  
  58      $has_aria_label = array_key_exists( 'ariaLabel', $block_attributes );
  59      if ( ! $has_aria_label ) {
  60          return array();
  61      }
  62      return array( 'aria-label' => $block_attributes['ariaLabel'] );
  63  }
  64  
  65  // Register the block support.
  66  WP_Block_Supports::get_instance()->register(
  67      'aria-label',
  68      array(
  69          'register_attribute' => 'wp_register_aria_label_support',
  70          'apply'              => 'wp_apply_aria_label_support',
  71      )
  72  );


Generated : Thu Aug 27 08:20:25 2026 Cross-referenced by PHPXref