diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index c313784..f19fa17 100644
|
|
class WP_REST_Posts_Controller extends WP_REST_Controller { |
2002 | 2002 | ); |
2003 | 2003 | } |
2004 | 2004 | |
2005 | | if ( 'page' === $this->post_type ) { |
2006 | | $schema['properties']['template'] = array( |
2007 | | 'description' => __( 'The theme file to use to display the object.' ), |
2008 | | 'type' => 'string', |
2009 | | 'enum' => array_keys( wp_get_theme()->get_page_templates() ), |
2010 | | 'context' => array( 'view', 'edit' ), |
2011 | | ); |
2012 | | } |
| 2005 | $schema['properties']['template'] = array( |
| 2006 | 'description' => __( 'The theme file to use to display the object.' ), |
| 2007 | 'type' => 'string', |
| 2008 | 'enum' => array_keys( wp_get_theme()->get_page_templates( null, $this->post_type ) ), |
| 2009 | 'context' => array( 'view', 'edit' ), |
| 2010 | ); |
2013 | 2011 | |
2014 | 2012 | $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); |
2015 | 2013 | foreach ( $taxonomies as $taxonomy ) { |
diff --git tests/phpunit/tests/rest-api/rest-posts-controller.php tests/phpunit/tests/rest-api/rest-posts-controller.php
index cdd5ec0..fab605b 100644
|
|
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
56 | 56 | public function setUp() { |
57 | 57 | parent::setUp(); |
58 | 58 | register_post_type( 'youseeme', array( 'supports' => array(), 'show_in_rest' => true ) ); |
| 59 | add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) ); |
59 | 60 | } |
60 | 61 | |
61 | 62 | public function test_register_routes() { |
… |
… |
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
1016 | 1017 | $this->check_create_post_response( $response ); |
1017 | 1018 | } |
1018 | 1019 | |
| 1020 | public function test_create_item_with_template() { |
| 1021 | wp_set_current_user( self::$editor_id ); |
| 1022 | |
| 1023 | $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); |
| 1024 | $params = $this->set_post_data( array( |
| 1025 | 'template' => 'post-my-test-template.php', |
| 1026 | ) ); |
| 1027 | $request->set_body_params( $params ); |
| 1028 | $response = $this->server->dispatch( $request ); |
| 1029 | |
| 1030 | $data = $response->get_data(); |
| 1031 | $new_post = get_post( $data['id'] ); |
| 1032 | $this->assertEquals( 'post-my-test-template.php', $data['template'] ); |
| 1033 | $this->assertEquals( 'post-my-test-template.php', get_page_template_slug( $new_post->ID ) ); |
| 1034 | } |
| 1035 | |
1019 | 1036 | public function test_rest_create_item() { |
1020 | 1037 | wp_set_current_user( self::$editor_id ); |
1021 | 1038 | |
… |
… |
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
2224 | 2241 | if ( isset( $this->attachment_id ) ) { |
2225 | 2242 | $this->remove_added_uploads(); |
2226 | 2243 | } |
| 2244 | remove_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) ); |
2227 | 2245 | parent::tearDown(); |
2228 | 2246 | } |
2229 | 2247 | |
… |
… |
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
2238 | 2256 | return $query; |
2239 | 2257 | } |
2240 | 2258 | |
| 2259 | public function filter_theme_post_templates( $post_templates ) { |
| 2260 | return array( |
| 2261 | 'post-my-test-template.php' => 'My Test Template', |
| 2262 | ); |
| 2263 | |
| 2264 | return $post_templates; |
| 2265 | } |
2241 | 2266 | } |