[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Align block support flag.
   4   *
   5   * @package WordPress
   6   */
   7  
   8  /**
   9   * Registers the align block attribute for block types that support it.
  10   *
  11   * @access private
  12   *
  13   * @param WP_Block_Type $block_type Block Type.
  14   */
  15  function wp_register_alignment_support( $block_type ) {
  16      $has_align_support = false;
  17      if ( property_exists( $block_type, 'supports' ) ) {
  18          $has_align_support = _wp_array_get( $block_type->supports, array( 'align' ), false );
  19      }
  20      if ( $has_align_support ) {
  21          if ( ! $block_type->attributes ) {
  22              $block_type->attributes = array();
  23          }
  24  
  25          if ( ! array_key_exists( 'align', $block_type->attributes ) ) {
  26              $block_type->attributes['align'] = array(
  27                  'type' => 'string',
  28                  'enum' => array( 'left', 'center', 'right', 'wide', 'full', '' ),
  29              );
  30          }
  31      }
  32  }
  33  
  34  /**
  35   * Add CSS classes for block alignment to the incoming attributes array.
  36   * This will be applied to the block markup in the front-end.
  37   *
  38   * @access private
  39   *
  40   * @param WP_Block_Type $block_type       Block Type.
  41   * @param array         $block_attributes Block attributes.
  42   *
  43   * @return array Block alignment CSS classes and inline styles.
  44   */
  45  function wp_apply_alignment_support( $block_type, $block_attributes ) {
  46      $attributes        = array();
  47      $has_align_support = false;
  48      if ( property_exists( $block_type, 'supports' ) ) {
  49          $has_align_support = _wp_array_get( $block_type->supports, array( 'align' ), false );
  50      }
  51      if ( $has_align_support ) {
  52          $has_block_alignment = array_key_exists( 'align', $block_attributes );
  53  
  54          if ( $has_block_alignment ) {
  55              $attributes['class'] = sprintf( 'align%s', $block_attributes['align'] );
  56          }
  57      }
  58  
  59      return $attributes;
  60  }
  61  
  62  // Register the block support.
  63  WP_Block_Supports::get_instance()->register(
  64      'align',
  65      array(
  66          'register_attribute' => 'wp_register_alignment_support',
  67          'apply'              => 'wp_apply_alignment_support',
  68      )
  69  );


Generated: Sat Apr 10 01:00:03 2021 Cross-referenced by PHPXref 0.7.1