Make WordPress Core


Ignore:
Timestamp:
04/14/2022 03:24:09 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/deprecated.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 $default and $parent parameters to $default_category and $parent_category in dropdown_categories().
  • Renames the $default parameter to $default_link_category in dropdown_link_categories().
  • Renames the $parent parameter to $parent_cat and some other parameters for consistency in wp_dropdown_cats().
  • Renames the $function to $callback in add_object_page() and add_utility_page().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/deprecated.php

    r52406 r53184  
    7878 * @global int $post_ID
    7979 *
    80  * @param int $default      Unused.
    81  * @param int $parent        Unused.
    82  * @param array $popular_ids Unused.
    83  */
    84 function dropdown_categories( $default = 0, $parent = 0, $popular_ids = array() ) {
     80 * @param int   $default_category Unused.
     81 * @param int   $parent_category  Unused.
     82 * @param array $popular_ids      Unused.
     83 */
     84function dropdown_categories( $default_category = 0, $parent_category = 0, $popular_ids = array() ) {
    8585    _deprecated_function( __FUNCTION__, '2.6.0', 'wp_category_checklist()' );
    8686    global $post_ID;
     
    9797 * @global int $link_id
    9898 *
    99  * @param int $default Unused.
    100  */
    101 function dropdown_link_categories( $default = 0 ) {
     99 * @param int $default_link_category Unused.
     100 */
     101function dropdown_link_categories( $default_link_category = 0 ) {
    102102    _deprecated_function( __FUNCTION__, '2.6.0', 'wp_link_category_checklist()' );
    103103    global $link_id;
     
    128128 * @see wp_dropdown_categories()
    129129 *
    130  * @param int $currentcat    Optional. ID of the current category. Default 0.
    131  * @param int $currentparent Optional. Current parent category ID. Default 0.
    132  * @param int $parent        Optional. Parent ID to retrieve categories for. Default 0.
    133  * @param int $level         Optional. Number of levels deep to display. Default 0.
    134  * @param array $categories  Optional. Categories to include in the control. Default 0.
     130 * @param int $current_cat    Optional. ID of the current category. Default 0.
     131 * @param int $current_parent Optional. Current parent category ID. Default 0.
     132 * @param int $parent_cat     Optional. Parent ID to retrieve categories for. Default 0.
     133 * @param int $level          Optional. Number of levels deep to display. Default 0.
     134 * @param array $categories   Optional. Categories to include in the control. Default 0.
    135135 * @return void|false Void on success, false if no categories were found.
    136136 */
    137 function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) {
     137function wp_dropdown_cats( $current_cat = 0, $current_parent = 0, $parent_cat = 0, $level = 0, $categories = 0 ) {
    138138    _deprecated_function( __FUNCTION__, '3.0.0', 'wp_dropdown_categories()' );
    139139    if (!$categories )
     
    142142    if ( $categories ) {
    143143        foreach ( $categories as $category ) {
    144             if ( $currentcat != $category->term_id && $parent == $category->parent) {
     144            if ( $current_cat != $category->term_id && $parent_cat == $category->parent) {
    145145                $pad = str_repeat( '– ', $level );
    146146                $category->name = esc_html( $category->name );
    147147                echo "\n\t<option value='$category->term_id'";
    148                 if ( $currentparent == $category->term_id )
     148                if ( $current_parent == $category->term_id )
    149149                    echo " selected='selected'";
    150150                echo ">$pad$category->name</option>";
    151                 wp_dropdown_cats( $currentcat, $currentparent, $category->term_id, $level +1, $categories );
     151                wp_dropdown_cats( $current_cat, $current_parent, $category->term_id, $level +1, $categories );
    152152            }
    153153        }
     
    14271427 * @param string   $capability The capability required for this menu to be displayed to the user.
    14281428 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    1429  * @param callable $function   Optional. The function to be called to output the content for this page.
     1429 * @param callable $callback   Optional. The function to be called to output the content for this page.
    14301430 * @param string   $icon_url   Optional. The URL to the icon to be used for this menu.
    14311431 * @return string The resulting page's hook_suffix.
    14321432 */
    1433 function add_object_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') {
     1433function add_object_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $icon_url = '') {
    14341434    _deprecated_function( __FUNCTION__, '4.5.0', 'add_menu_page()' );
    14351435
     
    14381438    $_wp_last_object_menu++;
    14391439
    1440     return add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $_wp_last_object_menu);
     1440    return add_menu_page($page_title, $menu_title, $capability, $menu_slug, $callback, $icon_url, $_wp_last_object_menu);
    14411441}
    14421442
     
    14601460 * @param string   $capability The capability required for this menu to be displayed to the user.
    14611461 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    1462  * @param callable $function   Optional. The function to be called to output the content for this page.
     1462 * @param callable $callback   Optional. The function to be called to output the content for this page.
    14631463 * @param string   $icon_url   Optional. The URL to the icon to be used for this menu.
    14641464 * @return string The resulting page's hook_suffix.
    14651465 */
    1466 function add_utility_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '') {
     1466function add_utility_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $icon_url = '') {
    14671467    _deprecated_function( __FUNCTION__, '4.5.0', 'add_menu_page()' );
    14681468
     
    14711471    $_wp_last_utility_menu++;
    14721472
    1473     return add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $_wp_last_utility_menu);
     1473    return add_menu_page($page_title, $menu_title, $capability, $menu_slug, $callback, $icon_url, $_wp_last_utility_menu);
    14741474}
    14751475
Note: See TracChangeset for help on using the changeset viewer.