Skip to content

Commit 608bbf5

Browse files
Code Modernization: Rename parameters that use reserved keywords in wp-includes/rest-api.php.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names. This commit: * Renames the `$namespace` parameter to `$route_namespace` in `register_rest_route()`. * Renames the `$function` parameter to `$function_name` in: * `rest_handle_deprecated_function()` * `rest_handle_deprecated_argument()` * `rest_handle_doing_it_wrong()` * Renames the `$array` parameter to `$input_array` in `rest_validate_array_contains_unique_items()`. Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938], [54943], [54944], [54945], [54946], [54947], [54948], [54950], [54951], [54952], [54956], [54959], [54960], [54961], [54962]. Props jrf, aristath, poena, justinahinon, SergeyBiryukov. See #56788. git-svn-id: https://develop.svn.wordpress.org/trunk@54964 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d18ab99 commit 608bbf5

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/wp-includes/rest-api.php

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
* @since 5.1.0 Added a `_doing_it_wrong()` notice when not called on or after the `rest_api_init` hook.
2424
* @since 5.5.0 Added a `_doing_it_wrong()` notice when the required `permission_callback` argument is not set.
2525
*
26-
* @param string $namespace The first URL segment after core prefix. Should be unique to your package/plugin.
27-
* @param string $route The base URL for route you are adding.
28-
* @param array $args Optional. Either an array of options for the endpoint, or an array of arrays for
29-
* multiple methods. Default empty array.
30-
* @param bool $override Optional. If the route already exists, should we override it? True overrides,
31-
* false merges (with newer overriding if duplicate keys exist). Default false.
26+
* @param string $route_namespace The first URL segment after core prefix. Should be unique to your package/plugin.
27+
* @param string $route The base URL for route you are adding.
28+
* @param array $args Optional. Either an array of options for the endpoint, or an array of arrays for
29+
* multiple methods. Default empty array.
30+
* @param bool $override Optional. If the route already exists, should we override it? True overrides,
31+
* false merges (with newer overriding if duplicate keys exist). Default false.
3232
* @return bool True on success, false on error.
3333
*/
34-
function register_rest_route( $namespace, $route, $args = array(), $override = false ) {
35-
if ( empty( $namespace ) ) {
34+
function register_rest_route( $route_namespace, $route, $args = array(), $override = false ) {
35+
if ( empty( $route_namespace ) ) {
3636
/*
3737
* Non-namespaced routes are not allowed, with the exception of the main
3838
* and namespace indexes. If you really need to register a
@@ -45,9 +45,9 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f
4545
return false;
4646
}
4747

48-
$clean_namespace = trim( $namespace, '/' );
48+
$clean_namespace = trim( $route_namespace, '/' );
4949

50-
if ( $clean_namespace !== $namespace ) {
50+
if ( $clean_namespace !== $route_namespace ) {
5151
_doing_it_wrong( __FUNCTION__, __( 'Namespace must not start or end with a slash.' ), '5.4.2' );
5252
}
5353

@@ -642,20 +642,20 @@ function rest_ensure_response( $response ) {
642642
*
643643
* @since 4.4.0
644644
*
645-
* @param string $function The function that was called.
646-
* @param string $replacement The function that should have been called.
647-
* @param string $version Version.
645+
* @param string $function_name The function that was called.
646+
* @param string $replacement The function that should have been called.
647+
* @param string $version Version.
648648
*/
649-
function rest_handle_deprecated_function( $function, $replacement, $version ) {
649+
function rest_handle_deprecated_function( $function_name, $replacement, $version ) {
650650
if ( ! WP_DEBUG || headers_sent() ) {
651651
return;
652652
}
653653
if ( ! empty( $replacement ) ) {
654654
/* translators: 1: Function name, 2: WordPress version number, 3: New function name. */
655-
$string = sprintf( __( '%1$s (since %2$s; use %3$s instead)' ), $function, $version, $replacement );
655+
$string = sprintf( __( '%1$s (since %2$s; use %3$s instead)' ), $function_name, $version, $replacement );
656656
} else {
657657
/* translators: 1: Function name, 2: WordPress version number. */
658-
$string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function, $version );
658+
$string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function_name, $version );
659659
}
660660

661661
header( sprintf( 'X-WP-DeprecatedFunction: %s', $string ) );
@@ -666,20 +666,20 @@ function rest_handle_deprecated_function( $function, $replacement, $version ) {
666666
*
667667
* @since 4.4.0
668668
*
669-
* @param string $function The function that was called.
670-
* @param string $message A message regarding the change.
671-
* @param string $version Version.
669+
* @param string $function_name The function that was called.
670+
* @param string $message A message regarding the change.
671+
* @param string $version Version.
672672
*/
673-
function rest_handle_deprecated_argument( $function, $message, $version ) {
673+
function rest_handle_deprecated_argument( $function_name, $message, $version ) {
674674
if ( ! WP_DEBUG || headers_sent() ) {
675675
return;
676676
}
677677
if ( $message ) {
678678
/* translators: 1: Function name, 2: WordPress version number, 3: Error message. */
679-
$string = sprintf( __( '%1$s (since %2$s; %3$s)' ), $function, $version, $message );
679+
$string = sprintf( __( '%1$s (since %2$s; %3$s)' ), $function_name, $version, $message );
680680
} else {
681681
/* translators: 1: Function name, 2: WordPress version number. */
682-
$string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function, $version );
682+
$string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function_name, $version );
683683
}
684684

685685
header( sprintf( 'X-WP-DeprecatedParam: %s', $string ) );
@@ -690,23 +690,23 @@ function rest_handle_deprecated_argument( $function, $message, $version ) {
690690
*
691691
* @since 5.5.0
692692
*
693-
* @param string $function The function that was called.
694-
* @param string $message A message explaining what has been done incorrectly.
695-
* @param string|null $version The version of WordPress where the message was added.
693+
* @param string $function_name The function that was called.
694+
* @param string $message A message explaining what has been done incorrectly.
695+
* @param string|null $version The version of WordPress where the message was added.
696696
*/
697-
function rest_handle_doing_it_wrong( $function, $message, $version ) {
697+
function rest_handle_doing_it_wrong( $function_name, $message, $version ) {
698698
if ( ! WP_DEBUG || headers_sent() ) {
699699
return;
700700
}
701701

702702
if ( $version ) {
703703
/* translators: Developer debugging message. 1: PHP function name, 2: WordPress version number, 3: Explanatory message. */
704704
$string = __( '%1$s (since %2$s; %3$s)' );
705-
$string = sprintf( $string, $function, $version, $message );
705+
$string = sprintf( $string, $function_name, $version, $message );
706706
} else {
707707
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message. */
708708
$string = __( '%1$s (%2$s)' );
709-
$string = sprintf( $string, $function, $message );
709+
$string = sprintf( $string, $function_name, $message );
710710
}
711711

712712
header( sprintf( 'X-WP-DoingItWrong: %s', $string ) );
@@ -1656,13 +1656,13 @@ function rest_handle_multi_type_schema( $value, $args, $param = '' ) {
16561656
*
16571657
* @since 5.5.0
16581658
*
1659-
* @param array $array The array to check.
1659+
* @param array $input_array The array to check.
16601660
* @return bool True if the array contains unique items, false otherwise.
16611661
*/
1662-
function rest_validate_array_contains_unique_items( $array ) {
1662+
function rest_validate_array_contains_unique_items( $input_array ) {
16631663
$seen = array();
16641664

1665-
foreach ( $array as $item ) {
1665+
foreach ( $input_array as $item ) {
16661666
$stabilized = rest_stabilize_value( $item );
16671667
$key = serialize( $stabilized );
16681668

0 commit comments

Comments
 (0)