From 7d47338e911c91c373d6b9c25916083827819cfc Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Tue, 23 Nov 2021 09:08:15 +0000 Subject: [PATCH] Update: Rename user preset origin to custom (#36748) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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> --- lib/class-wp-theme-json-gutenberg.php | 6 +++--- ...class-wp-theme-json-resolver-gutenberg.php | 14 ++++++------- .../get-global-styles-and-settings.php | 6 +++--- lib/global-styles.php | 10 +++++----- .../panel-color-gradient-settings.js | 4 ++-- .../src/components/use-setting/index.js | 2 +- .../global-styles-context/utils.native.js | 4 ++-- .../global-styles/color-palette-panel.js | 2 +- .../src/components/global-styles/hooks.js | 8 ++++---- .../src/components/global-styles/palette.js | 2 +- .../test/use-global-styles-output.js | 2 +- .../components/global-styles/test/utils.js | 2 +- .../global-styles/use-global-styles-output.js | 4 ++-- .../src/components/global-styles/utils.js | 2 +- phpunit/class-wp-theme-json-test.php | 20 +++++++++---------- 15 files changed, 44 insertions(+), 44 deletions(-) diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index 31919039b93d56..86bcba14cac345 100644 --- a/lib/class-wp-theme-json-gutenberg.php +++ b/lib/class-wp-theme-json-gutenberg.php @@ -37,7 +37,7 @@ class WP_Theme_JSON_Gutenberg { const VALID_ORIGINS = array( 'default', 'theme', - 'user', + 'custom', ); const VALID_TOP_LEVEL_KEYS = array( @@ -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 ) ) { @@ -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. */ diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index e697f3598635ef..50984fde62d388 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -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. @@ -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}, @@ -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() ); } diff --git a/lib/compat/wordpress-5.9/get-global-styles-and-settings.php b/lib/compat/wordpress-5.9/get-global-styles-and-settings.php index 532e97325055ac..409c01009da2b2 100644 --- a/lib/compat/wordpress-5.9/get-global-styles-and-settings.php +++ b/lib/compat/wordpress-5.9/get-global-styles-and-settings.php @@ -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'; } @@ -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'; } @@ -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' ); diff --git a/lib/global-styles.php b/lib/global-styles.php index 2d71902841e8de..98fe03c9ef204c 100644 --- a/lib/global-styles.php +++ b/lib/global-styles.php @@ -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'] @@ -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'] @@ -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'] : diff --git a/packages/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js b/packages/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js index fa807439819fe8..158071197c95ce 100644 --- a/packages/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js +++ b/packages/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js @@ -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' ); @@ -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( diff --git a/packages/block-editor/src/components/use-setting/index.js b/packages/block-editor/src/components/use-setting/index.js index c57a53026cb499..00cda78b2e8b3c 100644 --- a/packages/block-editor/src/components/use-setting/index.js +++ b/packages/block-editor/src/components/use-setting/index.js @@ -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 ); diff --git a/packages/components/src/mobile/global-styles-context/utils.native.js b/packages/components/src/mobile/global-styles-context/utils.native.js index 18207b93966972..9f6bbfae938c5a 100644 --- a/packages/components/src/mobile/global-styles-context/utils.native.js +++ b/packages/components/src/mobile/global-styles-context/utils.native.js @@ -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: { diff --git a/packages/edit-site/src/components/global-styles/color-palette-panel.js b/packages/edit-site/src/components/global-styles/color-palette-panel.js index 8332b6233ce58b..a6f34357b70027 100644 --- a/packages/edit-site/src/components/global-styles/color-palette-panel.js +++ b/packages/edit-site/src/components/global-styles/color-palette-panel.js @@ -32,7 +32,7 @@ export default function ColorPalettePanel( { name } ) { 'base' ); const [ customColors, setCustomColors ] = useSetting( - 'color.palette.user', + 'color.palette.custom', name ); diff --git a/packages/edit-site/src/components/global-styles/hooks.js b/packages/edit-site/src/components/global-styles/hooks.js index a639237ac0cf72..6c90220fbf788d 100644 --- a/packages/edit-site/src/components/global-styles/hooks.js +++ b/packages/edit-site/src/components/global-styles/hooks.js @@ -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 ); @@ -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; }; @@ -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' ); @@ -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( diff --git a/packages/edit-site/src/components/global-styles/palette.js b/packages/edit-site/src/components/global-styles/palette.js index 36375d1b84e433..06139043d5330f 100644 --- a/packages/edit-site/src/components/global-styles/palette.js +++ b/packages/edit-site/src/components/global-styles/palette.js @@ -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' diff --git a/packages/edit-site/src/components/global-styles/test/use-global-styles-output.js b/packages/edit-site/src/components/global-styles/test/use-global-styles-output.js index 0c4f7d8119f9d4..7433074da3bf61 100644 --- a/packages/edit-site/src/components/global-styles/test/use-global-styles-output.js +++ b/packages/edit-site/src/components/global-styles/test/use-global-styles-output.js @@ -206,7 +206,7 @@ describe( 'global styles renderer', () => { settings: { color: { palette: { - user: [ + custom: [ { name: 'White', slug: 'white', diff --git a/packages/edit-site/src/components/global-styles/test/utils.js b/packages/edit-site/src/components/global-styles/test/utils.js index 40e434a935dbb5..283384f36658f2 100644 --- a/packages/edit-site/src/components/global-styles/test/utils.js +++ b/packages/edit-site/src/components/global-styles/test/utils.js @@ -21,7 +21,7 @@ describe( 'editor utils', () => { name: 'Secondary', }, ], - user: [ + custom: [ { slug: 'primary', color: '#007cba', diff --git a/packages/edit-site/src/components/global-styles/use-global-styles-output.js b/packages/edit-site/src/components/global-styles/use-global-styles-output.js index b0d40133cca2c0..4908196c84d27e 100644 --- a/packages/edit-site/src/components/global-styles/use-global-styles-output.js +++ b/packages/edit-site/src/components/global-styles/use-global-styles-output.js @@ -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( @@ -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 } ) => { diff --git a/packages/edit-site/src/components/global-styles/utils.js b/packages/edit-site/src/components/global-styles/utils.js index 0b1c7607de23ac..aac3e40a1a9612 100644 --- a/packages/edit-site/src/components/global-styles/utils.js +++ b/packages/edit-site/src/components/global-styles/utils.js @@ -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 ) { diff --git a/phpunit/class-wp-theme-json-test.php b/phpunit/class-wp-theme-json-test.php index e1589cb7ddc290..94aac0d8e6e003 100644 --- a/phpunit/class-wp-theme-json-test.php +++ b/phpunit/class-wp-theme-json-test.php @@ -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', @@ -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', @@ -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', @@ -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', @@ -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/>ok', 'slug' => 'red', @@ -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/>test', 'slug' => 'helvetica-arial', @@ -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/>ok', 'slug' => 'red', @@ -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', @@ -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', @@ -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',