wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_register_colors_support › WordPress Function

Seit5.6.0
Veraltetn/v
wp_register_colors_support ( $block_type )
Zugriff:
  • private
Parameter:
  • (WP_Block_Type) $block_type Block Type.
    Erforderlich: Ja
Definiert in:
Codex:
Changelog:
  • 6.1.0

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



Quellcode

function wp_register_colors_support( $block_type ) {
	$color_support = false;
	if ( $block_type instanceof WP_Block_Type ) {
		$color_support = isset( $block_type->supports['color'] ) ? $block_type->supports['color'] : false;
	}
	$has_text_colors_support       = true === $color_support ||
		( isset( $color_support['text'] ) && $color_support['text'] ) ||
		( is_array( $color_support ) && ! isset( $color_support['text'] ) );
	$has_background_colors_support = true === $color_support ||
		( isset( $color_support['background'] ) && $color_support['background'] ) ||
		( is_array( $color_support ) && ! isset( $color_support['background'] ) );
	$has_gradients_support         = isset( $color_support['gradients'] ) ? $color_support['gradients'] : false;
	$has_link_colors_support       = isset( $color_support['link'] ) ? $color_support['link'] : false;
	$has_button_colors_support     = isset( $color_support['button'] ) ? $color_support['button'] : false;
	$has_heading_colors_support    = isset( $color_support['heading'] ) ? $color_support['heading'] : false;
	$has_color_support             = $has_text_colors_support ||
		$has_background_colors_support ||
		$has_gradients_support ||
		$has_link_colors_support ||
		$has_button_colors_support ||
		$has_heading_colors_support;

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

	if ( $has_color_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',
		);
	}
}