Style value parser that constructs a CSS definition array comprising a single CSS property and value.
Description
If the provided value is an array containing a url
property, the function will return a CSS definition array with a single property and value, with url
escaped and injected into a CSS url()
function, e.g., array( ‘background-image’ => "url( ‘…’ )" ).
Parameters
$style_value
arrayrequired- A single raw style value from $block_styles array.
$style_definition
arrayrequired- A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
Source
*
* @since 6.4.0
*
* @param array $style_value A single raw style value from $block_styles array.
* @param array $style_definition A single style definition from BLOCK_STYLE_DEFINITIONS_METADATA.
* @return string[] An associative array of CSS definitions, e.g., array( "$property" => "$value", "$property" => "$value" ).
*/
protected static function get_url_or_value_css_declaration( $style_value, $style_definition ) {
if ( empty( $style_value ) ) {
return array();
}
$css_declarations = array();
if ( isset( $style_definition['property_keys']['default'] ) ) {
$value = null;
if ( ! empty( $style_value['url'] ) ) {
$value = "url('" . $style_value['url'] . "')";
} elseif ( is_string( $style_value ) ) {
$value = $style_value;
}
Changelog
Version | Description |
---|---|
6.4.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.