[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Padding block support flag.
   4   *
   5   * @package WordPress
   6   * @since 5.8.0
   7   */
   8  
   9  /**
  10   * Registers the style block attribute for block types that support it.
  11   *
  12   * @since 5.8.0
  13   * @access private
  14   *
  15   * @param WP_Block_Type $block_type Block Type.
  16   */
  17  function wp_register_padding_support( $block_type ) {
  18      $has_padding_support = block_has_support( $block_type, array( 'spacing', 'padding' ), false );
  19  
  20      // Setup attributes and styles within that if needed.
  21      if ( ! $block_type->attributes ) {
  22          $block_type->attributes = array();
  23      }
  24  
  25      if ( $has_padding_support && ! array_key_exists( 'style', $block_type->attributes ) ) {
  26          $block_type->attributes['style'] = array(
  27              'type' => 'object',
  28          );
  29      }
  30  }
  31  
  32  /**
  33   * Add CSS classes for block padding to the incoming attributes array.
  34   * This will be applied to the block markup in the front-end.
  35   *
  36   * @since 5.8.0
  37   * @access private
  38   *
  39   * @param WP_Block_Type $block_type       Block Type.
  40   * @param array         $block_attributes Block attributes.
  41   *
  42   * @return array Block padding CSS classes and inline styles.
  43   */
  44  function wp_apply_padding_support( $block_type, $block_attributes ) {
  45      $has_padding_support = block_has_support( $block_type, array( 'spacing', 'padding' ), false );
  46      $styles              = array();
  47      if ( $has_padding_support ) {
  48          $padding_value = _wp_array_get( $block_attributes, array( 'style', 'spacing', 'padding' ), null );
  49          if ( null !== $padding_value ) {
  50              foreach ( $padding_value as $key => $value ) {
  51                  $styles[] = sprintf( 'padding-%s: %s;', $key, $value );
  52              }
  53          }
  54      }
  55  
  56      return empty( $styles ) ? array() : array( 'style' => implode( ' ', $styles ) );
  57  }
  58  
  59  // Register the block support.
  60  WP_Block_Supports::get_instance()->register(
  61      'padding',
  62      array(
  63          'register_attribute' => 'wp_register_padding_support',
  64          'apply'              => 'wp_apply_padding_support',
  65      )
  66  );


Generated: Fri May 21 01:00:05 2021 Cross-referenced by PHPXref 0.7.1