REST API: Allow passing existing template value for posts even when template no longer exists.

Also remove `enum` for validating allowed templates to allow plugins to dynamically supply their own templates for specific posts, even when they are not in the theme.

Props TimothyBlynJacobs, jnylen0, swissspidy.
Fixes #39996.


git-svn-id: https://develop.svn.wordpress.org/trunk@41979 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter
2017-10-23 22:10:48 +00:00
parent 074009ecdb
commit a0910276f1
2 changed files with 81 additions and 7 deletions

View File

@@ -2667,6 +2667,33 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
$this->assertEquals( '', $post_template );
}
/**
* Test update_item() with same template that no longer exists.
*
* @covers WP_REST_Posts_Controller::check_template()
* @ticket 39996
*/
public function test_update_item_with_same_template_that_no_longer_exists() {
wp_set_current_user( self::$editor_id );
update_post_meta( self::$post_id, '_wp_page_template', 'post-my-invalid-template.php' );
$request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
$params = $this->set_post_data( array(
'template' => 'post-my-invalid-template.php',
) );
$request->set_body_params( $params );
$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
$data = $response->get_data();
$post_template = get_page_template_slug( get_post( $data['id'] ) );
$this->assertEquals( 'post-my-invalid-template.php', $post_template );
$this->assertEquals( 'post-my-invalid-template.php', $data['template'] );
}
public function verify_post_roundtrip( $input = array(), $expected_output = array() ) {
// Create the post