[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Custom classname block support flag.
   4   *
   5   * @package WordPress
   6   */
   7  
   8  /**
   9   * Registers the custom classname 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_custom_classname_support( $block_type ) {
  16      $has_custom_classname_support = true;
  17      if ( property_exists( $block_type, 'supports' ) ) {
  18          $has_custom_classname_support = _wp_array_get( $block_type->supports, array( 'customClassName' ), true );
  19      }
  20      if ( $has_custom_classname_support ) {
  21          if ( ! $block_type->attributes ) {
  22              $block_type->attributes = array();
  23          }
  24  
  25          if ( ! array_key_exists( 'className', $block_type->attributes ) ) {
  26              $block_type->attributes['className'] = array(
  27                  'type' => 'string',
  28              );
  29          }
  30      }
  31  }
  32  
  33  /**
  34   * Add the custom classnames to the output.
  35   *
  36   * @access private
  37   *
  38   * @param  WP_Block_Type $block_type       Block Type.
  39   * @param  array         $block_attributes Block attributes.
  40   *
  41   * @return array Block CSS classes and inline styles.
  42   */
  43  function wp_apply_custom_classname_support( $block_type, $block_attributes ) {
  44      $has_custom_classname_support = true;
  45      $attributes                   = array();
  46      if ( property_exists( $block_type, 'supports' ) ) {
  47          $has_custom_classname_support = _wp_array_get( $block_type->supports, array( 'customClassName' ), true );
  48      }
  49      if ( $has_custom_classname_support ) {
  50          $has_custom_classnames = array_key_exists( 'className', $block_attributes );
  51  
  52          if ( $has_custom_classnames ) {
  53              $attributes['class'] = $block_attributes['className'];
  54          }
  55      }
  56  
  57      return $attributes;
  58  }
  59  
  60  // Register the block support.
  61  WP_Block_Supports::get_instance()->register(
  62      'custom-classname',
  63      array(
  64          'register_attribute' => 'wp_register_custom_classname_support',
  65          'apply'              => 'wp_apply_custom_classname_support',
  66      )
  67  );


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