Make WordPress Core


Ignore:
Timestamp:
09/20/2022 09:19:10 PM (2 years ago)
Author:
hellofromTonya
Message:

Editor: Adds template types, is_wp_suggestion, and fallback template content.

This commit improves site editor templates by:

  • Adds a post meta is_wp_suggestion to templates created from the site editor.

Why? To differentiate the templates created from the post editor in the Template panel in inspector controls and the templates suggested in site editor.

See Gutenberg PR 41387 for more details.

  • Expands the template types that can be added to the site editor to include single custom post type and specific posts templates.

See Gutenberg PR 41189 for more details.

  • Adds fallback template content on creation in site editor:
    • Introduces get_template_hierarchy() to get the template hierarchy for a given template slug to be created.
    • Adds a lookup route to WP_REST_Templates_Controller to get the fallback template content.

See Gutenberg PR 42520 for more details.

  • Fixes a typo in default category template's description within get_default_block_template_types().

See Gutenberg PR 42586 for more details.

  • Changes field checks from in_array() to rest_is_field_included() in WP_REST_Post_Types_Controller.
  • Adds an icon field to WP_REST_Post_Types_Controller

Follow-up to [53129], [52331], [52275], [52062], [51962], [43087].

Props ntsekouras, spacedmonkey, mamaduka, mburridge, jameskoster, bernhard-reiter, mcsf, hellofromTonya.
See #56467.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php

    r53760 r54269  
    187187        $data   = array();
    188188
    189         if ( in_array( 'capabilities', $fields, true ) ) {
     189        if ( rest_is_field_included( 'capabilities', $fields ) ) {
    190190            $data['capabilities'] = $post_type->cap;
    191191        }
    192192
    193         if ( in_array( 'description', $fields, true ) ) {
     193        if ( rest_is_field_included( 'description', $fields ) ) {
    194194            $data['description'] = $post_type->description;
    195195        }
    196196
    197         if ( in_array( 'hierarchical', $fields, true ) ) {
     197        if ( rest_is_field_included( 'hierarchical', $fields ) ) {
    198198            $data['hierarchical'] = $post_type->hierarchical;
    199199        }
    200200
    201         if ( in_array( 'visibility', $fields, true ) ) {
     201        if ( rest_is_field_included( 'visibility', $fields ) ) {
    202202            $data['visibility'] = array(
    203203                'show_in_nav_menus' => (bool) $post_type->show_in_nav_menus,
     
    206206        }
    207207
    208         if ( in_array( 'viewable', $fields, true ) ) {
     208        if ( rest_is_field_included( 'viewable', $fields ) ) {
    209209            $data['viewable'] = is_post_type_viewable( $post_type );
    210210        }
    211211
    212         if ( in_array( 'labels', $fields, true ) ) {
     212        if ( rest_is_field_included( 'labels', $fields ) ) {
    213213            $data['labels'] = $post_type->labels;
    214214        }
    215215
    216         if ( in_array( 'name', $fields, true ) ) {
     216        if ( rest_is_field_included( 'name', $fields ) ) {
    217217            $data['name'] = $post_type->label;
    218218        }
    219219
    220         if ( in_array( 'slug', $fields, true ) ) {
     220        if ( rest_is_field_included( 'slug', $fields ) ) {
    221221            $data['slug'] = $post_type->name;
    222222        }
    223223
    224         if ( in_array( 'supports', $fields, true ) ) {
     224        if ( rest_is_field_included( 'icon', $fields ) ) {
     225            $data['icon'] = $post_type->menu_icon;
     226        }
     227
     228        if ( rest_is_field_included( 'supports', $fields ) ) {
    225229            $data['supports'] = $supports;
    226230        }
    227231
    228         if ( in_array( 'taxonomies', $fields, true ) ) {
     232        if ( rest_is_field_included( 'taxonomies', $fields ) ) {
    229233            $data['taxonomies'] = array_values( $taxonomies );
    230234        }
    231235
    232         if ( in_array( 'rest_base', $fields, true ) ) {
     236        if ( rest_is_field_included( 'rest_base', $fields ) ) {
    233237            $data['rest_base'] = $base;
    234238        }
    235239
    236         if ( in_array( 'rest_namespace', $fields, true ) ) {
     240        if ( rest_is_field_included( 'rest_namespace', $fields ) ) {
    237241            $data['rest_namespace'] = $namespace;
    238242        }
     
    288292     * @since 4.8.0 The `supports` property was added.
    289293     * @since 5.9.0 The `visibility` and `rest_namespace` properties were added.
     294     * @since 6.1.0 The `icon` property was added.
    290295     *
    291296     * @return array Item schema data.
     
    386391                    ),
    387392                ),
     393                'icon'           => array(
     394                    'description' => __( 'The icon for the post type.' ),
     395                    'type'        => array( 'string', 'null' ),
     396                    'context'     => array( 'view', 'edit', 'embed' ),
     397                    'readonly'    => true,
     398                ),
    388399            ),
    389400        );
Note: See TracChangeset for help on using the changeset viewer.