Changeset 54339
- Timestamp:
- 09/27/2022 08:12:00 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r53877 r54339 102 102 ), 103 103 '5.5.0' 104 ); 105 } 106 107 if ( count( array_filter( $arg_group['args'], 'is_array' ) ) !== count( $arg_group['args'] ) ) { 108 _doing_it_wrong( 109 __FUNCTION__, 110 sprintf( 111 /* translators: %s: The REST API route being registered. */ 112 __( 'REST API $args should be an array of arrays. Non-array value detected for %s.' ), 113 '<code>' . $clean_namespace . '/' . trim( $route, '/' ) . '</code>' 114 ), 115 '6.1.0' 104 116 ); 105 117 } -
trunk/src/wp-includes/rest-api/class-wp-rest-server.php
r54133 r54339 1514 1514 1515 1515 foreach ( $callback['args'] as $key => $opts ) { 1516 if ( is_string( $opts ) ) { 1517 $opts = array( $opts => 0 ); 1518 } elseif ( ! is_array( $opts ) ) { 1519 $opts = array(); 1520 } 1516 1521 $arg_data = array_intersect_key( $opts, $allowed_schema_keywords ); 1517 1522 $arg_data['required'] = ! empty( $opts['required'] ); -
trunk/tests/phpunit/tests/rest-api.php
r53217 r54339 2519 2519 ); 2520 2520 } 2521 2522 /** 2523 * @ticket 51986 2524 */ 2525 public function test_route_args_is_array_of_arrays() { 2526 $this->setExpectedIncorrectUsage( 'register_rest_route' ); 2527 2528 $registered = register_rest_route( 2529 'my-ns/v1', 2530 '/my-route', 2531 array( 2532 'callback' => '__return_true', 2533 'permission_callback' => '__return_true', 2534 'args' => array( 'pattern' ), 2535 ) 2536 ); 2537 2538 $this->assertTrue( $registered ); 2539 } 2521 2540 }
Note: See TracChangeset
for help on using the changeset viewer.