WP_Duotone::get_slug_from_attribute()private staticWP 6.3.0

Takes the inline CSS duotone variable from a block and return the slug.

Handles styles slugs like: var:preset|duotone|blue-orange var(--wp--preset--duotone--blue-orange)

Method of the class: WP_Duotone{}

No Hooks.

Return

String. The slug of the duotone preset or an empty string if no slug is found.

Usage

$result = WP_Duotone::get_slug_from_attribute( $duotone_attr );
$duotone_attr(string) (required)
The duotone attribute from a block.

Changelog

Since 6.3.0 Introduced.

WP_Duotone::get_slug_from_attribute() code WP 6.5.3

private static function get_slug_from_attribute( $duotone_attr ) {
	// Uses Branch Reset Groups `(?|…)` to return one capture group.
	preg_match( '/(?|var:preset\|duotone\|(\S+)|var\(--wp--preset--duotone--(\S+)\))/', $duotone_attr, $matches );

	return ! empty( $matches[1] ) ? $matches[1] : '';
}