A WordPress-centric search engine for devs and theme authors



wp_register_colors_support ›

Sincen/a
Deprecatedn/a
wp_register_colors_support ( $block_type )
Access:
  • private
Parameters:
  • (WP_Block_Type) $block_type Block Type.
    Required: Yes
Defined at:
Codex:

Registers the style and colors block attributes for block types that support it.



Source

function wp_register_colors_support( $block_type ) {
	$color_support = false;
	if ( property_exists( $block_type, 'supports' ) ) {
		$color_support = wp_array_get( $block_type->supports, array( '__experimentalColor' ), false );
	}
	$has_text_colors_support       = true === $color_support || ( is_array( $color_support ) && wp_array_get( $color_support, array( 'text' ), true ) );
	$has_background_colors_support = true === $color_support || ( is_array( $color_support ) && wp_array_get( $color_support, array( 'background' ), true ) );
	$has_gradients_support         = wp_array_get( $color_support, array( 'gradients' ), false );

	if ( ! $block_type->attributes ) {
		$block_type->attributes = array();
	}

	if ( $has_text_colors_support && ! array_key_exists( 'style', $block_type->attributes ) ) {
		$block_type->attributes['style'] = array(
			'type' => 'object',
		);
	}

	if ( $has_background_colors_support && ! array_key_exists( 'backgroundColor', $block_type->attributes ) ) {
		$block_type->attributes['backgroundColor'] = array(
			'type' => 'string',
		);
	}

	if ( $has_text_colors_support && ! array_key_exists( 'textColor', $block_type->attributes ) ) {
		$block_type->attributes['textColor'] = array(
			'type' => 'string',
		);
	}

	if ( $has_gradients_support && ! array_key_exists( 'gradient', $block_type->attributes ) ) {
		$block_type->attributes['gradient'] = array(
			'type' => 'string',
		);
	}
}