Make WordPress Core


Ignore:
Timestamp:
11/30/2021 12:22:30 AM (5 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/rest-api/endpoints/class-wp-rest-templates-controller.php

    r52268 r52275  
    7373                                'args'   => array(
    7474                                        'id' => array(
    75                                                 'description' => __( 'The id of a template' ),
    76                                                 'type'        => 'string',
     75                                                'description'       => __( 'The id of a template' ),
     76                                                'type'              => 'string',
     77                                                'sanitize_callback' => array( $this, '_sanitize_template_id' ),
    7778                                        ),
    7879                                ),
    … …  
    133134
    134135        /**
     136         * Requesting this endpoint for a template like 'twentytwentytwo//home'
     137         * requires using a path like /wp/v2/templates/twentytwentytwo//home. There
     138         * are special cases when WordPress routing corrects the name to contain
     139         * only a single slash like 'twentytwentytwo/home'.
     140         *
     141         * This method doubles the last slash if it's not already doubled. It relies
     142         * on the template ID format {theme_name}//{template_slug} and the fact that
     143         * slugs cannot contain slashes.
     144         *
     145         * @since 5.9.0
     146         * @see https://core.trac.wordpress.org/ticket/54507
     147         *
     148         * @param string $id Template ID.
     149         * @return string Sanitized template ID.
     150         */
     151        public function _sanitize_template_id( $id ) {
     152                $last_slash_pos = strrpos( $id, '/' );
     153                if ( false === $last_slash_pos ) {
     154                        return $id;
     155                }
     156
     157                $is_double_slashed = substr( $id, $last_slash_pos - 1, 1 ) === '/';
     158                if ( $is_double_slashed ) {
     159                        return $id;
     160                }
     161                return (
     162                        substr( $id, 0, $last_slash_pos )
     163                        . '/'
     164                        . substr( $id, $last_slash_pos )
     165                );
     166        }
     167
     168        /**
    135169         * Checks if a given request has access to read templates.
    136170         *
    … …  
    244278
    245279                $changes = $this->prepare_item_for_database( $request );
     280
     281                if ( is_wp_error( $changes ) ) {
     282                        return $changes;
     283                }
    246284
    247285                if ( 'custom' === $template->source ) {
    … …  
    299337        public function create_item( $request ) {
    300338                $prepared_post            = $this->prepare_item_for_database( $request );
     339
     340                if ( is_wp_error( $prepared_post ) ) {
     341                        return $prepared_post;
     342                }
     343
    301344                $prepared_post->post_name = $request['slug'];
    302345                $post_id                  = wp_insert_post( wp_slash( (array) $prepared_post ), true );
    … …  
    431474                                'wp_theme' => $template->theme,
    432475                        );
     476                        $changes->meta_input  = array(
     477                                'origin' => $template->source,
     478                        );
    433479                } else {
    434480                        $changes->post_name   = $template->slug;
    … …  
    470516                }
    471517
     518                if ( ! empty( $request['author'] ) ) {
     519                        $post_author = (int) $request['author'];
     520
     521                        if ( get_current_user_id() !== $post_author ) {
     522                                $user_obj = get_userdata( $post_author );
     523
     524                                if ( ! $user_obj ) {
     525                                        return new WP_Error(
     526                                                'rest_invalid_author',
     527                                                __( 'Invalid author ID.' ),
     528                                                array( 'status' => 400 )
     529                                        );
     530                                }
     531                        }
     532
     533                        $changes->post_author = $post_author;
     534                }
     535
    472536                return $changes;
    473537        }
    … …  
    517581                if ( rest_is_field_included( 'source', $fields ) ) {
    518582                        $data['source'] = $template->source;
     583                }
     584
     585                if ( rest_is_field_included( 'origin', $fields ) ) {
     586                        $data['origin'] = $template->origin;
    519587                }
    520588
    … …  
    554622                if ( rest_is_field_included( 'has_theme_file', $fields ) ) {
    555623                        $data['has_theme_file'] = (bool) $template->has_theme_file;
     624                }
     625
     626                if ( rest_is_field_included( 'is_custom', $fields ) && 'wp_template' === $template->type ) {
     627                        $data['is_custom'] = $template->is_custom;
     628                }
     629
     630                if ( rest_is_field_included( 'author', $fields ) ) {
     631                        $data['author'] = (int) $template->author;
    556632                }
    557633
    … …  
    704780                                        'readonly'    => true,
    705781                                ),
     782                                'origin'         => array(
     783                                        'description' => __( 'Source of a customized template' ),
     784                                        'type'        => 'string',
     785                                        'context'     => array( 'embed', 'view', 'edit' ),
     786                                        'readonly'    => true,
     787                                ),
    706788                                'content'        => array(
    707789                                        'description' => __( 'Content of template.' ),
    … …  
    767849                                        'readonly'    => true,
    768850                                ),
     851                                'author' => array(
     852                                        'description' => __( 'The ID for the author of the template.' ),
     853                                        'type'        => 'integer',
     854                                        'context'     => array( 'view', 'edit', 'embed' ),
     855                                ),
    769856                        ),
    770857                );
     858
     859                if ( 'wp_template' === $this->post_type ) {
     860                        $schema['properties']['is_custom'] = array(
     861                                'description' => __( 'Whether a template is a custom template.' ),
     862                                'type'        => 'bool',
     863                                'context'     => array( 'embed', 'view', 'edit' ),
     864                                'readonly'    => true,
     865                        );
     866                }
    771867
    772868                if ( 'wp_template_part' === $this->post_type ) {
Note: See TracChangeset for help on using the changeset viewer.