| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Anchor block support flag. 4 * 5 * @package WordPress 6 * @since 7.0.0 7 */ 8 9 /** 10 * Registers the anchor block attribute for block types that support it. 11 * 12 * @since 7.0.0 13 * @access private 14 * 15 * @param WP_Block_Type $block_type Block Type. 16 */ 17 function wp_register_anchor_support( WP_Block_Type $block_type ) { 18 if ( ! block_has_support( $block_type, array( 'anchor' ) ) ) { 19 return; 20 } 21 22 if ( ! isset( $block_type->attributes ) ) { 23 $block_type->attributes = array(); 24 } 25 26 if ( ! array_key_exists( 'anchor', $block_type->attributes ) ) { 27 $block_type->attributes['anchor'] = array( 28 'type' => 'string', 29 ); 30 } 31 } 32 33 /** 34 * Add the anchor id to the output. 35 * 36 * @since 7.0.0 37 * @access private 38 * 39 * @param WP_Block_Type $block_type Block Type. 40 * @param array<string, mixed> $block_attributes Block attributes. 41 * @return array<string, string> Attributes with block anchor id. 42 */ 43 function wp_apply_anchor_support( WP_Block_Type $block_type, array $block_attributes ): array { 44 if ( empty( $block_attributes ) ) { 45 return array(); 46 } 47 48 if ( ! block_has_support( $block_type, array( 'anchor' ) ) ) { 49 return array(); 50 } 51 52 if ( ! isset( $block_attributes['anchor'] ) || ! is_string( $block_attributes['anchor'] ) || '' === $block_attributes['anchor'] ) { 53 return array(); 54 } 55 56 return array( 'id' => $block_attributes['anchor'] ); 57 } 58 59 // Register the block support. 60 WP_Block_Supports::get_instance()->register( 61 'anchor', 62 array( 63 'register_attribute' => 'wp_register_anchor_support', 64 'apply' => 'wp_apply_anchor_support', 65 ) 66 );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Thu Jan 15 08:20:04 2026 | Cross-referenced by PHPXref |