Title: WP_Block_Supports
Published: December 9, 2020
Last modified: May 20, 2026

---

# class WP_Block_Supports {}

## In this article

 * [Methods](https://developer.wordpress.org/reference/classes/wp_block_supports/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/wp_block_supports/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_block_supports/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_block_supports/?output_format=md#wp--skip-link--target)

This class’s access is marked private. This means it is not intended for use by 
plugin or theme developers, only by core. It is listed here for completeness.

Class encapsulating and implementing Block Supports.

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/wp_block_supports/?output_format=md#methods)󠁿

| Name | Description | 
| [WP_Block_Supports::apply_block_supports](https://developer.wordpress.org/reference/classes/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. | 
| [WP_Block_Supports::get_instance](https://developer.wordpress.org/reference/classes/wp_block_supports/get_instance/) | Utility method to retrieve the main instance of the class. | 
| [WP_Block_Supports::init](https://developer.wordpress.org/reference/classes/wp_block_supports/init/) | Initializes the block supports. It registers the block supports block attributes. | 
| [WP_Block_Supports::register](https://developer.wordpress.org/reference/classes/wp_block_supports/register/) | Registers a block support. | 
| [WP_Block_Supports::register_attributes](https://developer.wordpress.org/reference/classes/wp_block_supports/register_attributes/) | Registers the block attributes required by the different block supports. |

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_block_supports/?output_format=md#source)󠁿

    ```php
    #[AllowDynamicProperties]
    class WP_Block_Supports {

    	/**
    	 * Config.
    	 *
    	 * @since 5.6.0
    	 * @var array
    	 */
    	private $block_supports = array();

    	/**
    	 * Tracks the current block to be rendered.
    	 *
    	 * @since 5.6.0
    	 * @var array
    	 */
    	public static $block_to_render = null;

    	/**
    	 * Container for the main instance of the class.
    	 *
    	 * @since 5.6.0
    	 * @var WP_Block_Supports|null
    	 */
    	private static $instance = null;

    	/**
    	 * Utility method to retrieve the main instance of the class.
    	 *
    	 * The instance will be created if it does not exist yet.
    	 *
    	 * @since 5.6.0
    	 *
    	 * @return WP_Block_Supports The main instance.
    	 */
    	public static function get_instance() {
    		if ( null === self::$instance ) {
    			self::$instance = new self();
    		}

    		return self::$instance;
    	}

    	/**
    	 * Initializes the block supports. It registers the block supports block attributes.
    	 *
    	 * @since 5.6.0
    	 */
    	public static function init() {
    		$instance = self::get_instance();
    		$instance->register_attributes();
    	}

    	/**
    	 * Registers a block support.
    	 *
    	 * @since 5.6.0
    	 *
    	 * @link https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/
    	 *
    	 * @param string $block_support_name   Block support name.
    	 * @param array  $block_support_config Array containing the properties of the block support.
    	 */
    	public function register( $block_support_name, $block_support_config ) {
    		$this->block_supports[ $block_support_name ] = array_merge(
    			$block_support_config,
    			array( 'name' => $block_support_name )
    		);
    	}

    	/**
    	 * Generates an array of HTML attributes, such as classes, by applying to
    	 * the given block all of the features that the block supports.
    	 *
    	 * @since 5.6.0
    	 *
    	 * @return string[] Array of HTML attribute values keyed by their name.
    	 */
    	public function apply_block_supports() {
    		$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();
    		}

    		$block_attributes = array_key_exists( 'attrs', self::$block_to_render ) && is_array( self::$block_to_render['attrs'] )
    			? $block_type->prepare_attributes_for_render( self::$block_to_render['attrs'] )
    			: 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;
    	}

    	/**
    	 * Registers the block attributes required by the different block supports.
    	 *
    	 * @since 5.6.0
    	 */
    	private function register_attributes() {
    		$block_registry         = WP_Block_Type_Registry::get_instance();
    		$registered_block_types = $block_registry->get_all_registered();
    		foreach ( $registered_block_types as $block_type ) {
    			if ( ! ( $block_type instanceof WP_Block_Type ) ) {
    				continue;
    			}
    			if ( ! $block_type->attributes ) {
    				$block_type->attributes = array();
    			}

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

    				call_user_func(
    					$block_support_config['register_attribute'],
    					$block_type
    				);
    			}
    		}
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-supports.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-block-supports.php#L17)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-block-supports.php#L17-L164)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_block_supports/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_block_supports%2F)
before being able to contribute a note or feedback.