Changeset 52068
- Timestamp:
- 11/09/2021 01:57:48 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/class-wp-rest-server.php
r51962 r52068 1404 1404 ); 1405 1405 1406 $allow_batch = false; 1407 1406 1408 if ( isset( $this->route_options[ $route ] ) ) { 1407 1409 $options = $this->route_options[ $route ]; … … 1410 1412 $data['namespace'] = $options['namespace']; 1411 1413 } 1414 1415 $allow_batch = isset( $options['allow_batch'] ) ? $options['allow_batch'] : false; 1412 1416 1413 1417 if ( isset( $options['schema'] ) && 'help' === $context ) { … … 1430 1434 'methods' => array_keys( $callback['methods'] ), 1431 1435 ); 1436 1437 $callback_batch = isset( $callback['allow_batch'] ) ? $callback['allow_batch'] : $allow_batch; 1438 1439 if ( $callback_batch ) { 1440 $endpoint_data['allow_batch'] = $callback_batch; 1441 } 1432 1442 1433 1443 if ( isset( $callback['args'] ) ) { -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
r51786 r52068 16 16 */ 17 17 class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { 18 19 /** 20 * Whether the controller supports batching. 21 * 22 * @since 5.9.0 23 * @var false 24 */ 25 protected $allow_batch = false; 18 26 19 27 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r51964 r52068 39 39 */ 40 40 protected $password_check_passed = array(); 41 42 /** 43 * Whether the controller supports batching. 44 * 45 * @since 5.9.0 46 * @var array 47 */ 48 protected $allow_batch = array( 'v1' => true ); 41 49 42 50 /** … … 81 89 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), 82 90 ), 83 'schema' => array( $this, 'get_public_item_schema' ), 91 'allow_batch' => $this->allow_batch, 92 'schema' => array( $this, 'get_public_item_schema' ), 84 93 ) 85 94 ); … … 99 108 '/' . $this->rest_base . '/(?P<id>[\d]+)', 100 109 array( 101 'args' => array(110 'args' => array( 102 111 'id' => array( 103 112 'description' => __( 'Unique identifier for the post.' ), … … 129 138 ), 130 139 ), 131 'schema' => array( $this, 'get_public_item_schema' ), 140 'allow_batch' => $this->allow_batch, 141 'schema' => array( $this, 'get_public_item_schema' ), 132 142 ) 133 143 ); -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
r51964 r52068 48 48 */ 49 49 protected $total_terms; 50 51 /** 52 * Whether the controller supports batching. 53 * 54 * @since 5.9.0 55 * @var array 56 */ 57 protected $allow_batch = array( 'v1' => true ); 50 58 51 59 /** … … 90 98 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), 91 99 ), 92 'schema' => array( $this, 'get_public_item_schema' ), 100 'allow_batch' => $this->allow_batch, 101 'schema' => array( $this, 'get_public_item_schema' ), 93 102 ) 94 103 ); … … 98 107 '/' . $this->rest_base . '/(?P<id>[\d]+)', 99 108 array( 100 'args' => array(109 'args' => array( 101 110 'id' => array( 102 111 'description' => __( 'Unique identifier for the term.' ), … … 130 139 ), 131 140 ), 132 'schema' => array( $this, 'get_public_item_schema' ), 141 'allow_batch' => $this->allow_batch, 142 'schema' => array( $this, 'get_public_item_schema' ), 133 143 ) 134 144 ); -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php
r52016 r52068 24 24 */ 25 25 protected $widgets_retrieved = false; 26 27 /** 28 * Whether the controller supports batching. 29 * 30 * @since 5.9.0 31 * @var array 32 */ 33 protected $allow_batch = array( 'v1' => true ); 26 34 27 35 /** … … 57 65 'args' => $this->get_endpoint_args_for_item_schema(), 58 66 ), 59 'allow_batch' => array( 'v1' => true ),67 'allow_batch' => $this->allow_batch, 60 68 'schema' => array( $this, 'get_public_item_schema' ), 61 69 ) … … 91 99 ), 92 100 ), 93 'allow_batch' => array( 'v1' => true ),101 'allow_batch' => $this->allow_batch, 94 102 'schema' => array( $this, 'get_public_item_schema' ), 95 103 ) -
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r51568 r52068 161 161 $response = rest_get_server()->dispatch( $request ); 162 162 $data = $response->get_data(); 163 $this->assertArrayNotHasKey( 'allow_batch', $data['endpoints'][0] ); 163 164 $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] ); 164 165 $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); … … 175 176 $response = rest_get_server()->dispatch( $request ); 176 177 $data = $response->get_data(); 178 $this->assertArrayNotHasKey( 'allow_batch', $data['endpoints'][0] ); 177 179 $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] ); 178 180 $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); -
trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php
r51568 r52068 118 118 $response = rest_get_server()->dispatch( $request ); 119 119 $data = $response->get_data(); 120 $this->assertSame( array( 'v1' => true ), $data['endpoints'][0]['allow_batch'] ); 120 121 $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] ); 121 122 $this->assertSameSets( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); … … 125 126 $response = rest_get_server()->dispatch( $request ); 126 127 $data = $response->get_data(); 128 $this->assertSame( array( 'v1' => true ), $data['endpoints'][0]['allow_batch'] ); 127 129 $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] ); 128 130 $this->assertSameSets( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); -
trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php
r51568 r52068 65 65 $response = rest_get_server()->dispatch( $request ); 66 66 $data = $response->get_data(); 67 $keys = array_keys( $data['endpoints'][0]['args'] ); 67 $this->assertSame( array( 'v1' => true ), $data['endpoints'][0]['allow_batch'] ); 68 $keys = array_keys( $data['endpoints'][0]['args'] ); 68 69 sort( $keys ); 69 70 $this->assertSame( -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r51657 r52068 155 155 $response = rest_get_server()->dispatch( $request ); 156 156 $data = $response->get_data(); 157 $this->assertSame( array( 'v1' => true ), $data['endpoints'][0]['allow_batch'] ); 157 158 $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] ); 158 159 $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); … … 161 162 $response = rest_get_server()->dispatch( $request ); 162 163 $data = $response->get_data(); 164 $this->assertSame( array( 'v1' => true ), $data['endpoints'][0]['allow_batch'] ); 163 165 $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] ); 164 166 $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); -
trunk/tests/phpunit/tests/rest-api/rest-server.php
r51960 r52068 369 369 $sent_headers = $result->get_headers(); 370 370 $this->assertSame( $sent_headers['Allow'], 'POST' ); 371 } 372 373 /** 374 * @ticket 53063 375 */ 376 public function test_batched_options() { 377 register_rest_route( 378 'test-ns', 379 '/test', 380 array( 381 array( 382 'methods' => array( 'GET' ), 383 'callback' => '__return_null', 384 'permission_callback' => '__return_true', 385 ), 386 array( 387 'methods' => array( 'POST' ), 388 'callback' => '__return_null', 389 'permission_callback' => '__return_null', 390 'allow_batch' => false, 391 ), 392 'allow_batch' => array( 'v1' => true ), 393 ) 394 ); 395 396 $request = new WP_REST_Request( 'OPTIONS', '/test-ns/test' ); 397 $response = rest_get_server()->dispatch( $request ); 398 399 $data = $response->get_data(); 400 401 $this->assertSame( array( 'v1' => true ), $data['endpoints'][0]['allow_batch'] ); 402 $this->assertArrayNotHasKey( 'allow_batch', $data['endpoints'][1] ); 371 403 } 372 404 -
trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php
r51568 r52068 136 136 $response = rest_get_server()->dispatch( $request ); 137 137 $data = $response->get_data(); 138 $this->assertSame( array( 'v1' => true ), $data['endpoints'][0]['allow_batch'] ); 138 139 $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] ); 139 140 $this->assertSameSets( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); … … 143 144 $response = rest_get_server()->dispatch( $request ); 144 145 $data = $response->get_data(); 146 $this->assertSame( array( 'v1' => true ), $data['endpoints'][0]['allow_batch'] ); 145 147 $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] ); 146 148 $this->assertSameSets( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); -
trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php
r52031 r52068 1524 1524 $properties = $data['schema']['properties']; 1525 1525 1526 $this->assertSame( array( 'v1' => true ), $data['endpoints'][0]['allow_batch'] ); 1527 1526 1528 $this->assertCount( 7, $properties ); 1527 1529 $this->assertArrayHasKey( 'id', $properties ); -
trunk/tests/qunit/fixtures/wp-api-generated.js
r52062 r52068 262 262 "GET" 263 263 ], 264 "allow_batch": { 265 "v1": true 266 }, 264 267 "args": { 265 268 "context": { … … 603 606 "POST" 604 607 ], 608 "allow_batch": { 609 "v1": true 610 }, 605 611 "args": { 606 612 "date": { … … 841 847 "GET" 842 848 ], 849 "allow_batch": { 850 "v1": true 851 }, 843 852 "args": { 844 853 "id": { … … 871 880 "PATCH" 872 881 ], 882 "allow_batch": { 883 "v1": true 884 }, 873 885 "args": { 874 886 "id": { … … 1099 1111 "DELETE" 1100 1112 ], 1113 "allow_batch": { 1114 "v1": true 1115 }, 1101 1116 "args": { 1102 1117 "id": { … … 1580 1595 "GET" 1581 1596 ], 1597 "allow_batch": { 1598 "v1": true 1599 }, 1582 1600 "args": { 1583 1601 "context": { … … 1767 1785 "POST" 1768 1786 ], 1787 "allow_batch": { 1788 "v1": true 1789 }, 1769 1790 "args": { 1770 1791 "date": { … … 1977 1998 "GET" 1978 1999 ], 2000 "allow_batch": { 2001 "v1": true 2002 }, 1979 2003 "args": { 1980 2004 "id": { … … 2007 2031 "PATCH" 2008 2032 ], 2033 "allow_batch": { 2034 "v1": true 2035 }, 2009 2036 "args": { 2010 2037 "id": { … … 2207 2234 "DELETE" 2208 2235 ], 2236 "allow_batch": { 2237 "v1": true 2238 }, 2209 2239 "args": { 2210 2240 "id": { … … 3397 3427 "GET" 3398 3428 ], 3429 "allow_batch": { 3430 "v1": true 3431 }, 3399 3432 "args": { 3400 3433 "context": { … … 3542 3575 "POST" 3543 3576 ], 3577 "allow_batch": { 3578 "v1": true 3579 }, 3544 3580 "args": { 3545 3581 "date": { … … 3657 3693 "GET" 3658 3694 ], 3695 "allow_batch": { 3696 "v1": true 3697 }, 3659 3698 "args": { 3660 3699 "id": { … … 3687 3726 "PATCH" 3688 3727 ], 3728 "allow_batch": { 3729 "v1": true 3730 }, 3689 3731 "args": { 3690 3732 "id": { … … 3792 3834 "DELETE" 3793 3835 ], 3836 "allow_batch": { 3837 "v1": true 3838 }, 3794 3839 "args": { 3795 3840 "id": { … … 4607 4652 "GET" 4608 4653 ], 4654 "allow_batch": { 4655 "v1": true 4656 }, 4609 4657 "args": { 4610 4658 "context": { … … 5371 5419 "POST" 5372 5420 ], 5421 "allow_batch": { 5422 "v1": true 5423 }, 5373 5424 "args": { 5374 5425 "description": { … … 5419 5470 "GET" 5420 5471 ], 5472 "allow_batch": { 5473 "v1": true 5474 }, 5421 5475 "args": { 5422 5476 "id": { … … 5444 5498 "PATCH" 5445 5499 ], 5500 "allow_batch": { 5501 "v1": true 5502 }, 5446 5503 "args": { 5447 5504 "id": { … … 5482 5539 "DELETE" 5483 5540 ], 5541 "allow_batch": { 5542 "v1": true 5543 }, 5484 5544 "args": { 5485 5545 "id": { … … 5509 5569 "GET" 5510 5570 ], 5571 "allow_batch": { 5572 "v1": true 5573 }, 5511 5574 "args": { 5512 5575 "context": { … … 5616 5679 "POST" 5617 5680 ], 5681 "allow_batch": { 5682 "v1": true 5683 }, 5618 5684 "args": { 5619 5685 "description": { … … 5659 5725 "GET" 5660 5726 ], 5727 "allow_batch": { 5728 "v1": true 5729 }, 5661 5730 "args": { 5662 5731 "id": { … … 5684 5753 "PATCH" 5685 5754 ], 5755 "allow_batch": { 5756 "v1": true 5757 }, 5686 5758 "args": { 5687 5759 "id": { … … 5717 5789 "DELETE" 5718 5790 ], 5791 "allow_batch": { 5792 "v1": true 5793 }, 5719 5794 "args": { 5720 5795 "id": { … … 7665 7740 "GET" 7666 7741 ], 7742 "allow_batch": { 7743 "v1": true 7744 }, 7667 7745 "args": { 7668 7746 "context": { … … 7688 7766 "POST" 7689 7767 ], 7768 "allow_batch": { 7769 "v1": true 7770 }, 7690 7771 "args": { 7691 7772 "id": { … … 7763 7844 "GET" 7764 7845 ], 7846 "allow_batch": { 7847 "v1": true 7848 }, 7765 7849 "args": { 7766 7850 "context": { … … 7783 7867 "PATCH" 7784 7868 ], 7869 "allow_batch": { 7870 "v1": true 7871 }, 7785 7872 "args": { 7786 7873 "id": { … … 7838 7925 "DELETE" 7839 7926 ], 7927 "allow_batch": { 7928 "v1": true 7929 }, 7840 7930 "args": { 7841 7931 "force": {
Note: See TracChangeset
for help on using the changeset viewer.