diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index e0cdc79..d3c9b24 100644
a
|
b
|
class WP_REST_Posts_Controller extends WP_REST_Controller { |
77 | 77 | 'schema' => array( $this, 'get_public_item_schema' ), |
78 | 78 | ) ); |
79 | 79 | |
| 80 | $schema = $this->get_item_schema(); |
| 81 | $get_item_args = array( |
| 82 | 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
| 83 | ); |
| 84 | if ( isset( $schema['properties']['password'] ) ) { |
| 85 | $get_item_args['password'] = array( |
| 86 | 'description' => __( 'The password for the post if it is password protected.' ), |
| 87 | 'type' => 'string', |
| 88 | ); |
| 89 | } |
80 | 90 | register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
81 | 91 | array( |
82 | 92 | 'methods' => WP_REST_Server::READABLE, |
83 | 93 | 'callback' => array( $this, 'get_item' ), |
84 | 94 | 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
85 | | 'args' => array( |
86 | | 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
87 | | 'password' => array( |
88 | | 'description' => __( 'The password for the post if it is password protected.' ), |
89 | | 'type' => 'string', |
90 | | ), |
91 | | ), |
| 95 | 'args' => $get_item_args, |
92 | 96 | ), |
93 | 97 | array( |
94 | 98 | 'methods' => WP_REST_Server::EDITABLE, |
diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php
index 0de092d..a651a76 100644
a
|
b
|
class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control |
172 | 172 | $this->assertEqualSets( $media_types, $data['endpoints'][0]['args']['media_type']['enum'] ); |
173 | 173 | } |
174 | 174 | |
| 175 | public function test_registered_get_item_params() { |
| 176 | $id1 = $this->factory->attachment->create_object( $this->test_file, 0, array( |
| 177 | 'post_mime_type' => 'image/jpeg', |
| 178 | 'post_excerpt' => 'A sample caption', |
| 179 | ) ); |
| 180 | $request = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/media/%d', $id1 ) ); |
| 181 | $response = $this->server->dispatch( $request ); |
| 182 | $data = $response->get_data(); |
| 183 | $keys = array_keys( $data['endpoints'][0]['args'] ); |
| 184 | sort( $keys ); |
| 185 | $this->assertEquals( array( 'context' ), $keys ); |
| 186 | } |
| 187 | |
175 | 188 | public function test_get_items() { |
176 | 189 | wp_set_current_user( 0 ); |
177 | 190 | $id1 = $this->factory->attachment->create_object( $this->test_file, 0, array( |
diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php
index 70db2e2..328aa65 100644
a
|
b
|
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
121 | 121 | ), $keys ); |
122 | 122 | } |
123 | 123 | |
| 124 | public function test_registered_get_item_params() { |
| 125 | $request = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); |
| 126 | $response = $this->server->dispatch( $request ); |
| 127 | $data = $response->get_data(); |
| 128 | $keys = array_keys( $data['endpoints'][0]['args'] ); |
| 129 | sort( $keys ); |
| 130 | $this->assertEquals( array( 'context', 'password' ), $keys ); |
| 131 | } |
| 132 | |
124 | 133 | public function test_get_items() { |
125 | 134 | $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); |
126 | 135 | $response = $this->server->dispatch( $request ); |