WP_Style_Engine::get_classnames()protected staticWP 6.1.0

Returns classnames, and generates classname(s) from a CSS preset property pattern, e.g., 'var:preset|<PRESET_TYPE>|<PRESET_SLUG>'.

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

Хуков нет.

Возвращает

Массив|Строку[]. An array of CSS classnames, or empty array.

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

$result = WP_Style_Engine::get_classnames( $style_value, $style_definition );
$style_value(массив) (обязательный)
A single raw style value or css preset property from the $block_styles array.
$style_definition(массив) (обязательный)
A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.

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

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

Код WP_Style_Engine::get_classnames() WP 6.1.1

protected static function get_classnames( $style_value, $style_definition ) {
	if ( empty( $style_value ) ) {
		return array();
	}

	$classnames = array();
	if ( ! empty( $style_definition['classnames'] ) ) {
		foreach ( $style_definition['classnames'] as $classname => $property_key ) {
			if ( true === $property_key ) {
				$classnames[] = $classname;
			}

			$slug = static::get_slug_from_preset_value( $style_value, $property_key );

			if ( $slug ) {
				/*
				 * Right now we expect a classname pattern to be stored in BLOCK_STYLE_DEFINITIONS_METADATA.
				 * One day, if there are no stored schemata, we could allow custom patterns or
				 * generate classnames based on other properties
				 * such as a path or a value or a prefix passed in options.
				 */
				$classnames[] = strtr( $classname, array( '$slug' => $slug ) );
			}
		}
	}

	return $classnames;
}