Make WordPress Core


Ignore:
Timestamp:
10/23/2017 10:10:48 PM (7 years ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r41760 r41979  
    26682668    }
    26692669
     2670    /**
     2671     * Test update_item() with same template that no longer exists.
     2672     *
     2673     * @covers WP_REST_Posts_Controller::check_template()
     2674     * @ticket 39996
     2675     */
     2676    public function test_update_item_with_same_template_that_no_longer_exists() {
     2677
     2678        wp_set_current_user( self::$editor_id );
     2679
     2680        update_post_meta( self::$post_id, '_wp_page_template', 'post-my-invalid-template.php' );
     2681
     2682        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     2683        $params = $this->set_post_data( array(
     2684            'template' => 'post-my-invalid-template.php',
     2685        ) );
     2686        $request->set_body_params( $params );
     2687        $response = $this->server->dispatch( $request );
     2688
     2689        $this->assertEquals( 200, $response->get_status() );
     2690
     2691        $data = $response->get_data();
     2692        $post_template = get_page_template_slug( get_post( $data['id'] ) );
     2693
     2694        $this->assertEquals( 'post-my-invalid-template.php', $post_template );
     2695        $this->assertEquals( 'post-my-invalid-template.php', $data['template'] );
     2696    }
    26702697
    26712698    public function verify_post_roundtrip( $input = array(), $expected_output = array() ) {
Note: See TracChangeset for help on using the changeset viewer.