WordPress/wp-includes/class-wp-theme-json-resolve...

555 lines
18 KiB
PHP
Raw Normal View History

<?php
/**
* WP_Theme_JSON_Resolver class
*
* @package WordPress
* @subpackage Theme
* @since 5.8.0
*/
/**
* Class that abstracts the processing of the different data sources
* for site-level config and offers an API to work with them.
*
* This class is for internal core usage and is not supposed to be used by extenders (plugins and/or themes).
* This is a low-level API that may need to do breaking changes. Please,
* use get_global_settings, get_global_styles, and get_global_stylesheet instead.
*
* @access private
*/
Code Modernization: Add `AllowDynamicProperties` attribute to all (parent) classes. Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0. There are a number of ways to mitigate this: * If it is an accidental typo for a declared property: fix the typo. * For known properties: declare them on the class. * For unknown properties: add the magic `__get()`, `__set()`, et al. methods to the class or let the class extend `stdClass` which has highly optimized versions of these magic methods built in. * For unknown ''use'' of dynamic properties, the `#[AllowDynamicProperties]` attribute can be added to the class. The attribute will automatically be inherited by child classes. Trac ticket #56034 is open to investigate and handle the third and fourth type of situations, however it has become clear this will need more time and will not be ready in time for WP 6.1. To reduce “noise” in the meantime, both in the error logs of WP users moving onto PHP 8.2, in the test run logs of WP itself, in test runs of plugins and themes, as well as to prevent duplicate tickets from being opened for the same issue, this commit adds the `#[AllowDynamicProperties]` attribute to all “parent” classes in WP. The logic used for this commit is as follows: * If a class already has the attribute: no action needed. * If a class does not `extend`: add the attribute. * If a class does `extend`: - If it extends `stdClass`: no action needed (as `stdClass` supports dynamic properties). - If it extends a PHP native class: add the attribute. - If it extends a class from one of WP's external dependencies: add the attribute. * In all other cases: no action — the attribute should not be needed as child classes inherit from the parent. Whether or not a class contains magic methods has not been taken into account, as a review of the currently existing magic methods has shown that those are generally not sturdy enough and often even set dynamic properties (which they should not). See the [https://www.youtube.com/watch?v=vDZWepDQQVE live stream from August 16, 2022] for more details. This commit only affects classes in the `src` directory of WordPress core. * Tests should not get this attribute, but should be fixed to not use dynamic properties instead. Patches for this are already being committed under ticket #56033. * While a number bundled themes (2014, 2019, 2020, 2021) contain classes, they are not a part of this commit and may be updated separately. Reference: [https://wiki.php.net/rfc/deprecate_dynamic_properties PHP RFC: Deprecate dynamic properties]. Follow-up to [53922]. Props jrf, hellofromTonya, markjaquith, peterwilsoncc, costdev, knutsp, aristath. See #56513, #56034. Built from https://develop.svn.wordpress.org/trunk@54133 git-svn-id: http://core.svn.wordpress.org/trunk@53692 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-12 11:47:14 -04:00
#[AllowDynamicProperties]
class WP_Theme_JSON_Resolver {
/**
* Container for data coming from core.
*
* @since 5.8.0
* @var WP_Theme_JSON
*/
protected static $core = null;
/**
* Container for data coming from the theme.
*
* @since 5.8.0
* @var WP_Theme_JSON
*/
protected static $theme = null;
/**
* Whether or not the theme supports theme.json.
*
* @since 5.8.0
* @var bool
*/
protected static $theme_has_support = null;
/**
* Container for data coming from the user.
*
* @since 5.9.0
* @var WP_Theme_JSON
*/
protected static $user = null;
/**
* Stores the ID of the custom post type
* that holds the user data.
*
* @since 5.9.0
* @var int
*/
protected static $user_custom_post_type_id = null;
/**
* Container to keep loaded i18n schema for `theme.json`.
*
* @since 5.8.0 As `$theme_json_i18n`.
* @since 5.9.0 Renamed from `$theme_json_i18n` to `$i18n_schema`.
* @var array
*/
protected static $i18n_schema = null;
/**
* Processes a file that adheres to the theme.json schema
* and returns an array with its contents, or a void array if none found.
*
* @since 5.8.0
*
* @param string $file_path Path to file. Empty if no file.
* @return array Contents that adhere to the theme.json schema.
*/
protected static function read_json_file( $file_path ) {
$config = array();
if ( $file_path ) {
$decoded_file = wp_json_file_decode( $file_path, array( 'associative' => true ) );
if ( is_array( $decoded_file ) ) {
$config = $decoded_file;
}
}
return $config;
}
/**
* Returns a data structure used in theme.json translation.
*
* @since 5.8.0
* @deprecated 5.9.0
*
* @return array An array of theme.json fields that are translatable and the keys that are translatable.
*/
public static function get_fields_to_translate() {
_deprecated_function( __METHOD__, '5.9.0' );
return array();
}
/**
* Given a theme.json structure modifies it in place to update certain values
* by its translated strings according to the language set by the user.
*
* @since 5.8.0
*
* @param array $theme_json The theme.json to translate.
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
* Default 'default'.
* @return array Returns the modified $theme_json_structure.
*/
protected static function translate( $theme_json, $domain = 'default' ) {
if ( null === static::$i18n_schema ) {
$i18n_schema = wp_json_file_decode( __DIR__ . '/theme-i18n.json' );
static::$i18n_schema = null === $i18n_schema ? array() : $i18n_schema;
}
return translate_settings_using_i18n_schema( static::$i18n_schema, $theme_json, $domain );
}
/**
* Returns core's origin config.
*
* @since 5.8.0
*
* @return WP_Theme_JSON Entity that holds core data.
*/
public static function get_core_data() {
if ( null !== static::$core ) {
return static::$core;
}
$config = static::read_json_file( __DIR__ . '/theme.json' );
$config = static::translate( $config );
static::$core = new WP_Theme_JSON( $config, 'default' );
return static::$core;
}
/**
* Returns the theme's data.
*
* Data from theme.json will be backfilled from existing
* theme supports, if any. Note that if the same data
* is present in theme.json and in theme supports,
* the theme.json takes precedence.
*
* @since 5.8.0
* @since 5.9.0 Theme supports have been inlined and the `$theme_support_data` argument removed.
* @since 6.0.0 Added an `$options` parameter to allow the theme data to be returned without theme supports.
*
* @param array $deprecated Deprecated. Not used.
* @param array $options {
* Options arguments.
*
* @type bool $with_supports Whether to include theme supports in the data. Default true.
* }
* @return WP_Theme_JSON Entity that holds theme data.
*/
public static function get_theme_data( $deprecated = array(), $options = array() ) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __METHOD__, '5.9.0' );
}
$options = wp_parse_args( $options, array( 'with_supports' => true ) );
if ( null === static::$theme ) {
$theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json' ) );
$theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) );
static::$theme = new WP_Theme_JSON( $theme_json_data );
if ( wp_get_theme()->parent() ) {
// Get parent theme.json.
$parent_theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json', true ) );
$parent_theme_json_data = static::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) );
$parent_theme = new WP_Theme_JSON( $parent_theme_json_data );
// Merge the child theme.json into the parent theme.json.
// The child theme takes precedence over the parent.
$parent_theme->merge( static::$theme );
static::$theme = $parent_theme;
}
}
if ( ! $options['with_supports'] ) {
return static::$theme;
}
/*
* We want the presets and settings declared in theme.json
* to override the ones declared via theme supports.
* So we take theme supports, transform it to theme.json shape
* and merge the static::$theme upon that.
*/
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - FSE: Add welcome guide - Update theme styles for the code block - Add feature flag to toggle the new site editor sidebar - Add templates list page for site editor - Cover Block: Fix default background dim - E2E: Add more Cover block tests - Cover Block: Fix regressions - Post Comments Form: ensure typography styles are applied to child elements - Navigation: Fix space-between - Fix background colours in nested submenus. - Fix duplicate custom classnames in navigation submenu block - Fix colour rendering in Navigation overlay - Fix: Add ability to opt out of Core color palette V2 - Change @package to WordPress in block-library - Make the core color palette opt-in for themes with not theme.json - Remove textdomain from calendar block - Page List block: fix space before href attribute - Try: Let Featured Image block inherit dimensions, look like a placeholder - [Global Styles]: Add block icon next to blocks list - Page List: Use core entities instead of direct apiFetch - Site Editor: Stabilize export endpoint - Fix mobile horizontal scrollbar. - Multi-entity save: Only set site entity to pending if really saving - Add page list to navigation direct insert conditions - Implement "Add New" for templates list in Site Editor - Post Featured Image: Remove withNotices HOC - Fix page list missing button styles when set to open on click. - Make appender fixed position to avoid jumps in the UI - Color UI component: reorder palettes and update names (core by defaults, user by custom) - Remove the Styles link in Site Editor - GlobalStyles sidebar: do not show default palette if theme opts-out - Only render the site editor canvas when the global styles are ready. - Global Styles: rename core origin key to default for presets - Clarify i18n context for PostTemplateActions's "New" label - Revert erroneous native editor package version bumps - Try: Hide the columns inserter in pattern previews. - Fix site editor region navigation - Update navigation sidebar responsiveness - Add _wp_array_set and _wp_to_kebab_case to 5.8 compat - Make user able to change all color palette origins - Site Editor: Update hrefs to not specifically refer to themes.php?page=gutenberg-edit-site - Site Editor: Validate the postType query argument - Navigation: Scale submenu icon. - Move the theme editor under tools for FSE themes - Deprecate navigation areas See #54487. Built from https://develop.svn.wordpress.org/trunk@52232 git-svn-id: http://core.svn.wordpress.org/trunk@51824 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-23 00:40:38 -05:00
$theme_support_data = WP_Theme_JSON::get_from_editor_settings( get_default_block_editor_settings() );
if ( ! static::theme_has_support() ) {
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - FSE: Add welcome guide - Update theme styles for the code block - Add feature flag to toggle the new site editor sidebar - Add templates list page for site editor - Cover Block: Fix default background dim - E2E: Add more Cover block tests - Cover Block: Fix regressions - Post Comments Form: ensure typography styles are applied to child elements - Navigation: Fix space-between - Fix background colours in nested submenus. - Fix duplicate custom classnames in navigation submenu block - Fix colour rendering in Navigation overlay - Fix: Add ability to opt out of Core color palette V2 - Change @package to WordPress in block-library - Make the core color palette opt-in for themes with not theme.json - Remove textdomain from calendar block - Page List block: fix space before href attribute - Try: Let Featured Image block inherit dimensions, look like a placeholder - [Global Styles]: Add block icon next to blocks list - Page List: Use core entities instead of direct apiFetch - Site Editor: Stabilize export endpoint - Fix mobile horizontal scrollbar. - Multi-entity save: Only set site entity to pending if really saving - Add page list to navigation direct insert conditions - Implement "Add New" for templates list in Site Editor - Post Featured Image: Remove withNotices HOC - Fix page list missing button styles when set to open on click. - Make appender fixed position to avoid jumps in the UI - Color UI component: reorder palettes and update names (core by defaults, user by custom) - Remove the Styles link in Site Editor - GlobalStyles sidebar: do not show default palette if theme opts-out - Only render the site editor canvas when the global styles are ready. - Global Styles: rename core origin key to default for presets - Clarify i18n context for PostTemplateActions's "New" label - Revert erroneous native editor package version bumps - Try: Hide the columns inserter in pattern previews. - Fix site editor region navigation - Update navigation sidebar responsiveness - Add _wp_array_set and _wp_to_kebab_case to 5.8 compat - Make user able to change all color palette origins - Site Editor: Update hrefs to not specifically refer to themes.php?page=gutenberg-edit-site - Site Editor: Validate the postType query argument - Navigation: Scale submenu icon. - Move the theme editor under tools for FSE themes - Deprecate navigation areas See #54487. Built from https://develop.svn.wordpress.org/trunk@52232 git-svn-id: http://core.svn.wordpress.org/trunk@51824 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-23 00:40:38 -05:00
if ( ! isset( $theme_support_data['settings']['color'] ) ) {
$theme_support_data['settings']['color'] = array();
}
$default_palette = false;
if ( current_theme_supports( 'default-color-palette' ) ) {
$default_palette = true;
}
if ( ! isset( $theme_support_data['settings']['color']['palette'] ) ) {
// If the theme does not have any palette, we still want to show the core one.
$default_palette = true;
}
$theme_support_data['settings']['color']['defaultPalette'] = $default_palette;
$default_gradients = false;
if ( current_theme_supports( 'default-gradient-presets' ) ) {
$default_gradients = true;
}
if ( ! isset( $theme_support_data['settings']['color']['gradients'] ) ) {
// If the theme does not have any gradients, we still want to show the core ones.
$default_gradients = true;
}
$theme_support_data['settings']['color']['defaultGradients'] = $default_gradients;
// Classic themes without a theme.json don't support global duotone.
$theme_support_data['settings']['color']['defaultDuotone'] = false;
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - FSE: Add welcome guide - Update theme styles for the code block - Add feature flag to toggle the new site editor sidebar - Add templates list page for site editor - Cover Block: Fix default background dim - E2E: Add more Cover block tests - Cover Block: Fix regressions - Post Comments Form: ensure typography styles are applied to child elements - Navigation: Fix space-between - Fix background colours in nested submenus. - Fix duplicate custom classnames in navigation submenu block - Fix colour rendering in Navigation overlay - Fix: Add ability to opt out of Core color palette V2 - Change @package to WordPress in block-library - Make the core color palette opt-in for themes with not theme.json - Remove textdomain from calendar block - Page List block: fix space before href attribute - Try: Let Featured Image block inherit dimensions, look like a placeholder - [Global Styles]: Add block icon next to blocks list - Page List: Use core entities instead of direct apiFetch - Site Editor: Stabilize export endpoint - Fix mobile horizontal scrollbar. - Multi-entity save: Only set site entity to pending if really saving - Add page list to navigation direct insert conditions - Implement "Add New" for templates list in Site Editor - Post Featured Image: Remove withNotices HOC - Fix page list missing button styles when set to open on click. - Make appender fixed position to avoid jumps in the UI - Color UI component: reorder palettes and update names (core by defaults, user by custom) - Remove the Styles link in Site Editor - GlobalStyles sidebar: do not show default palette if theme opts-out - Only render the site editor canvas when the global styles are ready. - Global Styles: rename core origin key to default for presets - Clarify i18n context for PostTemplateActions's "New" label - Revert erroneous native editor package version bumps - Try: Hide the columns inserter in pattern previews. - Fix site editor region navigation - Update navigation sidebar responsiveness - Add _wp_array_set and _wp_to_kebab_case to 5.8 compat - Make user able to change all color palette origins - Site Editor: Update hrefs to not specifically refer to themes.php?page=gutenberg-edit-site - Site Editor: Validate the postType query argument - Navigation: Scale submenu icon. - Move the theme editor under tools for FSE themes - Deprecate navigation areas See #54487. Built from https://develop.svn.wordpress.org/trunk@52232 git-svn-id: http://core.svn.wordpress.org/trunk@51824 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-23 00:40:38 -05:00
}
$with_theme_supports = new WP_Theme_JSON( $theme_support_data );
$with_theme_supports->merge( static::$theme );
return $with_theme_supports;
}
Editor: Backport foundation for Layout block support refactor (part 1). Backports the following changes from the Gutenberg repository: * [WordPress/gutenberg/40875 gutenberg/40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json * [WordPress/gutenberg/42544 gutenberg/42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg/42544 * [WordPress/gutenberg/42087 gutenberg/42087] Theme.json: Add block support feature level selectors for blocks gutenberg/42087 * [WordPress/gutenberg/43792 gutenberg/43792] Global Styles: Split root layout rules into a different function gutenberg/43792 * [WordPress/gutenberg/42544 gutenberg/42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg/42544 * [WordPress/gutenberg/42665 gutenberg/42665] Layout: Reduce specificity of fallback blockGap styles gutenberg/42665 * [WordPress/gutenberg/42085 gutenberg/42085] Core CSS support for root padding and alignfull blocks gutenberg/42085 Notes: * It doesn't entirely port over PR 40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`. * [54159] was reverted in [54160] due to PHPUnit test failures for tests added by the commit. Later, tests passed when applied on top of `trunk`. There were various outages today of upstream `wp-env` dependencies, which likely were the root cause of the earlier failures. For historical tracking and to make sure, recommitting [54159] but instead on top of current `trunk`. See PR 3205 for more details. * Giving additional props for those who did a deep dive investigation into the failed tests. Follow-up to [54160], [54159]. Props andrewserong, aaronrobertshaw, isabel_brison, bernhard-reiter, hellofromTonya. See #56467. Built from https://develop.svn.wordpress.org/trunk@54162 git-svn-id: http://core.svn.wordpress.org/trunk@53721 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-14 14:44:09 -04:00
/**
* Gets the styles for blocks from the block.json file.
*
* @since 6.1.0
*
* @return WP_Theme_JSON
*/
public static function get_block_data() {
$registry = WP_Block_Type_Registry::get_instance();
$blocks = $registry->get_all_registered();
$config = array( 'version' => 1 );
foreach ( $blocks as $block_name => $block_type ) {
if ( isset( $block_type->supports['__experimentalStyle'] ) ) {
$config['styles']['blocks'][ $block_name ] = static::remove_json_comments( $block_type->supports['__experimentalStyle'] );
}
if (
isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ) &&
null === _wp_array_get( $config, array( 'styles', 'blocks', $block_name, 'spacing', 'blockGap' ), null )
) {
// Ensure an empty placeholder value exists for the block, if it provides a default blockGap value.
// The real blockGap value to be used will be determined when the styles are rendered for output.
$config['styles']['blocks'][ $block_name ]['spacing']['blockGap'] = null;
}
}
// Core here means it's the lower level part of the styles chain.
// It can be a core or a third-party block.
return new WP_Theme_JSON( $config, 'core' );
}
/**
* When given an array, this will remove any keys with the name `//`.
*
* @param array $array The array to filter.
* @return array The filtered array.
*/
private static function remove_json_comments( $array ) {
unset( $array['//'] );
foreach ( $array as $k => $v ) {
if ( is_array( $v ) ) {
$array[ $k ] = static::remove_json_comments( $v );
}
}
return $array;
}
/**
* Returns the custom post type that contains the user's origin config
* for the active theme or a void array if none are found.
*
* This can also create and return a new draft custom post type.
*
* @since 5.9.0
*
* @param WP_Theme $theme The theme object. If empty, it
* defaults to the active theme.
* @param bool $create_post Optional. Whether a new custom post
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. Built from https://develop.svn.wordpress.org/trunk@52275 git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-29 19:24:27 -05:00
* type should be created if none are
* found. Default false.
* @param array $post_status_filter Optional. Filter custom post type by
* post status. Default `array( 'publish' )`,
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. Built from https://develop.svn.wordpress.org/trunk@52275 git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-29 19:24:27 -05:00
* so it only fetches published posts.
* @return array Custom Post Type for the user's origin config.
*/
public static function get_user_data_from_wp_global_styles( $theme, $create_post = false, $post_status_filter = array( 'publish' ) ) {
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. Built from https://develop.svn.wordpress.org/trunk@52275 git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-29 19:24:27 -05:00
if ( ! $theme instanceof WP_Theme ) {
$theme = wp_get_theme();
}
$user_cpt = array();
$post_type_filter = 'wp_global_styles';
$stylesheet = $theme->get_stylesheet();
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. Built from https://develop.svn.wordpress.org/trunk@52275 git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-29 19:24:27 -05:00
$args = array(
'posts_per_page' => 1,
'orderby' => 'post_date',
'order' => 'desc',
'post_type' => $post_type_filter,
'post_status' => $post_status_filter,
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'tax_query' => array(
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. Built from https://develop.svn.wordpress.org/trunk@52275 git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-29 19:24:27 -05:00
array(
'taxonomy' => 'wp_theme',
'field' => 'name',
'terms' => $stylesheet,
),
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. Built from https://develop.svn.wordpress.org/trunk@52275 git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-29 19:24:27 -05:00
),
);
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. Built from https://develop.svn.wordpress.org/trunk@52275 git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-29 19:24:27 -05:00
$cache_key = sprintf( 'wp_global_styles_%s', md5( serialize( $args ) ) );
$post_id = (int) get_transient( $cache_key );
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. Built from https://develop.svn.wordpress.org/trunk@52275 git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-29 19:24:27 -05:00
// Special case: '-1' is a results not found.
if ( -1 === $post_id && ! $create_post ) {
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. Built from https://develop.svn.wordpress.org/trunk@52275 git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-29 19:24:27 -05:00
return $user_cpt;
}
if ( $post_id > 0 && in_array( get_post_status( $post_id ), (array) $post_status_filter, true ) ) {
return get_post( $post_id, ARRAY_A );
}
$global_style_query = new WP_Query();
$recent_posts = $global_style_query->query( $args );
if ( count( $recent_posts ) === 1 ) {
$user_cpt = get_post( $recent_posts[0], ARRAY_A );
} elseif ( $create_post ) {
$cpt_post_id = wp_insert_post(
array(
'post_content' => '{"version": ' . WP_Theme_JSON::LATEST_SCHEMA . ', "isGlobalStylesUserThemeJSON": true }',
'post_status' => 'publish',
'post_title' => __( 'Custom Styles' ),
'post_type' => $post_type_filter,
'post_name' => sprintf( 'wp-global-styles-%s', urlencode( $stylesheet ) ),
'tax_input' => array(
'wp_theme' => array( $stylesheet ),
),
),
true
);
if ( ! is_wp_error( $cpt_post_id ) ) {
$user_cpt = get_post( $cpt_post_id, ARRAY_A );
}
}
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. Built from https://develop.svn.wordpress.org/trunk@52275 git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-29 19:24:27 -05:00
$cache_expiration = $user_cpt ? DAY_IN_SECONDS : HOUR_IN_SECONDS;
set_transient( $cache_key, $user_cpt ? $user_cpt['ID'] : -1, $cache_expiration );
return $user_cpt;
}
/**
* Returns the user's origin config.
*
* @since 5.9.0
*
* @return WP_Theme_JSON Entity that holds styles for user data.
*/
public static function get_user_data() {
if ( null !== static::$user ) {
return static::$user;
}
$config = array();
$user_cpt = static::get_user_data_from_wp_global_styles( wp_get_theme() );
if ( array_key_exists( 'post_content', $user_cpt ) ) {
$decoded_data = json_decode( $user_cpt['post_content'], true );
$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() );
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. Built from https://develop.svn.wordpress.org/trunk@52275 git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-29 19:24:27 -05:00
return new WP_Theme_JSON( $config, 'custom' );
}
// Very important to verify that the flag isGlobalStylesUserThemeJSON is true.
// If it's not true then the content was not escaped and is not safe.
if (
is_array( $decoded_data ) &&
isset( $decoded_data['isGlobalStylesUserThemeJSON'] ) &&
$decoded_data['isGlobalStylesUserThemeJSON']
) {
unset( $decoded_data['isGlobalStylesUserThemeJSON'] );
$config = $decoded_data;
}
}
static::$user = new WP_Theme_JSON( $config, 'custom' );
return static::$user;
}
/**
* Returns the data merged from multiple origins.
*
* There are three sources of data (origins) for a site:
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. Built from https://develop.svn.wordpress.org/trunk@52275 git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-29 19:24:27 -05:00
* default, theme, and custom. The custom's has higher priority
* than the theme's, and the theme's higher than default's.
*
* Unlike the getters
* {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_core_data/ get_core_data},
* {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_theme_data/ get_theme_data},
* and {@link https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_user_data/ get_user_data},
* this method returns data after it has been merged with the previous origins.
* This means that if the same piece of data is declared in different origins
* (user, theme, and core), the last origin overrides the previous.
*
* For example, if the user has set a background color
* for the paragraph block, and the theme has done it as well,
* the user preference wins.
*
* @since 5.8.0
* @since 5.9.0 Added user data, removed the `$settings` parameter,
* added the `$origin` parameter.
Editor: Backport foundation for Layout block support refactor (part 1). Backports the following changes from the Gutenberg repository: * [WordPress/gutenberg/40875 gutenberg/40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json * [WordPress/gutenberg/42544 gutenberg/42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg/42544 * [WordPress/gutenberg/42087 gutenberg/42087] Theme.json: Add block support feature level selectors for blocks gutenberg/42087 * [WordPress/gutenberg/43792 gutenberg/43792] Global Styles: Split root layout rules into a different function gutenberg/43792 * [WordPress/gutenberg/42544 gutenberg/42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg/42544 * [WordPress/gutenberg/42665 gutenberg/42665] Layout: Reduce specificity of fallback blockGap styles gutenberg/42665 * [WordPress/gutenberg/42085 gutenberg/42085] Core CSS support for root padding and alignfull blocks gutenberg/42085 Notes: * It doesn't entirely port over PR 40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`. * [54159] was reverted in [54160] due to PHPUnit test failures for tests added by the commit. Later, tests passed when applied on top of `trunk`. There were various outages today of upstream `wp-env` dependencies, which likely were the root cause of the earlier failures. For historical tracking and to make sure, recommitting [54159] but instead on top of current `trunk`. See PR 3205 for more details. * Giving additional props for those who did a deep dive investigation into the failed tests. Follow-up to [54160], [54159]. Props andrewserong, aaronrobertshaw, isabel_brison, bernhard-reiter, hellofromTonya. See #56467. Built from https://develop.svn.wordpress.org/trunk@54162 git-svn-id: http://core.svn.wordpress.org/trunk@53721 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-14 14:44:09 -04:00
* @since 6.1.0 Added block data.
*
* @param string $origin Optional. To what level should we merge data.
* Valid values are 'theme' or 'custom'. Default 'custom'.
* @return WP_Theme_JSON
*/
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. Built from https://develop.svn.wordpress.org/trunk@52275 git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-29 19:24:27 -05:00
public static function get_merged_data( $origin = 'custom' ) {
if ( is_array( $origin ) ) {
_deprecated_argument( __FUNCTION__, '5.9.0' );
}
$result = new WP_Theme_JSON();
$result->merge( static::get_core_data() );
Editor: Backport foundation for Layout block support refactor (part 1). Backports the following changes from the Gutenberg repository: * [WordPress/gutenberg/40875 gutenberg/40875] Layout: Use semantic classnames, centralize layout definitions, reduce duplication, and fix blockGap in theme.json * [WordPress/gutenberg/42544 gutenberg/42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg/42544 * [WordPress/gutenberg/42087 gutenberg/42087] Theme.json: Add block support feature level selectors for blocks gutenberg/42087 * [WordPress/gutenberg/43792 gutenberg/43792] Global Styles: Split root layout rules into a different function gutenberg/43792 * [WordPress/gutenberg/42544 gutenberg/42544] Layout: Add a disable-layout-styles theme supports flag to opt out of all layout styles gutenberg/42544 * [WordPress/gutenberg/42665 gutenberg/42665] Layout: Reduce specificity of fallback blockGap styles gutenberg/42665 * [WordPress/gutenberg/42085 gutenberg/42085] Core CSS support for root padding and alignfull blocks gutenberg/42085 Notes: * It doesn't entirely port over PR 40875 — the remaining PHP changes for that PR will be explored in a separate PR targeting `layout.php`. * [54159] was reverted in [54160] due to PHPUnit test failures for tests added by the commit. Later, tests passed when applied on top of `trunk`. There were various outages today of upstream `wp-env` dependencies, which likely were the root cause of the earlier failures. For historical tracking and to make sure, recommitting [54159] but instead on top of current `trunk`. See PR 3205 for more details. * Giving additional props for those who did a deep dive investigation into the failed tests. Follow-up to [54160], [54159]. Props andrewserong, aaronrobertshaw, isabel_brison, bernhard-reiter, hellofromTonya. See #56467. Built from https://develop.svn.wordpress.org/trunk@54162 git-svn-id: http://core.svn.wordpress.org/trunk@53721 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-14 14:44:09 -04:00
$result->merge( static::get_block_data() );
$result->merge( static::get_theme_data() );
Update @wordpress packages Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. Built from https://develop.svn.wordpress.org/trunk@52275 git-svn-id: http://core.svn.wordpress.org/trunk@51867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-11-29 19:24:27 -05:00
if ( 'custom' === $origin ) {
$result->merge( static::get_user_data() );
}
return $result;
}
/**
* Returns the ID of the custom post type
* that stores user data.
*
* @since 5.9.0
*
* @return integer|null
*/
public static function get_user_global_styles_post_id() {
if ( null !== static::$user_custom_post_type_id ) {
return static::$user_custom_post_type_id;
}
$user_cpt = static::get_user_data_from_wp_global_styles( wp_get_theme(), true );
if ( array_key_exists( 'ID', $user_cpt ) ) {
static::$user_custom_post_type_id = $user_cpt['ID'];
}
return static::$user_custom_post_type_id;
}
/**
* Determines whether the active theme has a theme.json file.
*
* @since 5.8.0
* @since 5.9.0 Added a check in the parent theme.
*
* @return bool
*/
public static function theme_has_support() {
if ( ! isset( static::$theme_has_support ) ) {
static::$theme_has_support = (
is_readable( static::get_file_path_from_theme( 'theme.json' ) ) ||
is_readable( static::get_file_path_from_theme( 'theme.json', true ) )
);
}
return static::$theme_has_support;
}
/**
* Builds the path to the given file and checks that it is readable.
*
* If it isn't, returns an empty string, otherwise returns the whole file path.
*
* @since 5.8.0
* @since 5.9.0 Adapted to work with child themes, added the `$template` argument.
*
* @param string $file_name Name of the file.
* @param bool $template Optional. Use template theme directory. Default false.
* @return string The whole file path or empty if the file doesn't exist.
*/
protected static function get_file_path_from_theme( $file_name, $template = false ) {
$path = $template ? get_template_directory() : get_stylesheet_directory();
$candidate = $path . '/' . $file_name;
return is_readable( $candidate ) ? $candidate : '';
}
/**
* Cleans the cached data so it can be recalculated.
*
* @since 5.8.0
* @since 5.9.0 Added the `$user`, `$user_custom_post_type_id`,
* and `$i18n_schema` variables to reset.
*/
public static function clean_cached_data() {
static::$core = null;
static::$theme = null;
static::$user = null;
static::$user_custom_post_type_id = null;
static::$theme_has_support = null;
static::$i18n_schema = null;
}
/**
* Returns the style variations defined by the theme.
*
* @since 6.0.0
*
* @return array
*/
public static function get_style_variations() {
$variations = array();
$base_directory = get_stylesheet_directory() . '/styles';
if ( is_dir( $base_directory ) ) {
$nested_files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $base_directory ) );
$nested_html_files = iterator_to_array( new RegexIterator( $nested_files, '/^.+\.json$/i', RecursiveRegexIterator::GET_MATCH ) );
ksort( $nested_html_files );
foreach ( $nested_html_files as $path => $file ) {
$decoded_file = wp_json_file_decode( $path, array( 'associative' => true ) );
if ( is_array( $decoded_file ) ) {
$translated = static::translate( $decoded_file, wp_get_theme()->get( 'TextDomain' ) );
$variation = ( new WP_Theme_JSON( $translated ) )->get_raw_data();
if ( empty( $variation['title'] ) ) {
$variation['title'] = basename( $path, '.json' );
}
$variations[] = $variation;
}
}
}
return $variations;
}
}