WP_Duotone::get_slug_from_attributeprivate 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)

Метод класса: WP_Duotone{}

Хуков нет.

Возвращает

Строку. The slug of the duotone preset or an empty string if no slug is found (including when an array was passed).

Использование

$result = WP_Duotone::get_slug_from_attribute( $duotone_attr );
$duotone_attr(строка|string[]) (обязательный)
The duotone attribute from a block.

Список изменений

С версии 6.3.0 Введена.

Код WP_Duotone::get_slug_from_attribute() WP 7.1

private static function get_slug_from_attribute( $duotone_attr ) {
	if ( ! is_string( $duotone_attr ) ) {
		return '';
	}

	// 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] : '';
}