mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user