Skip to content

Commit

Permalink
Update: Rename user preset origin to custom (#36748)
Browse files Browse the repository at this point in the history
* Update: Rename user preset origin to custom

* Fix PHP tests

* Fix JS tests

* Remove console.log

Co-authored-by: André <583546+oandregal@users.noreply.github.com>
  • Loading branch information
2 people authored and noisysocks committed Nov 28, 2021
1 parent d45ba69 commit 7d47338
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 44 deletions.
6 changes: 3 additions & 3 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class WP_Theme_JSON_Gutenberg {
const VALID_ORIGINS = array(
'default',
'theme',
'user',
'custom',
);

const VALID_TOP_LEVEL_KEYS = array(
Expand Down Expand Up @@ -282,7 +282,7 @@ class WP_Theme_JSON_Gutenberg {
* Constructor.
*
* @param array $theme_json A structure that follows the theme.json schema.
* @param string $origin What source of data this object represents. One of default, theme, or user. Default: theme.
* @param string $origin What source of data this object represents. One of default, theme, or custom. Default: theme.
*/
public function __construct( $theme_json = array(), $origin = 'theme' ) {
if ( ! in_array( $origin, self::VALID_ORIGINS, true ) ) {
Expand Down Expand Up @@ -1318,7 +1318,7 @@ private static function get_setting_nodes( $theme_json, $selectors = array() ) {
* 'variables': only the CSS Custom Properties for presets & custom ones.
* 'styles': only the styles section in theme.json.
* 'presets': only the classes for the presets.
* @param array $origins A list of origins to include. By default it includes 'default', 'theme', and 'user'.
* @param array $origins A list of origins to include. By default it includes 'default', 'theme', and 'custom'.
*
* @return string Stylesheet.
*/
Expand Down
14 changes: 7 additions & 7 deletions lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public static function get_user_data() {
$json_decoding_error = json_last_error();
if ( JSON_ERROR_NONE !== $json_decoding_error ) {
trigger_error( 'Error when decoding a theme.json schema for user data. ' . json_last_error_msg() );
return new WP_Theme_JSON_Gutenberg( $config, 'user' );
return new WP_Theme_JSON_Gutenberg( $config, 'custom' );
}

// Very important to verify if the flag isGlobalStylesUserThemeJSON is true.
Expand All @@ -294,14 +294,14 @@ public static function get_user_data() {
$config = $decoded_data;
}
}
self::$user = new WP_Theme_JSON_Gutenberg( $config, 'user' );
self::$user = new WP_Theme_JSON_Gutenberg( $config, 'custom' );

return self::$user;
}

/**
* There are three sources of data (origins) for a site:
* default, theme, and user. The user's has higher priority
* default, theme, and custom. The custom's has higher priority
* than the theme's, and the theme's higher than defaults's.
*
* Unlike the getters {@link get_core_data},
Expand All @@ -316,17 +316,17 @@ public static function get_user_data() {
* the user preference wins.
*
* @param string $origin To what level should we merge data.
* Valid values are 'theme' or 'user'.
* Default is 'user'.
* Valid values are 'theme' or 'custom'.
* Default is 'custom'.
*
* @return WP_Theme_JSON_Gutenberg
*/
public static function get_merged_data( $origin = 'user' ) {
public static function get_merged_data( $origin = 'custom' ) {
$result = new WP_Theme_JSON_Gutenberg();
$result->merge( self::get_core_data() );
$result->merge( self::get_theme_data() );

if ( 'user' === $origin ) {
if ( 'custom' === $origin ) {
$result->merge( self::get_user_data() );
}

Expand Down
6 changes: 3 additions & 3 deletions lib/compat/wordpress-5.9/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function gutenberg_get_global_settings( $path = array(), $context = array() ) {
$path = array_merge( array( 'blocks', $context['block_name'] ), $path );
}

$origin = 'user';
$origin = 'custom';
if ( isset( $context['origin'] ) && 'base' === $context['origin'] ) {
$origin = 'theme';
}
Expand Down Expand Up @@ -59,7 +59,7 @@ function gutenberg_get_global_styles( $path = array(), $context = array() ) {
$path = array_merge( array( 'blocks', $context['block_name'] ), $path );
}

$origin = 'user';
$origin = 'custom';
if ( isset( $context['origin'] ) && 'base' === $context['origin'] ) {
$origin = 'theme';
}
Expand Down Expand Up @@ -105,7 +105,7 @@ function gutenberg_get_global_stylesheet( $types = array() ) {
$types = array( 'variables', 'styles', 'presets' );
}

$origins = array( 'default', 'theme', 'user' );
$origins = array( 'default', 'theme', 'custom' );
if ( ! $supports_theme_json && ! $supports_link_color ) {
// In this case we only enqueue the core presets (CSS Custom Properties + the classes).
$origins = array( 'default' );
Expand Down
10 changes: 5 additions & 5 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ function_exists( 'gutenberg_is_edit_site_page' ) &&

if ( isset( $settings['__experimentalFeatures']['color']['palette'] ) ) {
$colors_by_origin = $settings['__experimentalFeatures']['color']['palette'];
$settings['colors'] = isset( $colors_by_origin['user'] ) ?
$colors_by_origin['user'] : (
$settings['colors'] = isset( $colors_by_origin['custom'] ) ?
$colors_by_origin['custom'] : (
isset( $colors_by_origin['theme'] ) ?
$colors_by_origin['theme'] :
$colors_by_origin['default']
Expand All @@ -120,8 +120,8 @@ function_exists( 'gutenberg_is_edit_site_page' ) &&

if ( isset( $settings['__experimentalFeatures']['color']['gradients'] ) ) {
$gradients_by_origin = $settings['__experimentalFeatures']['color']['gradients'];
$settings['gradients'] = isset( $gradients_by_origin['user'] ) ?
$gradients_by_origin['user'] : (
$settings['gradients'] = isset( $gradients_by_origin['custom'] ) ?
$gradients_by_origin['custom'] : (
isset( $gradients_by_origin['theme'] ) ?
$gradients_by_origin['theme'] :
$gradients_by_origin['default']
Expand All @@ -130,7 +130,7 @@ function_exists( 'gutenberg_is_edit_site_page' ) &&

if ( isset( $settings['__experimentalFeatures']['typography']['fontSizes'] ) ) {
$font_sizes_by_origin = $settings['__experimentalFeatures']['typography']['fontSizes'];
$settings['fontSizes'] = isset( $font_sizes_by_origin['user'] ) ?
$settings['fontSizes'] = isset( $font_sizes_by_origin['custom'] ) ?
$font_sizes_by_origin['user'] : (
isset( $font_sizes_by_origin['theme'] ) ?
$font_sizes_by_origin['theme'] :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const PanelColorGradientSettingsSingleSelect = ( props ) => {

const PanelColorGradientSettingsMultipleSelect = ( props ) => {
const colorGradientSettings = useCommonSingleMultipleSelects();
const customColors = useSetting( 'color.palette.user' );
const customColors = useSetting( 'color.palette.custom' );
const themeColors = useSetting( 'color.palette.theme' );
const defaultColors = useSetting( 'color.palette.default' );
const shouldDisplayDefaultColors = useSetting( 'color.defaultPalette' );
Expand Down Expand Up @@ -213,7 +213,7 @@ const PanelColorGradientSettingsMultipleSelect = ( props ) => {
return result;
}, [ defaultColors, themeColors, customColors ] );

const customGradients = useSetting( 'color.gradients.user' );
const customGradients = useSetting( 'color.gradients.custom' );
const themeGradients = useSetting( 'color.gradients.theme' );
const defaultGradients = useSetting( 'color.gradients.default' );
const shouldDisplayDefaultGradients = useSetting(
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/use-setting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default function useSetting( path ) {
if ( experimentalFeaturesResult !== undefined ) {
if ( PATHS_WITH_MERGE[ normalizedPath ] ) {
return (
experimentalFeaturesResult.user ??
experimentalFeaturesResult.custom ??
experimentalFeaturesResult.theme ??
experimentalFeaturesResult.default
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ export function parseStylesVariables( styles, mappedValues, customValues ) {

export function getMappedValues( features, palette ) {
const typography = features?.typography;
const colors = { ...palette?.theme, ...palette?.user };
const colors = { ...palette?.theme, ...palette?.custom };
const fontSizes = {
...typography?.fontSizes?.theme,
...typography?.fontSizes?.user,
...typography?.fontSizes?.custom,
};
const mappedValues = {
color: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function ColorPalettePanel( { name } ) {
'base'
);
const [ customColors, setCustomColors ] = useSetting(
'color.palette.user',
'color.palette.custom',
name
);

Expand Down
8 changes: 4 additions & 4 deletions packages/edit-site/src/components/global-styles/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function useSetting( path, blockName, source = 'all' ) {
setUserConfig( ( currentConfig ) => {
const newUserConfig = cloneDeep( currentConfig );
const pathToSet = PATHS_WITH_MERGE[ path ]
? fullPath + '.user'
? fullPath + '.custom'
: fullPath;
set( newUserConfig, pathToSet, newValue );

Expand All @@ -65,7 +65,7 @@ export function useSetting( path, blockName, source = 'all' ) {
const getSettingValue = ( configToUse ) => {
const result = get( configToUse, currentPath );
if ( PATHS_WITH_MERGE[ path ] ) {
return result?.user ?? result?.theme ?? result?.default;
return result?.custom ?? result?.theme ?? result?.default;
}
return result;
};
Expand Down Expand Up @@ -218,7 +218,7 @@ export function getSupportedGlobalStylesPanels( name ) {
}

export function useColorsPerOrigin( name ) {
const [ customColors ] = useSetting( 'color.palette.user', name );
const [ customColors ] = useSetting( 'color.palette.custom', name );
const [ themeColors ] = useSetting( 'color.palette.theme', name );
const [ defaultColors ] = useSetting( 'color.palette.default', name );
const [ shouldDisplayDefaultColors ] = useSetting( 'color.defaultPalette' );
Expand Down Expand Up @@ -261,7 +261,7 @@ export function useColorsPerOrigin( name ) {
}

export function useGradientsPerOrigin( name ) {
const [ customGradients ] = useSetting( 'color.gradients.user', name );
const [ customGradients ] = useSetting( 'color.gradients.custom', name );
const [ themeGradients ] = useSetting( 'color.gradients.theme', name );
const [ defaultGradients ] = useSetting( 'color.gradients.default', name );
const [ shouldDisplayDefaultGradients ] = useSetting(
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/global-styles/palette.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useSetting } from './hooks';
const EMPTY_COLORS = [];

function Palette( { name } ) {
const [ colorsSetting ] = useSetting( 'color.palette.user', name );
const [ colorsSetting ] = useSetting( 'color.palette.custom', name );
const colors = colorsSetting || EMPTY_COLORS;
const screenPath = ! name
? '/colors/palette'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe( 'global styles renderer', () => {
settings: {
color: {
palette: {
user: [
custom: [
{
name: 'White',
slug: 'white',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe( 'editor utils', () => {
name: 'Secondary',
},
],
user: [
custom: [
{
slug: 'primary',
color: '#007cba',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function getPresetsDeclarations( blockPresets = {} ) {
PRESET_METADATA,
( declarations, { path, valueKey, cssVarInfix } ) => {
const presetByOrigin = get( blockPresets, path, [] );
[ 'default', 'theme', 'user' ].forEach( ( origin ) => {
[ 'default', 'theme', 'custom' ].forEach( ( origin ) => {
if ( presetByOrigin[ origin ] ) {
presetByOrigin[ origin ].forEach( ( value ) => {
declarations.push(
Expand Down Expand Up @@ -94,7 +94,7 @@ function getPresetsClasses( blockSelector, blockPresets = {} ) {
}

const presetByOrigin = get( blockPresets, path, [] );
[ 'default', 'theme', 'user' ].forEach( ( origin ) => {
[ 'default', 'theme', 'custom' ].forEach( ( origin ) => {
if ( presetByOrigin[ origin ] ) {
presetByOrigin[ origin ].forEach( ( { slug } ) => {
classes.forEach( ( { classSuffix, propertyName } ) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/global-styles/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function findInPresetsBy(
for ( const presetByOrigin of orderedPresetsByOrigin ) {
if ( presetByOrigin ) {
// Preset origins ordered by priority.
const origins = [ 'user', 'theme', 'default' ];
const origins = [ 'custom', 'theme', 'default' ];
for ( const origin of origins ) {
const presets = presetByOrigin[ origin ];
if ( presets ) {
Expand Down
20 changes: 10 additions & 10 deletions phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ function test_remove_insecure_properties_removes_non_preset_settings() {
'color' => array(
'custom' => true,
'palette' => array(
'user' => array(
'custom' => array(
array(
'name' => 'Red',
'slug' => 'red',
Expand All @@ -1337,7 +1337,7 @@ function test_remove_insecure_properties_removes_non_preset_settings() {
'color' => array(
'custom' => true,
'palette' => array(
'user' => array(
'custom' => array(
array(
'name' => 'Yellow',
'slug' => 'yellow',
Expand Down Expand Up @@ -1370,7 +1370,7 @@ function test_remove_insecure_properties_removes_non_preset_settings() {
'settings' => array(
'color' => array(
'palette' => array(
'user' => array(
'custom' => array(
array(
'name' => 'Red',
'slug' => 'red',
Expand All @@ -1393,7 +1393,7 @@ function test_remove_insecure_properties_removes_non_preset_settings() {
'core/group' => array(
'color' => array(
'palette' => array(
'user' => array(
'custom' => array(
array(
'name' => 'Yellow',
'slug' => 'yellow',
Expand Down Expand Up @@ -1426,7 +1426,7 @@ function test_remove_insecure_properties_removes_unsafe_preset_settings() {
'settings' => array(
'color' => array(
'palette' => array(
'user' => array(
'custom' => array(
array(
'name' => 'Red/><b>ok</ok>',
'slug' => 'red',
Expand All @@ -1452,7 +1452,7 @@ function test_remove_insecure_properties_removes_unsafe_preset_settings() {
),
'typography' => array(
'fontFamilies' => array(
'user' => array(
'custom' => array(
array(
'name' => 'Helvetica Arial/><b>test</b>',
'slug' => 'helvetica-arial',
Expand Down Expand Up @@ -1480,7 +1480,7 @@ function test_remove_insecure_properties_removes_unsafe_preset_settings() {
'core/group' => array(
'color' => array(
'palette' => array(
'user' => array(
'custom' => array(
array(
'name' => 'Red/><b>ok</ok>',
'slug' => 'red',
Expand Down Expand Up @@ -1515,7 +1515,7 @@ function test_remove_insecure_properties_removes_unsafe_preset_settings() {
'settings' => array(
'color' => array(
'palette' => array(
'user' => array(
'custom' => array(
array(
'name' => 'Pink',
'slug' => 'pink',
Expand All @@ -1526,7 +1526,7 @@ function test_remove_insecure_properties_removes_unsafe_preset_settings() {
),
'typography' => array(
'fontFamilies' => array(
'user' => array(
'custom' => array(
array(
'name' => 'Cambria',
'slug' => 'cambria',
Expand All @@ -1539,7 +1539,7 @@ function test_remove_insecure_properties_removes_unsafe_preset_settings() {
'core/group' => array(
'color' => array(
'palette' => array(
'user' => array(
'custom' => array(
array(
'name' => 'Pink',
'slug' => 'pink',
Expand Down

0 comments on commit 7d47338

Please sign in to comment.