wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_get_block_style_variation_name_from_registered_style › WordPress Function

Since7.0.0
Deprecatedn/a
wp_get_block_style_variation_name_from_registered_style ( $class_name, $registered_styles = array() )
Parameters: (2)
  • (string) $class_name CSS class string for a block.
    Required: Yes
  • (array<string,array<string,mixed>>) $registered_styles Currently registered block styles.
    Required: No
    Default: array()
Returns:
  • (string|null) The name of the first registered variation, or null if none found.
Defined at:
Codex:

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



Source

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;
}