| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Shadow block support flag. 4 * 5 * @package WordPress 6 * @since 6.3.0 7 */ 8 9 /** 10 * Registers the style and shadow block attributes for block types that support it. 11 * 12 * @since 6.3.0 13 * @access private 14 * 15 * @param WP_Block_Type $block_type Block Type. 16 */ 17 function wp_register_shadow_support( $block_type ) { 18 $has_shadow_support = block_has_support( $block_type, 'shadow', false ); 19 20 if ( ! $has_shadow_support ) { 21 return; 22 } 23 24 if ( ! $block_type->attributes ) { 25 $block_type->attributes = array(); 26 } 27 28 if ( ! array_key_exists( 'style', $block_type->attributes ) ) { 29 $block_type->attributes['style'] = array( 30 'type' => 'object', 31 ); 32 } 33 34 if ( ! array_key_exists( 'shadow', $block_type->attributes ) ) { 35 $block_type->attributes['shadow'] = array( 36 'type' => 'string', 37 ); 38 } 39 } 40 41 /** 42 * Add CSS classes and inline styles for shadow features to the incoming attributes array. 43 * This will be applied to the block markup in the front-end. 44 * 45 * @since 6.3.0 46 * @since 6.6.0 Return early if __experimentalSkipSerialization is true. 47 * @access private 48 * 49 * @param WP_Block_Type $block_type Block type. 50 * @param array $block_attributes Block attributes. 51 * @return array Shadow CSS classes and inline styles. 52 */ 53 function wp_apply_shadow_support( $block_type, $block_attributes ) { 54 $has_shadow_support = block_has_support( $block_type, 'shadow', false ); 55 56 if ( 57 ! $has_shadow_support || 58 wp_should_skip_block_supports_serialization( $block_type, 'shadow' ) 59 ) { 60 return array(); 61 } 62 63 return wp_get_shadow_classes_and_styles( $block_attributes ); 64 } 65 66 /** 67 * Returns shadow classes and inline styles for block attributes, like the JS 68 * `getShadowClassesAndStyles()`. Does not check block support or skipped 69 * serialization. 70 * 71 * @since 7.3.0 72 * 73 * @param array<string, mixed> $block_attributes Block attributes. 74 * @return array<string, string> Array with `class` and `style` keys, each present only when non-empty. 75 * 76 * @phpstan-param array{ style?: array<string, mixed>, ...<string, mixed> } $block_attributes 77 * @phpstan-return array{ class?: non-empty-string, style?: non-empty-string } 78 */ 79 function wp_get_shadow_classes_and_styles( $block_attributes ) { 80 if ( ! is_array( $block_attributes ) ) { 81 return array(); 82 } 83 84 $shadow = $block_attributes['style']['shadow'] ?? null; 85 86 $attributes = array(); 87 $styles = wp_style_engine_get_styles( array( 'shadow' => $shadow ) ); 88 89 if ( ! empty( $styles['classnames'] ) ) { 90 $attributes['class'] = $styles['classnames']; 91 } 92 93 if ( ! empty( $styles['css'] ) ) { 94 $attributes['style'] = $styles['css']; 95 } 96 97 return $attributes; 98 } 99 100 // Register the block support. 101 WP_Block_Supports::get_instance()->register( 102 'shadow', 103 array( 104 'register_attribute' => 'wp_register_shadow_support', 105 'apply' => 'wp_apply_shadow_support', 106 ) 107 );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Dec 5 08:20:02 2026 | Cross-referenced by PHPXref |