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



wp_get_block_style_variation_name_from_registered_style › WordPress Function

Seit7.0.0
Veraltetn/v
wp_get_block_style_variation_name_from_registered_style ( $class_name, $registered_styles = array() )
Parameter: (2)
  • (string) $class_name CSS class string for a block.
    Erforderlich: Ja
  • (array<string,array<string,mixed>>) $registered_styles Currently registered block styles.
    Erforderlich: Nein
    Standard: array()
Gibt zurück:
  • (string|null) The name of the first registered variation, or null if none found.
Definiert in:
Codex:

Gets the first style variation name from a className string that matches a registered style.



Quellcode

function wp_get_block_style_variation_name_from_registered_style( string $class_name, array $registered_styles = array() ): ?string {
	if ( ! $class_name ) {
		return null;
	}

	$registered_names = array_filter( array_column( $registered_styles, 'name' ) );

	$prefix = 'is-style-';
	$length = strlen( $prefix );

	foreach ( explode( ' ', $class_name ) as $class ) {
		if ( str_starts_with( $class, $prefix ) ) {
			$variation = substr( $class, $length );
			if ( 'default' !== $variation && in_array( $variation, $registered_names, true ) ) {
				return $variation;
			}
		}
	}

	return null;
}