Ticket #45265: 45265.3.diff
File 45265.3.diff, 3.7 KB (added by , 6 years ago) |
---|
-
src/wp-includes/rest-api.php
17 17 /** 18 18 * Registers a REST API route. 19 19 * 20 * Note: Do not use before the {@see 'rest_api_init'} hook. 21 * 20 22 * @since 4.4.0 23 * @since 5.1.0 Added a _doing_it_wrong() notice when not called on the rest_api_init hook. 21 24 * 22 25 * @param string $namespace The first URL segment after core prefix. Should be unique to your package/plugin. 23 26 * @param string $route The base URL for route you are adding. … … 41 44 return false; 42 45 } 43 46 47 if ( ! did_action( 'rest_api_init' ) && ! doing_action( 'rest_api_init' ) ) { 48 _doing_it_wrong( 'register_rest_route', __( 'REST API routes must be registered on the rest_api_init action.' ), '5.1.0' ); 49 } 50 44 51 if ( isset( $args['args'] ) ) { 45 52 $common_args = $args['args']; 46 53 unset( $args['args'] ); -
tests/phpunit/tests/rest-api.php
75 75 * Check that a single route is canonicalized. 76 76 * 77 77 * Ensures that single and multiple routes are handled correctly. 78 * 79 * @expectedIncorrectUsage register_rest_route 78 80 */ 79 81 public function test_route_canonicalized() { 80 82 register_rest_route( … … 110 112 * Check that a single route is canonicalized. 111 113 * 112 114 * Ensures that single and multiple routes are handled correctly. 115 * 116 * @expectedIncorrectUsage register_rest_route 113 117 */ 114 118 public function test_route_canonicalized_multiple() { 115 119 register_rest_route( … … 151 155 152 156 /** 153 157 * Check that routes are merged by default. 158 * 159 * @expectedIncorrectUsage register_rest_route 154 160 */ 155 161 public function test_route_merge() { 156 162 register_rest_route( … … 178 184 179 185 /** 180 186 * Check that we can override routes. 187 * 188 * @expectedIncorrectUsage register_rest_route 181 189 */ 182 190 public function test_route_override() { 183 191 register_rest_route( … … 256 264 $this->assertTrue( in_array( 'rest_route', $GLOBALS['wp']->public_query_vars ) ); 257 265 } 258 266 267 /** 268 * @expectedIncorrectUsage register_rest_route 269 */ 259 270 public function test_route_method() { 260 271 register_rest_route( 261 272 'test-ns', … … 273 284 274 285 /** 275 286 * The 'methods' arg should accept a single value as well as array. 287 * 288 * @expectedIncorrectUsage register_rest_route 276 289 */ 277 290 public function test_route_method_string() { 278 291 register_rest_route( … … 291 304 292 305 /** 293 306 * The 'methods' arg should accept a single value as well as array. 307 * 308 * @expectedIncorrectUsage register_rest_route 294 309 */ 295 310 public function test_route_method_array() { 296 311 register_rest_route( … … 315 330 316 331 /** 317 332 * The 'methods' arg should a comma seperated string. 333 * 334 * @expectedIncorrectUsage register_rest_route 318 335 */ 319 336 public function test_route_method_comma_seperated() { 320 337 register_rest_route( … … 337 354 ); 338 355 } 339 356 357 /** 358 * @expectedIncorrectUsage register_rest_route 359 */ 340 360 public function test_options_request() { 341 361 register_rest_route( 342 362 'test-ns', … … 358 378 359 379 /** 360 380 * Ensure that the OPTIONS handler doesn't kick in for non-OPTIONS requests. 381 * 382 * @expectedIncorrectUsage register_rest_route 361 383 */ 362 384 public function test_options_request_not_options() { 363 385 register_rest_route( … … 696 718 return 'Spy_REST_Server'; 697 719 } 698 720 721 /** 722 * @expectedIncorrectUsage register_rest_route2 723 */ 699 724 public function test_register_rest_route_without_server() { 700 725 $GLOBALS['wp_rest_server'] = null; 701 726 add_filter( 'wp_rest_server_class', array( $this, 'filter_wp_rest_server_class' ) );