WP_Block_Supports::apply_block_supports() WordPress Method

The apply_block_supports() method is used to apply block support data to a given block type. This is typically done when the block type is first registered. The method accepts two arguments: the block type to apply the block support data to, and an array of block support data.

WP_Block_Supports::apply_block_supports() #

Generates an array of HTML attributes, such as classes, by applying to the given block all of the features that the block supports.


Return

(string[]) Array of HTML attributes.


Top ↑

Source

File: wp-includes/class-wp-block-supports.php

	public function apply_block_supports() {
		$block_attributes = self::$block_to_render['attrs'];
		$block_type       = WP_Block_Type_Registry::get_instance()->get_registered(
			self::$block_to_render['blockName']
		);

		// If no render_callback, assume styles have been previously handled.
		if ( ! $block_type || empty( $block_type ) ) {
			return array();
		}

		$output = array();
		foreach ( $this->block_supports as $block_support_config ) {
			if ( ! isset( $block_support_config['apply'] ) ) {
				continue;
			}

			$new_attributes = call_user_func(
				$block_support_config['apply'],
				$block_type,
				$block_attributes
			);

			if ( ! empty( $new_attributes ) ) {
				foreach ( $new_attributes as $attribute_name => $attribute_value ) {
					if ( empty( $output[ $attribute_name ] ) ) {
						$output[ $attribute_name ] = $attribute_value;
					} else {
						$output[ $attribute_name ] .= " $attribute_value";
					}
				}
			}
		}

		return $output;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.