wpseek.com
Bazujące na WordPress narzędzie wyszukiwania dla deweloperów i twórców motywów.



wp_render_block_style_variation_class_name › WordPress Function

Od6.6.0
Przestarzałyn/a
wp_render_block_style_variation_class_name ( $block_content, $block )
Dostęp:
  • private
Parametry: (2)
  • (string) $block_content Rendered block content.
    Wymagane: Tak
  • (array) $block Block object.
    Wymagane: Tak
Zobacz:
Powrót:
  • (string) Filtered block content.
Zdefiniowane na:
Codex:

Ensure the variation block support class name generated and added to block attributes in the `render_block_data` filter gets applied to the block's markup.



Źródło

function wp_render_block_style_variation_class_name( $block_content, $block ) {
	if ( ! $block_content || empty( $block['attrs']['className'] ) ) {
		return $block_content;
	}

	/*
	 * Matches a class prefixed by `is-style`, followed by the
	 * variation slug, then `--`, and finally a hash.
	 *
	 * See `wp_create_block_style_variation_instance_name` for class generation.
	 */
	preg_match( '/\bis-style-(\S+?--\w+)\b/', $block['attrs']['className'], $matches );

	if ( empty( $matches ) ) {
		return $block_content;
	}

	$tags = new WP_HTML_Tag_Processor( $block_content );

	if ( $tags->next_tag() ) {
		/*
		 * Ensure the variation instance class name set in the
		 * `render_block_data` filter is applied in markup.
		 * See `wp_render_block_style_variation_support_styles`.
		 */
		$tags->add_class( $matches[0] );
	}

	return $tags->get_updated_html();
}