wp/wp-includes/class-wp-block-supports.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    56 
    56 
    57 		return self::$instance;
    57 		return self::$instance;
    58 	}
    58 	}
    59 
    59 
    60 	/**
    60 	/**
    61 	 * Initializes the block supports. It registes the block supports block attributes.
    61 	 * Initializes the block supports. It registers the block supports block attributes.
    62 	 *
    62 	 *
    63 	 * @since 5.6.0
    63 	 * @since 5.6.0
    64 	 */
    64 	 */
    65 	public static function init() {
    65 	public static function init() {
    66 		$instance = self::get_instance();
    66 		$instance = self::get_instance();
    70 	/**
    70 	/**
    71 	 * Registers a block support.
    71 	 * Registers a block support.
    72 	 *
    72 	 *
    73 	 * @since 5.6.0
    73 	 * @since 5.6.0
    74 	 *
    74 	 *
    75 	 * @param string $block_support_name Block support name.
    75 	 * @param string $block_support_name   Block support name.
    76 	 * @param array  $block_support_config Array containing the properties of the block support.
    76 	 * @param array  $block_support_config Array containing the properties of the block support.
    77 	 */
    77 	 */
    78 	public function register( $block_support_name, $block_support_config ) {
    78 	public function register( $block_support_name, $block_support_config ) {
    79 		$this->block_supports[ $block_support_name ] = array_merge(
    79 		$this->block_supports[ $block_support_name ] = array_merge(
    80 			$block_support_config,
    80 			$block_support_config,
    86 	 * Generates an array of HTML attributes, such as classes, by applying to
    86 	 * Generates an array of HTML attributes, such as classes, by applying to
    87 	 * the given block all of the features that the block supports.
    87 	 * the given block all of the features that the block supports.
    88 	 *
    88 	 *
    89 	 * @since 5.6.0
    89 	 * @since 5.6.0
    90 	 *
    90 	 *
    91 	 * @return array Array of HTML attributes.
    91 	 * @return string[] Array of HTML attributes.
    92 	 */
    92 	 */
    93 	public function apply_block_supports() {
    93 	public function apply_block_supports() {
    94 		$block_attributes = self::$block_to_render['attrs'];
    94 		$block_attributes = self::$block_to_render['attrs'];
    95 		$block_type       = WP_Block_Type_Registry::get_instance()->get_registered(
    95 		$block_type       = WP_Block_Type_Registry::get_instance()->get_registered(
    96 			self::$block_to_render['blockName']
    96 			self::$block_to_render['blockName']
   161  * Generates a string of attributes by applying to the current block being
   161  * Generates a string of attributes by applying to the current block being
   162  * rendered all of the features that the block supports.
   162  * rendered all of the features that the block supports.
   163  *
   163  *
   164  * @since 5.6.0
   164  * @since 5.6.0
   165  *
   165  *
   166  * @param array $extra_attributes Optional. Extra attributes to render on the block wrapper.
   166  * @param string[] $extra_attributes Optional. Array of extra attributes to render on the block wrapper.
   167  *
   167  * @return string String of HTML attributes.
   168  * @return string String of HTML classes.
       
   169  */
   168  */
   170 function get_block_wrapper_attributes( $extra_attributes = array() ) {
   169 function get_block_wrapper_attributes( $extra_attributes = array() ) {
   171 	$new_attributes = WP_Block_Supports::get_instance()->apply_block_supports();
   170 	$new_attributes = WP_Block_Supports::get_instance()->apply_block_supports();
   172 
   171 
   173 	if ( empty( $new_attributes ) && empty( $extra_attributes ) ) {
   172 	if ( empty( $new_attributes ) && empty( $extra_attributes ) ) {