Make WordPress Core

Changeset 54964


Ignore:
Timestamp:
12/13/2022 06:26:28 PM (17 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r54891 r54964  
    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 ) ) {
     34function 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
     
    4646    }
    4747
    48     $clean_namespace = trim( $namespace, '/' );
    49 
    50     if ( $clean_namespace !== $namespace ) {
     48    $clean_namespace = trim( $route_namespace, '/' );
     49
     50    if ( $clean_namespace !== $route_namespace ) {
    5151        _doing_it_wrong( __FUNCTION__, __( 'Namespace must not start or end with a slash.' ), '5.4.2' );
    5252    }
     
    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.
    648  */
    649 function rest_handle_deprecated_function( $function, $replacement, $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.
     648 */
     649function rest_handle_deprecated_function( $function_name, $replacement, $version ) {
    650650    if ( ! WP_DEBUG || headers_sent() ) {
    651651        return;
     
    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
     
    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.
    672  */
    673 function rest_handle_deprecated_argument( $function, $message, $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.
     672 */
     673function rest_handle_deprecated_argument( $function_name, $message, $version ) {
    674674    if ( ! WP_DEBUG || headers_sent() ) {
    675675        return;
     
    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
     
    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.
    696  */
    697 function rest_handle_doing_it_wrong( $function, $message, $version ) {
     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.
     696 */
     697function rest_handle_doing_it_wrong( $function_name, $message, $version ) {
    698698    if ( ! WP_DEBUG || headers_sent() ) {
    699699        return;
     
    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
     
    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 ) {
     1662function 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 );
Note: See TracChangeset for help on using the changeset viewer.