Make WordPress Core

Changeset 53215


Ignore:
Timestamp:
04/19/2022 12:46:24 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/plugin.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 $function parameter to $callback in:
    • add_menu_page()
    • add_submenu_page()
    • add_management_page()
    • add_options_page()
    • add_theme_page()
    • add_plugins_page()
    • add_users_page()
    • add_dashboard_page()
    • add_posts_page()
    • add_media_page()
    • add_links_page()
    • add_pages_page()
    • add_comments_page()
  • Renames the $echo parameter to $display in menu_page_url().
  • Renames the $parent parameter to $parent_page in get_admin_page_parent().

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207].

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

File:
1 edited

Legend:

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

    r53181 r53215  
    12931293 *                              include lowercase alphanumeric, dashes, and underscores characters to be compatible
    12941294 *                              with sanitize_key().
    1295  * @param callable  $function   Optional. The function to be called to output the content for this page.
     1295 * @param callable  $callback   Optional. The function to be called to output the content for this page.
    12961296 * @param string    $icon_url   Optional. The URL to the icon to be used for this menu.
    12971297 *                              * Pass a base64-encoded SVG using a data URI, which will be colored to match
     
    13031303 * @return string The resulting page's hook_suffix.
    13041304 */
    1305 function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = null ) {
     1305function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $icon_url = '', $position = null ) {
    13061306    global $menu, $admin_page_hooks, $_registered_pages, $_parent_pages;
    13071307
     
    13121312    $hookname = get_plugin_page_hookname( $menu_slug, '' );
    13131313
    1314     if ( ! empty( $function ) && ! empty( $hookname ) && current_user_can( $capability ) ) {
    1315         add_action( $hookname, $function );
     1314    if ( ! empty( $callback ) && ! empty( $hookname ) && current_user_can( $capability ) ) {
     1315        add_action( $hookname, $callback );
    13161316    }
    13171317
     
    13721372 * @global array $_parent_pages
    13731373 *
    1374  * @param string         $parent_slug The slug name for the parent menu (or the file name of a standard
    1375  *                                    WordPress admin page).
    1376  * @param string         $page_title  The text to be displayed in the title tags of the page when the menu
    1377  *                                    is selected.
    1378  * @param string         $menu_title  The text to be used for the menu.
    1379  * @param string         $capability  The capability required for this menu to be displayed to the user.
    1380  * @param string         $menu_slug   The slug name to refer to this menu by. Should be unique for this menu
    1381  *                                    and only include lowercase alphanumeric, dashes, and underscores characters
    1382  *                                    to be compatible with sanitize_key().
    1383  * @param callable       $function    Optional. The function to be called to output the content for this page.
    1384  * @param int|float      $position    Optional. The position in the menu order this item should appear.
     1374 * @param string    $parent_slug The slug name for the parent menu (or the file name of a standard
     1375 *                               WordPress admin page).
     1376 * @param string    $page_title  The text to be displayed in the title tags of the page when the menu
     1377 *                               is selected.
     1378 * @param string    $menu_title  The text to be used for the menu.
     1379 * @param string    $capability  The capability required for this menu to be displayed to the user.
     1380 * @param string    $menu_slug   The slug name to refer to this menu by. Should be unique for this menu
     1381 *                               and only include lowercase alphanumeric, dashes, and underscores characters
     1382 *                               to be compatible with sanitize_key().
     1383 * @param callable  $callback    Optional. The function to be called to output the content for this page.
     1384 * @param int|float $position    Optional. The position in the menu order this item should appear.
    13851385 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
    13861386 */
    1387 function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1387function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {
    13881388    global $submenu, $menu, $_wp_real_parent_file, $_wp_submenu_nopriv,
    13891389        $_registered_pages, $_parent_pages;
     
    14571457
    14581458    $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug );
    1459     if ( ! empty( $function ) && ! empty( $hookname ) ) {
    1460         add_action( $hookname, $function );
     1459    if ( ! empty( $callback ) && ! empty( $hookname ) ) {
     1460        add_action( $hookname, $callback );
    14611461    }
    14621462
     
    14931493 * @param string   $capability The capability required for this menu to be displayed to the user.
    14941494 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    1495  * @param callable $function   Optional. The function to be called to output the content for this page.
     1495 * @param callable $callback   Optional. The function to be called to output the content for this page.
    14961496 * @param int      $position   Optional. The position in the menu order this item should appear.
    14971497 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
    14981498 */
    1499 function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
    1500     return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
     1499function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {
     1500    return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position );
    15011501}
    15021502
     
    15171517 * @param string   $capability The capability required for this menu to be displayed to the user.
    15181518 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    1519  * @param callable $function   Optional. The function to be called to output the content for this page.
     1519 * @param callable $callback   Optional. The function to be called to output the content for this page.
    15201520 * @param int      $position   Optional. The position in the menu order this item should appear.
    15211521 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
    15221522 */
    1523 function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
    1524     return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
     1523function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {
     1524    return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position );
    15251525}
    15261526
     
    15411541 * @param string   $capability The capability required for this menu to be displayed to the user.
    15421542 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    1543  * @param callable $function   Optional. The function to be called to output the content for this page.
     1543 * @param callable $callback   Optional. The function to be called to output the content for this page.
    15441544 * @param int      $position   Optional. The position in the menu order this item should appear.
    15451545 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
    15461546 */
    1547 function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
    1548     return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
     1547function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {
     1548    return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position );
    15491549}
    15501550
     
    15651565 * @param string   $capability The capability required for this menu to be displayed to the user.
    15661566 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    1567  * @param callable $function   Optional. The function to be called to output the content for this page.
     1567 * @param callable $callback   Optional. The function to be called to output the content for this page.
    15681568 * @param int      $position   Optional. The position in the menu order this item should appear.
    15691569 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
    15701570 */
    1571 function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
    1572     return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
     1571function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {
     1572    return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position );
    15731573}
    15741574
     
    15891589 * @param string   $capability The capability required for this menu to be displayed to the user.
    15901590 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    1591  * @param callable $function   Optional. The function to be called to output the content for this page.
     1591 * @param callable $callback   Optional. The function to be called to output the content for this page.
    15921592 * @param int      $position   Optional. The position in the menu order this item should appear.
    15931593 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
    15941594 */
    1595 function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1595function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {
    15961596    if ( current_user_can( 'edit_users' ) ) {
    15971597        $parent = 'users.php';
     
    15991599        $parent = 'profile.php';
    16001600    }
    1601     return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function, $position );
     1601    return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $callback, $position );
    16021602}
    16031603
     
    16181618 * @param string   $capability The capability required for this menu to be displayed to the user.
    16191619 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    1620  * @param callable $function   Optional. The function to be called to output the content for this page.
     1620 * @param callable $callback   Optional. The function to be called to output the content for this page.
    16211621 * @param int      $position   Optional. The position in the menu order this item should appear.
    16221622 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
    16231623 */
    1624 function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
    1625     return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
     1624function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {
     1625    return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position );
    16261626}
    16271627
     
    16421642 * @param string   $capability The capability required for this menu to be displayed to the user.
    16431643 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    1644  * @param callable $function   Optional. The function to be called to output the content for this page.
     1644 * @param callable $callback   Optional. The function to be called to output the content for this page.
    16451645 * @param int      $position   Optional. The position in the menu order this item should appear.
    16461646 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
    16471647 */
    1648 function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
    1649     return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
     1648function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {
     1649    return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position );
    16501650}
    16511651
     
    16661666 * @param string   $capability The capability required for this menu to be displayed to the user.
    16671667 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    1668  * @param callable $function   Optional. The function to be called to output the content for this page.
     1668 * @param callable $callback   Optional. The function to be called to output the content for this page.
    16691669 * @param int      $position   Optional. The position in the menu order this item should appear.
    16701670 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
    16711671 */
    1672 function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
    1673     return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
     1672function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {
     1673    return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position );
    16741674}
    16751675
     
    16901690 * @param string   $capability The capability required for this menu to be displayed to the user.
    16911691 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    1692  * @param callable $function   Optional. The function to be called to output the content for this page.
     1692 * @param callable $callback   Optional. The function to be called to output the content for this page.
    16931693 * @param int      $position   Optional. The position in the menu order this item should appear.
    16941694 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
    16951695 */
    1696 function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
    1697     return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
     1696function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {
     1697    return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position );
    16981698}
    16991699
     
    17141714 * @param string   $capability The capability required for this menu to be displayed to the user.
    17151715 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    1716  * @param callable $function   Optional. The function to be called to output the content for this page.
     1716 * @param callable $callback   Optional. The function to be called to output the content for this page.
    17171717 * @param int      $position   Optional. The position in the menu order this item should appear.
    17181718 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
    17191719 */
    1720 function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
    1721     return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
     1720function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {
     1721    return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $callback, $position );
    17221722}
    17231723
     
    17381738 * @param string   $capability The capability required for this menu to be displayed to the user.
    17391739 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    1740  * @param callable $function   Optional. The function to be called to output the content for this page.
     1740 * @param callable $callback   Optional. The function to be called to output the content for this page.
    17411741 * @param int      $position   Optional. The position in the menu order this item should appear.
    17421742 * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required.
    17431743 */
    1744 function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
    1745     return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
     1744function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {
     1745    return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position );
    17461746}
    17471747
     
    18181818 *
    18191819 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu).
    1820  * @param bool   $echo      Whether or not to echo the URL. Default true.
     1820 * @param bool   $display   Optional. Whether or not to display the URL. Default true.
    18211821 * @return string The menu page URL.
    18221822 */
    1823 function menu_page_url( $menu_slug, $echo = true ) {
     1823function menu_page_url( $menu_slug, $display = true ) {
    18241824    global $_parent_pages;
    18251825
     
    18381838    $url = esc_url( $url );
    18391839
    1840     if ( $echo ) {
     1840    if ( $display ) {
    18411841        echo $url;
    18421842    }
     
    18631863 * @global array  $_wp_submenu_nopriv
    18641864 *
    1865  * @param string $parent The slug name for the parent menu (or the file name of a standard
    1866  *                       WordPress admin page). Default empty string.
     1865 * @param string $parent_page Optional. The slug name for the parent menu (or the file name
     1866 *                            of a standard WordPress admin page). Default empty string.
    18671867 * @return string The parent file of the current admin page.
    18681868 */
    1869 function get_admin_page_parent( $parent = '' ) {
     1869function get_admin_page_parent( $parent_page = '' ) {
    18701870    global $parent_file, $menu, $submenu, $pagenow, $typenow,
    18711871        $plugin_page, $_wp_real_parent_file, $_wp_menu_nopriv, $_wp_submenu_nopriv;
    18721872
    1873     if ( ! empty( $parent ) && 'admin.php' !== $parent ) {
    1874         if ( isset( $_wp_real_parent_file[ $parent ] ) ) {
    1875             $parent = $_wp_real_parent_file[ $parent ];
    1876         }
    1877 
    1878         return $parent;
     1873    if ( ! empty( $parent_page ) && 'admin.php' !== $parent_page ) {
     1874        if ( isset( $_wp_real_parent_file[ $parent_page ] ) ) {
     1875            $parent_page = $_wp_real_parent_file[ $parent_page ];
     1876        }
     1877
     1878        return $parent_page;
    18791879    }
    18801880
     
    19121912    }
    19131913
    1914     foreach ( array_keys( (array) $submenu ) as $parent ) {
    1915         foreach ( $submenu[ $parent ] as $submenu_array ) {
    1916             if ( isset( $_wp_real_parent_file[ $parent ] ) ) {
    1917                 $parent = $_wp_real_parent_file[ $parent ];
     1914    foreach ( array_keys( (array) $submenu ) as $parent_page ) {
     1915        foreach ( $submenu[ $parent_page ] as $submenu_array ) {
     1916            if ( isset( $_wp_real_parent_file[ $parent_page ] ) ) {
     1917                $parent_page = $_wp_real_parent_file[ $parent_page ];
    19181918            }
    19191919
    19201920            if ( ! empty( $typenow ) && "$pagenow?post_type=$typenow" === $submenu_array[2] ) {
    1921                 $parent_file = $parent;
    1922                 return $parent;
     1921                $parent_file = $parent_page;
     1922                return $parent_page;
    19231923            } elseif ( empty( $typenow ) && $pagenow === $submenu_array[2]
    19241924                && ( empty( $parent_file ) || false === strpos( $parent_file, '?' ) )
    19251925            ) {
    1926                 $parent_file = $parent;
    1927                 return $parent;
     1926                $parent_file = $parent_page;
     1927                return $parent_page;
    19281928            } elseif ( isset( $plugin_page ) && $plugin_page === $submenu_array[2] ) {
    1929                 $parent_file = $parent;
    1930                 return $parent;
     1929                $parent_file = $parent_page;
     1930                return $parent_page;
    19311931            }
    19321932        }
Note: See TracChangeset for help on using the changeset viewer.