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.
Built from https://develop.svn.wordpress.org/trunk@54964


git-svn-id: http://core.svn.wordpress.org/trunk@54516 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-12-13 18:28:11 +00:00
parent 0d5910247a
commit e52cbfe467
2 changed files with 32 additions and 32 deletions

View File

@ -23,16 +23,16 @@ define( 'REST_API_VERSION', '2.0' );
* @since 5.1.0 Added a `_doing_it_wrong()` notice when not called on or after the `rest_api_init` hook. * @since 5.1.0 Added a `_doing_it_wrong()` notice when not called on or after the `rest_api_init` hook.
* @since 5.5.0 Added a `_doing_it_wrong()` notice when the required `permission_callback` argument is not set. * @since 5.5.0 Added a `_doing_it_wrong()` notice when the required `permission_callback` argument is not set.
* *
* @param string $namespace The first URL segment after core prefix. Should be unique to your package/plugin. * @param string $route_namespace The first URL segment after core prefix. Should be unique to your package/plugin.
* @param string $route The base URL for route you are adding. * @param string $route The base URL for route you are adding.
* @param array $args Optional. Either an array of options for the endpoint, or an array of arrays for * @param array $args Optional. Either an array of options for the endpoint, or an array of arrays for
* multiple methods. Default empty array. * multiple methods. Default empty array.
* @param bool $override Optional. If the route already exists, should we override it? True overrides, * @param bool $override Optional. If the route already exists, should we override it? True overrides,
* false merges (with newer overriding if duplicate keys exist). Default false. * false merges (with newer overriding if duplicate keys exist). Default false.
* @return bool True on success, false on error. * @return bool True on success, false on error.
*/ */
function register_rest_route( $namespace, $route, $args = array(), $override = false ) { function register_rest_route( $route_namespace, $route, $args = array(), $override = false ) {
if ( empty( $namespace ) ) { if ( empty( $route_namespace ) ) {
/* /*
* Non-namespaced routes are not allowed, with the exception of the main * Non-namespaced routes are not allowed, with the exception of the main
* and namespace indexes. If you really need to register a * and namespace indexes. If you really need to register a
@ -45,9 +45,9 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f
return false; return false;
} }
$clean_namespace = trim( $namespace, '/' ); $clean_namespace = trim( $route_namespace, '/' );
if ( $clean_namespace !== $namespace ) { if ( $clean_namespace !== $route_namespace ) {
_doing_it_wrong( __FUNCTION__, __( 'Namespace must not start or end with a slash.' ), '5.4.2' ); _doing_it_wrong( __FUNCTION__, __( 'Namespace must not start or end with a slash.' ), '5.4.2' );
} }
@ -642,20 +642,20 @@ function rest_ensure_response( $response ) {
* *
* @since 4.4.0 * @since 4.4.0
* *
* @param string $function The function that was called. * @param string $function_name The function that was called.
* @param string $replacement The function that should have been called. * @param string $replacement The function that should have been called.
* @param string $version Version. * @param string $version Version.
*/ */
function rest_handle_deprecated_function( $function, $replacement, $version ) { function rest_handle_deprecated_function( $function_name, $replacement, $version ) {
if ( ! WP_DEBUG || headers_sent() ) { if ( ! WP_DEBUG || headers_sent() ) {
return; return;
} }
if ( ! empty( $replacement ) ) { if ( ! empty( $replacement ) ) {
/* translators: 1: Function name, 2: WordPress version number, 3: New function name. */ /* translators: 1: Function name, 2: WordPress version number, 3: New function name. */
$string = sprintf( __( '%1$s (since %2$s; use %3$s instead)' ), $function, $version, $replacement ); $string = sprintf( __( '%1$s (since %2$s; use %3$s instead)' ), $function_name, $version, $replacement );
} else { } else {
/* translators: 1: Function name, 2: WordPress version number. */ /* translators: 1: Function name, 2: WordPress version number. */
$string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function, $version ); $string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function_name, $version );
} }
header( sprintf( 'X-WP-DeprecatedFunction: %s', $string ) ); header( sprintf( 'X-WP-DeprecatedFunction: %s', $string ) );
@ -666,20 +666,20 @@ function rest_handle_deprecated_function( $function, $replacement, $version ) {
* *
* @since 4.4.0 * @since 4.4.0
* *
* @param string $function The function that was called. * @param string $function_name The function that was called.
* @param string $message A message regarding the change. * @param string $message A message regarding the change.
* @param string $version Version. * @param string $version Version.
*/ */
function rest_handle_deprecated_argument( $function, $message, $version ) { function rest_handle_deprecated_argument( $function_name, $message, $version ) {
if ( ! WP_DEBUG || headers_sent() ) { if ( ! WP_DEBUG || headers_sent() ) {
return; return;
} }
if ( $message ) { if ( $message ) {
/* translators: 1: Function name, 2: WordPress version number, 3: Error message. */ /* translators: 1: Function name, 2: WordPress version number, 3: Error message. */
$string = sprintf( __( '%1$s (since %2$s; %3$s)' ), $function, $version, $message ); $string = sprintf( __( '%1$s (since %2$s; %3$s)' ), $function_name, $version, $message );
} else { } else {
/* translators: 1: Function name, 2: WordPress version number. */ /* translators: 1: Function name, 2: WordPress version number. */
$string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function, $version ); $string = sprintf( __( '%1$s (since %2$s; no alternative available)' ), $function_name, $version );
} }
header( sprintf( 'X-WP-DeprecatedParam: %s', $string ) ); header( sprintf( 'X-WP-DeprecatedParam: %s', $string ) );
@ -690,11 +690,11 @@ function rest_handle_deprecated_argument( $function, $message, $version ) {
* *
* @since 5.5.0 * @since 5.5.0
* *
* @param string $function The function that was called. * @param string $function_name The function that was called.
* @param string $message A message explaining what has been done incorrectly. * @param string $message A message explaining what has been done incorrectly.
* @param string|null $version The version of WordPress where the message was added. * @param string|null $version The version of WordPress where the message was added.
*/ */
function rest_handle_doing_it_wrong( $function, $message, $version ) { function rest_handle_doing_it_wrong( $function_name, $message, $version ) {
if ( ! WP_DEBUG || headers_sent() ) { if ( ! WP_DEBUG || headers_sent() ) {
return; return;
} }
@ -702,11 +702,11 @@ function rest_handle_doing_it_wrong( $function, $message, $version ) {
if ( $version ) { if ( $version ) {
/* translators: Developer debugging message. 1: PHP function name, 2: WordPress version number, 3: Explanatory message. */ /* translators: Developer debugging message. 1: PHP function name, 2: WordPress version number, 3: Explanatory message. */
$string = __( '%1$s (since %2$s; %3$s)' ); $string = __( '%1$s (since %2$s; %3$s)' );
$string = sprintf( $string, $function, $version, $message ); $string = sprintf( $string, $function_name, $version, $message );
} else { } else {
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message. */ /* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message. */
$string = __( '%1$s (%2$s)' ); $string = __( '%1$s (%2$s)' );
$string = sprintf( $string, $function, $message ); $string = sprintf( $string, $function_name, $message );
} }
header( sprintf( 'X-WP-DoingItWrong: %s', $string ) ); header( sprintf( 'X-WP-DoingItWrong: %s', $string ) );
@ -1656,13 +1656,13 @@ function rest_handle_multi_type_schema( $value, $args, $param = '' ) {
* *
* @since 5.5.0 * @since 5.5.0
* *
* @param array $array The array to check. * @param array $input_array The array to check.
* @return bool True if the array contains unique items, false otherwise. * @return bool True if the array contains unique items, false otherwise.
*/ */
function rest_validate_array_contains_unique_items( $array ) { function rest_validate_array_contains_unique_items( $input_array ) {
$seen = array(); $seen = array();
foreach ( $array as $item ) { foreach ( $input_array as $item ) {
$stabilized = rest_stabilize_value( $item ); $stabilized = rest_stabilize_value( $item );
$key = serialize( $stabilized ); $key = serialize( $stabilized );

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.2-alpha-54963'; $wp_version = '6.2-alpha-54964';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.