Make WordPress Core

Ticket #39776: 39776.2.diff

File 39776.2.diff, 13.7 KB (added by welcher, 6 years ago)

Refreshed patch

  • src/wp-admin/includes/plugin.php

    diff --git src/wp-admin/includes/plugin.php src/wp-admin/includes/plugin.php
    index c898fc5169..e5e9d07d65 100644
    function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $func 
    12081208 *                              and only include lowercase alphanumeric, dashes, and underscores characters
    12091209 *                              to be compatible with sanitize_key().
    12101210 * @param callable $function    The function to be called to output the content for this page.
     1211 * @param int      $position    The position in the menu order this one should appear.
     1212 *
    12111213 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    12121214 */
    1213 function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     1215function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
    12141216        global $submenu, $menu, $_wp_real_parent_file, $_wp_submenu_nopriv,
    12151217                $_registered_pages, $_parent_pages;
    12161218
    function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, 
    12401242                }
    12411243        }
    12421244
    1243         $submenu[ $parent_slug ][] = array( $menu_title, $capability, $menu_slug, $page_title );
     1245        $new_sub_menu = array( $menu_title, $capability, $menu_slug, $page_title );
     1246        if ( null === $position ) {
     1247                $submenu[ $parent_slug ][] = $new_sub_menu;
     1248        } else {
     1249                //Set the position to a multiple of 5
     1250                $position = ( $position > 1 ) ? $position * 5 : $position;
     1251                if ( isset( $submenu[ $parent_slug ][ $position ] ) ) {
     1252                        $existing_keys = array_keys( $submenu[ $parent_slug ] );
     1253                        while ( in_array( $position, $existing_keys, true ) ) {
     1254                                $position += 0.1;
     1255                        }
     1256                }
     1257                $submenu[ $parent_slug ][ $position ] = $new_sub_menu;
     1258        }
     1259        // Sort the parent array
     1260        ksort( $submenu[ $parent_slug ] );
    12441261
    12451262        $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug );
    12461263        if ( ! empty( $function ) && ! empty( $hookname ) ) {
    function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, 
    12791296 * @param string   $capability The capability required for this menu to be displayed to the user.
    12801297 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    12811298 * @param callable $function   The function to be called to output the content for this page.
     1299 * @param int      $position   The position in the menu order this one should appear.
    12821300 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    12831301 */
    1284 function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1285         return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1302function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1303        return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    12861304}
    12871305
    12881306/**
    function add_management_page( $page_title, $menu_title, $capability, $menu_slug, 
    13011319 * @param string   $capability The capability required for this menu to be displayed to the user.
    13021320 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    13031321 * @param callable $function   The function to be called to output the content for this page.
     1322 * @param int      $position   The position in the menu order this one should appear.
    13041323 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    13051324 */
    1306 function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1307         return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1325function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1326        return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    13081327}
    13091328
    13101329/**
    function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $f 
    13231342 * @param string   $capability The capability required for this menu to be displayed to the user.
    13241343 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    13251344 * @param callable $function   The function to be called to output the content for this page.
     1345 * @param int      $position   The position in the menu order this one should appear.
    13261346 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    13271347 */
    1328 function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1329         return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1348function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1349        return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    13301350}
    13311351
    13321352/**
    function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $fun 
    13451365 * @param string   $capability The capability required for this menu to be displayed to the user.
    13461366 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    13471367 * @param callable $function   The function to be called to output the content for this page.
     1368 * @param int      $position   The position in the menu order this one should appear.
    13481369 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    13491370 */
    1350 function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1351         return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1371function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1372        return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    13521373}
    13531374
    13541375/**
    function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $f 
    13671388 * @param string   $capability The capability required for this menu to be displayed to the user.
    13681389 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    13691390 * @param callable $function   The function to be called to output the content for this page.
     1391 * @param int      $position   The position in the menu order this one should appear.
    13701392 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    13711393 */
    1372 function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1373         if ( current_user_can( 'edit_users' ) ) {
     1394
     1395function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1396        if ( current_user_can('edit_users') ) {
    13741397                $parent = 'users.php';
    13751398        } else {
    13761399                $parent = 'profile.php';
    13771400        }
    1378         return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function );
     1401        return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    13791402}
    13801403/**
    13811404 * Add submenu page to the Dashboard main menu.
    function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $fun 
    13931416 * @param string   $capability The capability required for this menu to be displayed to the user.
    13941417 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    13951418 * @param callable $function   The function to be called to output the content for this page.
     1419 * @param int      $position   The position in the menu order this one should appear.
    13961420 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    13971421 */
    1398 function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1399         return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1422function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1423        return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    14001424}
    14011425
    14021426/**
    function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, 
    14151439 * @param string   $capability The capability required for this menu to be displayed to the user.
    14161440 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    14171441 * @param callable $function   The function to be called to output the content for this page.
     1442 * @param int      $position   The position in the menu order this one should appear.
    14181443 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    14191444 */
    1420 function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1421         return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1445function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1446        return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    14221447}
    14231448
    14241449/**
    function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $fun 
    14371462 * @param string   $capability The capability required for this menu to be displayed to the user.
    14381463 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    14391464 * @param callable $function   The function to be called to output the content for this page.
     1465 * @param int      $position   The position in the menu order this one should appear.
    14401466 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    14411467 */
    1442 function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1443         return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1468function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1469        return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    14441470}
    14451471
    14461472/**
    function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $fun 
    14591485 * @param string   $capability The capability required for this menu to be displayed to the user.
    14601486 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    14611487 * @param callable $function   The function to be called to output the content for this page.
     1488 * @param int      $position   The position in the menu order this one should appear.
    14621489 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    14631490 */
    1464 function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1465         return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1491function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1492        return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    14661493}
    14671494
    14681495/**
    function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $fun 
    14811508 * @param string   $capability The capability required for this menu to be displayed to the user.
    14821509 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    14831510 * @param callable $function   The function to be called to output the content for this page.
     1511 * @param int      $position   The position in the menu order this one should appear.
    14841512 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    14851513 */
    1486 function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1487         return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function );
     1514function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1515        return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function, $position);
    14881516}
    14891517
    14901518/**
    function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $fun 
    15031531 * @param string   $capability The capability required for this menu to be displayed to the user.
    15041532 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    15051533 * @param callable $function   The function to be called to output the content for this page.
     1534 * @param int      $position   The position in the menu order this one should appear.
    15061535 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    15071536 */
    1508 function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1509         return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1537function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1538        return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    15101539}
    15111540
    15121541/**