[wp-trac] [WordPress Trac] #39996: Allow passing existing template value for posts, even when template does not exist

WordPress Trac noreply at wordpress.org
Tue Oct 3 04:15:11 UTC 2017


#39996: Allow passing existing template value for posts, even when template does
not exist
--------------------------------------+-----------------------
 Reporter:  danielbachhuber           |       Owner:  jnylen0
     Type:  defect (bug)              |      Status:  assigned
 Priority:  normal                    |   Milestone:  4.9
Component:  REST API                  |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-----------------------
Changes (by TimothyBlynJacobs):

 * keywords:  needs-patch needs-unit-tests => has-patch has-unit-tests


Comment:

 Attached a patch to use `validate_callback` as suggested.

 I also had to account for the built in validation that `wp_insert_post()`
 performs for the page template. When updating the post, the original
 template value gets merged into the update data. This means that even if
 the page template was validated accounting for updating to the same value,
 internal validation would prevent it from being saved.

 To account for this, I set `page_template` to null so that template
 handling will be bypassed in `wp_insert_post`.

 Since the template is now validated at request time, I removed the extra
 validation in `::handle_template()` by default. However, I kept it when
 performing a create request because the filter on the templates can be
 contextual based on the new post object and we don't have the new post ID
 when validating at request time. It might be worth returning an error in
 this case as well, similar to updating terms, or meta, etc...

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39996#comment:19>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list