Make WordPress Core

Ticket #39776: 39776.3.diff

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

New simplified approach.

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

    diff --git src/wp-admin/includes/plugin.php src/wp-admin/includes/plugin.php
    index 54c6db27ac..33266d67a0 100644
    function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $func 
    13121312 *                              and only include lowercase alphanumeric, dashes, and underscores characters
    13131313 *                              to be compatible with sanitize_key().
    13141314 * @param callable $function    The function to be called to output the content for this page.
     1315 * @param int      $position    The position order in the menu where this item should appear.
     1316 *
    13151317 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    13161318 */
    1317 function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
     1319function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
    13181320        global $submenu, $menu, $_wp_real_parent_file, $_wp_submenu_nopriv,
    13191321                $_registered_pages, $_parent_pages;
    13201322
    function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, 
    13441346                }
    13451347        }
    13461348
    1347         $submenu[ $parent_slug ][] = array( $menu_title, $capability, $menu_slug, $page_title );
     1349        $new_sub_menu = array( $menu_title, $capability, $menu_slug, $page_title );
     1350        if ( null === $position ) {
     1351                $submenu[ $parent_slug ][] = $new_sub_menu;
     1352        } else {
     1353                // If there is a position.
     1354                // Grab all of the items before the insertion point.
     1355                $before_items = array_slice( $submenu[ $parent_slug ], 0, $position, true );
     1356                // Grab all of the items after the insertion point
     1357                $after_items = array_slice( $submenu[ $parent_slug ], $position, null, true );
     1358                // Add the new item
     1359                $before_items[] = $new_sub_menu;
     1360                // Merge the items.
     1361                $submenu[ $parent_slug ] = array_merge( $before_items, $after_items );
     1362        }
     1363        // Sort the parent array
     1364        ksort( $submenu[ $parent_slug ] );
    13481365
    13491366        $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug );
    13501367        if ( ! empty( $function ) && ! empty( $hookname ) ) {
    function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, 
    13831400 * @param string   $capability The capability required for this menu to be displayed to the user.
    13841401 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    13851402 * @param callable $function   The function to be called to output the content for this page.
     1403 * @param int      $position   The position in the menu order this one should appear.
    13861404 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    13871405 */
    1388 function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1389         return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1406function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1407        return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    13901408}
    13911409
    13921410/**
    function add_management_page( $page_title, $menu_title, $capability, $menu_slug, 
    14051423 * @param string   $capability The capability required for this menu to be displayed to the user.
    14061424 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    14071425 * @param callable $function   The function to be called to output the content for this page.
     1426 * @param int      $position   The position in the menu order this one should appear.
    14081427 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    14091428 */
    1410 function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1411         return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1429function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1430        return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    14121431}
    14131432
    14141433/**
    function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $f 
    14271446 * @param string   $capability The capability required for this menu to be displayed to the user.
    14281447 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    14291448 * @param callable $function   The function to be called to output the content for this page.
     1449 * @param int      $position   The position in the menu order this one should appear.
    14301450 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    14311451 */
    1432 function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1433         return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1452function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1453        return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    14341454}
    14351455
    14361456/**
    function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $fun 
    14491469 * @param string   $capability The capability required for this menu to be displayed to the user.
    14501470 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    14511471 * @param callable $function   The function to be called to output the content for this page.
     1472 * @param int      $position   The position in the menu order this one should appear.
    14521473 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    14531474 */
    1454 function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1455         return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1475function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1476        return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    14561477}
    14571478
    14581479/**
    function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $f 
    14711492 * @param string   $capability The capability required for this menu to be displayed to the user.
    14721493 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    14731494 * @param callable $function   The function to be called to output the content for this page.
     1495 * @param int      $position   The position in the menu order this one should appear.
    14741496 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    14751497 */
    1476 function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1477         if ( current_user_can( 'edit_users' ) ) {
     1498
     1499function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1500        if ( current_user_can('edit_users') ) {
    14781501                $parent = 'users.php';
    14791502        } else {
    14801503                $parent = 'profile.php';
    14811504        }
    1482         return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function );
     1505        return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    14831506}
    14841507/**
    14851508 * Add submenu page to the Dashboard main menu.
    function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $fun 
    14971520 * @param string   $capability The capability required for this menu to be displayed to the user.
    14981521 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    14991522 * @param callable $function   The function to be called to output the content for this page.
     1523 * @param int      $position   The position in the menu order this one should appear.
    15001524 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    15011525 */
    1502 function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1503         return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1526function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1527        return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    15041528}
    15051529
    15061530/**
    function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, 
    15191543 * @param string   $capability The capability required for this menu to be displayed to the user.
    15201544 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    15211545 * @param callable $function   The function to be called to output the content for this page.
     1546 * @param int      $position   The position in the menu order this one should appear.
    15221547 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    15231548 */
    1524 function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1525         return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1549function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1550        return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    15261551}
    15271552
    15281553/**
    function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $fun 
    15411566 * @param string   $capability The capability required for this menu to be displayed to the user.
    15421567 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    15431568 * @param callable $function   The function to be called to output the content for this page.
     1569 * @param int      $position   The position in the menu order this one should appear.
    15441570 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    15451571 */
    1546 function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1547         return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1572function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1573        return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    15481574}
    15491575
    15501576/**
    function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $fun 
    15631589 * @param string   $capability The capability required for this menu to be displayed to the user.
    15641590 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    15651591 * @param callable $function   The function to be called to output the content for this page.
     1592 * @param int      $position   The position in the menu order this one should appear.
    15661593 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    15671594 */
    1568 function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1569         return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1595function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1596        return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    15701597}
    15711598
    15721599/**
    function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $fun 
    15851612 * @param string   $capability The capability required for this menu to be displayed to the user.
    15861613 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    15871614 * @param callable $function   The function to be called to output the content for this page.
     1615 * @param int      $position   The position in the menu order this one should appear.
    15881616 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    15891617 */
    1590 function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1591         return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function );
     1618function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1619        return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function, $position);
    15921620}
    15931621
    15941622/**
    function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $fun 
    16071635 * @param string   $capability The capability required for this menu to be displayed to the user.
    16081636 * @param string   $menu_slug  The slug name to refer to this menu by (should be unique for this menu).
    16091637 * @param callable $function   The function to be called to output the content for this page.
     1638 * @param int      $position   The position in the menu order this one should appear.
    16101639 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
    16111640 */
    1612 function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    1613         return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1641function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) {
     1642        return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position );
    16141643}
    16151644
    16161645/**