mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backport defaultDuotone
changes
#2526
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,41 +74,48 @@ class WP_Theme_JSON { | |
* | ||
* This contains the necessary metadata to process them: | ||
* | ||
* - path => where to find the preset within the settings section | ||
* - override => whether a theme preset with the same slug as a default preset | ||
* can override it | ||
* - use_default_names => whether to use the default names | ||
* - value_key => the key that represents the value | ||
* - value_func => optionally, instead of value_key, a function to generate | ||
* the value that takes a preset as an argument | ||
* (either value_key or value_func should be present) | ||
* - css_vars => template string to use in generating the CSS Custom Property. | ||
* Example output: "--wp--preset--duotone--blue: <value>" will generate | ||
* as many CSS Custom Properties as presets defined | ||
* substituting the $slug for the slug's value for each preset value. | ||
* - classes => array containing a structure with the classes to | ||
* generate for the presets, where for each array item | ||
* the key is the class name and the value the property name. | ||
* The "$slug" substring will be replaced by the slug of each preset. | ||
* For example: | ||
* 'classes' => array( | ||
* '.has-$slug-color' => 'color', | ||
* '.has-$slug-background-color' => 'background-color', | ||
* '.has-$slug-border-color' => 'border-color', | ||
* ) | ||
* - properties => array of CSS properties to be used by kses to | ||
* validate the content of each preset | ||
* by means of the remove_insecure_properties method. | ||
* - path => Where to find the preset within the settings section. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All changes in this file are also being backported at #2534 If this lands later, this file can be ignored. |
||
* - prevent_override => Disables override of default presets by theme presets. | ||
* The relationship between whether to override the defaults | ||
* and whether the defaults are enabled is inverse: | ||
* - If defaults are enabled => theme presets should not be overriden | ||
* - If defaults are disabled => theme presets should be overriden | ||
* For example, a theme sets defaultPalette to false, | ||
* making the default palette hidden from the user. | ||
* In that case, we want all the theme presets to be present, | ||
* so they should override the defaults by setting this false. | ||
* - value_key => the key that represents the value | ||
* - value_func => optionally, instead of value_key, a function to generate | ||
* the value that takes a preset as an argument | ||
* (either value_key or value_func should be present) | ||
* - css_vars => template string to use in generating the CSS Custom Property. | ||
* Example output: "--wp--preset--duotone--blue: <value>" will generate as many CSS Custom Properties as presets defined | ||
* substituting the $slug for the slug's value for each preset value. | ||
* - classes => array containing a structure with the classes to | ||
* generate for the presets, where for each array item | ||
* the key is the class name and the value the property name. | ||
* The "$slug" substring will be replaced by the slug of each preset. | ||
* For example: | ||
* 'classes' => array( | ||
* '.has-$slug-color' => 'color', | ||
* '.has-$slug-background-color' => 'background-color', | ||
* '.has-$slug-border-color' => 'border-color', | ||
* ) | ||
* - properties => array of CSS properties to be used by kses to | ||
* validate the content of each preset | ||
* by means of the remove_insecure_properties method. | ||
* | ||
* @since 5.8.0 | ||
* @since 5.9.0 Added the `color.duotone` and `typography.fontFamilies` presets, | ||
* `use_default_names` preset key, and simplified the metadata structure. | ||
* @since 6.0.0 Replaced `override` with `prevent_override` and updated the | ||
* `prevent_overried` value for `color.duotone` to use `color.defaultDuotone`. | ||
* @var array | ||
*/ | ||
const PRESETS_METADATA = array( | ||
array( | ||
'path' => array( 'color', 'palette' ), | ||
'override' => array( 'color', 'defaultPalette' ), | ||
'prevent_override' => array( 'color', 'defaultPalette' ), | ||
'use_default_names' => false, | ||
'value_key' => 'color', | ||
'css_vars' => '--wp--preset--color--$slug', | ||
|
@@ -121,7 +128,7 @@ class WP_Theme_JSON { | |
), | ||
array( | ||
'path' => array( 'color', 'gradients' ), | ||
'override' => array( 'color', 'defaultGradients' ), | ||
'prevent_override' => array( 'color', 'defaultGradients' ), | ||
'use_default_names' => false, | ||
'value_key' => 'gradient', | ||
'css_vars' => '--wp--preset--gradient--$slug', | ||
|
@@ -130,7 +137,7 @@ class WP_Theme_JSON { | |
), | ||
array( | ||
'path' => array( 'color', 'duotone' ), | ||
'override' => true, | ||
'prevent_override' => array( 'color', 'defaultDuotone' ), | ||
'use_default_names' => false, | ||
'value_func' => 'wp_get_duotone_filter_property', | ||
'css_vars' => '--wp--preset--duotone--$slug', | ||
|
@@ -139,7 +146,7 @@ class WP_Theme_JSON { | |
), | ||
array( | ||
'path' => array( 'typography', 'fontSizes' ), | ||
'override' => true, | ||
'prevent_override' => false, | ||
'use_default_names' => true, | ||
'value_key' => 'size', | ||
'css_vars' => '--wp--preset--font-size--$slug', | ||
|
@@ -148,7 +155,7 @@ class WP_Theme_JSON { | |
), | ||
array( | ||
'path' => array( 'typography', 'fontFamilies' ), | ||
'override' => true, | ||
'prevent_override' => false, | ||
'use_default_names' => false, | ||
'value_key' => 'fontFamily', | ||
'css_vars' => '--wp--preset--font-family--$slug', | ||
|
@@ -242,6 +249,7 @@ class WP_Theme_JSON { | |
* @since 5.9.0 Renamed from `ALLOWED_SETTINGS` to `VALID_SETTINGS`, | ||
* added new properties for `border`, `color`, `spacing`, | ||
* and `typography`, and renamed others according to the new schema. | ||
* @since 6.0.0 Added `color.defaultDuotone`. | ||
* @var array | ||
*/ | ||
const VALID_SETTINGS = array( | ||
|
@@ -257,6 +265,7 @@ class WP_Theme_JSON { | |
'custom' => null, | ||
'customDuotone' => null, | ||
'customGradient' => null, | ||
'defaultDuotone' => null, | ||
'defaultGradients' => null, | ||
'defaultPalette' => null, | ||
'duotone' => null, | ||
|
@@ -1550,7 +1559,7 @@ public function merge( $incoming ) { | |
|
||
// Replace the presets. | ||
foreach ( static::PRESETS_METADATA as $preset ) { | ||
$override_preset = static::should_override_preset( $this->theme_json, $node['path'], $preset['override'] ); | ||
$override_preset = ! static::get_metadata_boolean( $this->theme_json['settings'], $preset['prevent_override'], true ); | ||
|
||
foreach ( static::VALID_ORIGINS as $origin ) { | ||
$base_path = array_merge( $node['path'], $preset['path'] ); | ||
|
@@ -1624,13 +1633,16 @@ public function get_svg_filters( $origins ) { | |
* Returns whether a presets should be overridden or not. | ||
* | ||
* @since 5.9.0 | ||
* @deprecated 6.0.0 Use {@see 'get_metadata_boolean'} instead. | ||
* | ||
* @param array $theme_json The theme.json like structure to inspect. | ||
* @param array $path Path to inspect. | ||
* @param bool|array $override Data to compute whether to override the preset. | ||
* @return boolean | ||
*/ | ||
protected static function should_override_preset( $theme_json, $path, $override ) { | ||
_deprecated_function( __METHOD__, '6.0.0' ); | ||
|
||
if ( is_bool( $override ) ) { | ||
return $override; | ||
} | ||
|
@@ -1663,6 +1675,45 @@ protected static function should_override_preset( $theme_json, $path, $override | |
} | ||
} | ||
|
||
/** | ||
* For metadata values that can either be booleans or paths to booleans, gets the value. | ||
* | ||
* ```php | ||
* $data = array( | ||
* 'color' => array( | ||
* 'defaultPalette' => true | ||
* ) | ||
* ); | ||
* | ||
* static::get_metadata_boolean( $data, false ); | ||
* // => false | ||
* | ||
* static::get_metadata_boolean( $data, array( 'color', 'defaultPalette' ) ); | ||
* // => true | ||
* ``` | ||
* | ||
* @since 6.0.0 | ||
* | ||
* @param array $data The data to inspect. | ||
* @param bool|array $path Boolean or path to a boolean. | ||
* @param bool $default Default value if the referenced path is missing. | ||
* @return boolean | ||
*/ | ||
protected static function get_metadata_boolean( $data, $path, $default = false ) { | ||
if ( is_bool( $path ) ) { | ||
return $path; | ||
} | ||
|
||
if ( is_array( $path ) ) { | ||
$value = _wp_array_get( $data, $path ); | ||
if ( isset( $value ) ) { | ||
return $value; | ||
} | ||
} | ||
|
||
return $default; | ||
} | ||
|
||
/** | ||
* Returns the default slugs for all the presets in an associative array | ||
* whose keys are the preset paths and the leafs is the list of slugs. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These is being backported at #2534 If this one lands later, this file can be ignored.