Ticket #41411: 41411.2.diff
File 41411.2.diff, 2.8 KB (added by , 4 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php index 52bc9d2b0a..6783ea9808 100644
class WP_REST_Terms_Controller extends WP_REST_Controller { 468 468 return $fields_update; 469 469 } 470 470 471 $request->set_param( 'context', ' view' );471 $request->set_param( 'context', 'edit' ); 472 472 473 473 /** 474 474 * Fires after a single term is completely created or updated via the REST API. … … class WP_REST_Terms_Controller extends WP_REST_Controller { 570 570 return $fields_update; 571 571 } 572 572 573 $request->set_param( 'context', ' view' );573 $request->set_param( 'context', 'edit' ); 574 574 575 575 /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */ 576 576 do_action( "rest_after_insert_{$this->taxonomy}", $term, $request, false ); -
tests/phpunit/tests/rest-api/rest-tags-controller.php
diff --git tests/phpunit/tests/rest-api/rest-tags-controller.php tests/phpunit/tests/rest-api/rest-tags-controller.php index 96263c4061..ec17bc71e9 100644
class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { 1269 1269 $this->assertSame( $num_queries, $wpdb->num_queries ); 1270 1270 } 1271 1271 1272 /** 1273 * @ticket 41411 1274 */ 1275 public function test_editable_response_uses_edit_context() { 1276 wp_set_current_user( self::$administrator ); 1277 1278 $view_field = 'view_only_field'; 1279 $edit_field = 'edit_only_field'; 1280 1281 register_rest_field( 1282 'tag', 1283 $view_field, 1284 array( 1285 'context' => array( 'view' ), 1286 'get_callback' => '__return_empty_string', 1287 ) 1288 ); 1289 1290 register_rest_field( 1291 'tag', 1292 $edit_field, 1293 array( 1294 'context' => array( 'edit' ), 1295 'get_callback' => '__return_empty_string', 1296 ) 1297 ); 1298 1299 $create = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 1300 $create->set_param( 'name', 'My New Term' ); 1301 $response = rest_get_server()->dispatch( $create ); 1302 $this->assertEquals( 201, $response->get_status() ); 1303 $data = $response->get_data(); 1304 $this->assertArrayHasKey( $edit_field, $data ); 1305 $this->assertArrayNotHasKey( $view_field, $data ); 1306 1307 $update = new WP_REST_Request( 'PUT', '/wp/v2/tags/' . $data['id'] ); 1308 $update->set_param( 'name', 'My Awesome New Term' ); 1309 $response = rest_get_server()->dispatch( $update ); 1310 $this->assertEquals( 200, $response->get_status() ); 1311 $data = $response->get_data(); 1312 $this->assertArrayHasKey( $edit_field, $data ); 1313 $this->assertArrayNotHasKey( $view_field, $data ); 1314 } 1315 1272 1316 public function additional_field_get_callback( $object, $request ) { 1273 1317 return 123; 1274 1318 }