Make WordPress Core


Ignore:
Timestamp:
06/21/2024 01:04:47 PM (11 months ago)
Author:
jorgefilipecosta
Message:

REST API: Add template and template_lock to post types endpoint.

Adds template and template_lock property of the post type to post types REST API endpoint.
This change allows us to fix a bug where the template of a page is not respected when creating a new page on the site editor.

Props jorgefilipecosta, oandregal, timothyblynjacobs, mukesh27.
Fixes #61477.

File:
1 edited

Legend:

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

    r56586 r58452  
    245245        if ( rest_is_field_included( 'rest_namespace', $fields ) ) {
    246246            $data['rest_namespace'] = $namespace;
     247        }
     248
     249        if ( rest_is_field_included( 'template', $fields ) ) {
     250            $data['template'] = $post_type->template ?? array();
     251        }
     252
     253        if ( rest_is_field_included( 'template_lock', $fields ) ) {
     254            $data['template_lock'] = ! empty( $post_type->template_lock ) ? $post_type->template_lock : false;
    247255        }
    248256
     
    408416                    'readonly'    => true,
    409417                ),
     418                'template'       => array(
     419                    'type'        => array( 'array' ),
     420                    'description' => __( 'The block template associated with the post type.' ),
     421                    'readonly'    => true,
     422                    'context'     => array( 'view', 'edit', 'embed' ),
     423                ),
     424                'template_lock'  => array(
     425                    'type'        => array( 'string', 'boolean' ),
     426                    'enum'        => array( 'all', 'insert', 'contentOnly', false ),
     427                    'description' => __( 'The template_lock associated with the post type, or false if none.' ),
     428                    'readonly'    => true,
     429                    'context'     => array( 'view', 'edit', 'embed' ),
     430                ),
    410431            ),
    411432        );
Note: See TracChangeset for help on using the changeset viewer.