[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   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   * @access private
  47   *
  48   * @param  WP_Block_Type $block_type       Block type.
  49   * @param  array         $block_attributes Block attributes.
  50   * @return array Shadow CSS classes and inline styles.
  51   */
  52  function wp_apply_shadow_support( $block_type, $block_attributes ) {
  53      $has_shadow_support = block_has_support( $block_type, 'shadow', false );
  54  
  55      if ( ! $has_shadow_support ) {
  56          return array();
  57      }
  58  
  59      $shadow_block_styles = array();
  60  
  61      $custom_shadow                 = $block_attributes['style']['shadow'] ?? null;
  62      $shadow_block_styles['shadow'] = $custom_shadow;
  63  
  64      $attributes = array();
  65      $styles     = wp_style_engine_get_styles( $shadow_block_styles );
  66  
  67      if ( ! empty( $styles['css'] ) ) {
  68          $attributes['style'] = $styles['css'];
  69      }
  70  
  71      return $attributes;
  72  }
  73  
  74  // Register the block support.
  75  WP_Block_Supports::get_instance()->register(
  76      'shadow',
  77      array(
  78          'register_attribute' => 'wp_register_shadow_support',
  79          'apply'              => 'wp_apply_shadow_support',
  80      )
  81  );


Generated : Sat Apr 27 08:20:02 2024 Cross-referenced by PHPXref