Make WordPress Core


Ignore:
Timestamp:
11/30/2021 12:22:30 AM (3 years ago)
Author:
noisysocks
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json-resolver.php

    r52232 r52275  
    223223     * @since 5.9.0
    224224     *
    225      * @param bool  $should_create_cpt  Optional. Whether a new custom post type should be created if none are found.
    226      *                                  False by default.
    227      * @param array $post_status_filter Filter Optional. custom post type by post status.
    228      *                                   ['publish'] by default, so it only fetches published posts.
    229      *
     225     * @param WP_Theme $theme              The theme object.  If empty, it
     226     *                                     defaults to the current theme.
     227     * @param bool     $should_create_cpt  Optional. Whether a new custom post
     228     *                                     type should be created if none are
     229     *                                     found.  False by default.
     230     * @param array    $post_status_filter Filter Optional. custom post type by
     231     *                                     post status.  ['publish'] by default,
     232     *                                     so it only fetches published posts.
    230233     * @return array Custom Post Type for the user's origin config.
    231234     */
    232     private static function get_user_data_from_custom_post_type( $should_create_cpt = false, $post_status_filter = array( 'publish' ) ) {
     235    public static function get_user_data_from_custom_post_type( $theme, $should_create_cpt = false, $post_status_filter = array( 'publish' ) ) {
     236        if ( ! $theme instanceof WP_Theme ) {
     237            $theme = wp_get_theme();
     238        }
    233239        $user_cpt         = array();
    234240        $post_type_filter = 'wp_global_styles';
    235         $query            = new WP_Query(
    236             array(
    237                 'posts_per_page' => 1,
    238                 'orderby'        => 'date',
    239                 'order'          => 'desc',
    240                 'post_type'      => $post_type_filter,
    241                 'post_status'    => $post_status_filter,
    242                 'tax_query'      => array(
    243                     array(
    244                         'taxonomy' => 'wp_theme',
    245                         'field'    => 'name',
    246                         'terms'    => wp_get_theme()->get_stylesheet(),
    247                     ),
     241        $args             = array(
     242            'numberposts' => 1,
     243            'orderby'     => 'date',
     244            'order'       => 'desc',
     245            'post_type'   => $post_type_filter,
     246            'post_status' => $post_status_filter,
     247            'tax_query'   => array(
     248                array(
     249                    'taxonomy' => 'wp_theme',
     250                    'field'    => 'name',
     251                    'terms'    => $theme->get_stylesheet(),
    248252                ),
    249             )
     253            ),
    250254        );
    251255
    252         if ( is_array( $query->posts ) && ( 1 === $query->post_count ) ) {
    253             $user_cpt = $query->posts[0]->to_array();
     256        $cache_key = sprintf( 'wp_global_styles_%s', md5( serialize( $args ) ) );
     257        $post_id   = wp_cache_get( $cache_key );
     258
     259        if ( (int) $post_id > 0 ) {
     260            return get_post( $post_id, ARRAY_A );
     261        }
     262
     263        // Special case: '-1' is a results not found.
     264        if ( -1 === $post_id && ! $should_create_cpt ) {
     265            return $user_cpt;
     266        }
     267
     268        $recent_posts = wp_get_recent_posts( $args );
     269        if ( is_array( $recent_posts ) && ( count( $recent_posts ) === 1 ) ) {
     270            $user_cpt = $recent_posts[0];
    254271        } elseif ( $should_create_cpt ) {
    255272            $cpt_post_id = wp_insert_post(
     
    266283                true
    267284            );
    268 
    269             if ( is_wp_error( $cpt_post_id ) ) {
    270                 $user_cpt = array();
    271             } else {
    272                 $user_cpt = get_post( $cpt_post_id, ARRAY_A );
    273             }
    274         }
     285            $user_cpt    = get_post( $cpt_post_id, ARRAY_A );
     286        }
     287        $cache_expiration = $user_cpt ? DAY_IN_SECONDS : HOUR_IN_SECONDS;
     288        wp_cache_set( $cache_key, $user_cpt ? $user_cpt['ID'] : -1, '', $cache_expiration );
    275289
    276290        return $user_cpt;
     
    290304
    291305        $config   = array();
    292         $user_cpt = self::get_user_data_from_custom_post_type();
     306        $user_cpt = self::get_user_data_from_custom_post_type( wp_get_theme() );
    293307
    294308        if ( array_key_exists( 'post_content', $user_cpt ) ) {
     
    298312            if ( JSON_ERROR_NONE !== $json_decoding_error ) {
    299313                trigger_error( 'Error when decoding a theme.json schema for user data. ' . json_last_error_msg() );
    300                 return new WP_Theme_JSON( $config, 'user' );
     314                return new WP_Theme_JSON( $config, 'custom' );
    301315            }
    302316
     
    312326            }
    313327        }
    314         self::$user = new WP_Theme_JSON( $config, 'user' );
     328        self::$user = new WP_Theme_JSON( $config, 'custom' );
    315329
    316330        return self::$user;
     
    319333    /**
    320334     * There are three sources of data (origins) for a site:
    321      * default, theme, and user. The user's has higher priority
    322      * than the theme's, and the theme's higher than core's.
     335     * default, theme, and custom. The custom's has higher priority
     336     * than the theme's, and the theme's higher than default's.
    323337     *
    324338     * Unlike the getters {@link get_core_data},
     
    337351     *
    338352     * @param string $origin Optional. To what level should we merge data.
    339      *                       Valid values are 'theme' or 'user'.
    340      *                       Default is 'user'.
     353     *                       Valid values are 'theme' or 'custom'.
     354     *                       Default is 'custom'.
    341355     * @return WP_Theme_JSON
    342356     */
    343     public static function get_merged_data( $origin = 'user' ) {
     357    public static function get_merged_data( $origin = 'custom' ) {
    344358        if ( is_array( $origin ) ) {
    345359            _deprecated_argument( __FUNCTION__, '5.9' );
     
    350364        $result->merge( self::get_theme_data() );
    351365
    352         if ( 'user' === $origin ) {
     366        if ( 'custom' === $origin ) {
    353367            $result->merge( self::get_user_data() );
    354368        }
     
    370384        }
    371385
    372         $user_cpt = self::get_user_data_from_custom_post_type( true );
     386        $user_cpt = self::get_user_data_from_custom_post_type( wp_get_theme(), true );
    373387
    374388        if ( array_key_exists( 'ID', $user_cpt ) ) {
Note: See TracChangeset for help on using the changeset viewer.