[wp-trac] [WordPress Trac] #38877: REST API - Unable to update page when default template used.

WordPress Trac noreply at wordpress.org
Sun Nov 20 11:31:39 UTC 2016


#38877: REST API - Unable to update page when default template used.
--------------------------+-----------------------------
 Reporter:  lucasstark    |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:  rest-api      |
--------------------------+-----------------------------
 Sending a request to update a page with the template property set to an
 empty string results in an Invalid Rest Request Parameter.

 The reason this occurs is because the schema property for template is
 configured as an enum of the theme page templates.

 {{{#!php
 <?php
 $schema['properties']['template'] = array(
                         'description' => __( 'The theme file to use to
 display the object.' ),
                         'type'        => 'string',
                         'enum'        => array_keys(
 wp_get_theme()->get_page_templates( null, $this->post_type ) ),
                         'context'     => array( 'view', 'edit' ),
                 );
 }}}

 When validation occurs against the template property it will fail if the
 template is the default, which is an empty string.

 An example to reproduce, use the Javascript Client Library and do
 something like the following.   This assumes the page you fetch is using
 the default template, which will be an empty string.

 {{{
 var page = new wp.api.models.Page( { id : 1 } );
 page.fetch().done(function() {
       page.set('title', 'Testing');
       page.save();
 });
 }}}

 This fails since the template property on the model is empty, therefore
 schema param validation fails when the template property is compared
 against the enumerated values for the themes page templates.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38877>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list