diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 683cb7c215..3d138d176f 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -1267,7 +1267,7 @@ function uninstall_plugin( $plugin ) { * * Pass the name of a Dashicons helper class to use a font icon, * e.g. 'dashicons-chart-pie'. * * Pass 'none' to leave div.wp-menu-image empty so an icon can be added via CSS. - * @param int $position The position in the menu order this one should appear. + * @param int $position The position in the menu order this item should appear. * @return string The resulting page's hook_suffix. */ function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = null ) { @@ -1338,9 +1338,11 @@ function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $func * and only include lowercase alphanumeric, dashes, and underscores characters * to be compatible with sanitize_key(). * @param callable $function The function to be called to output the content for this page. + * @param int $position The position in the menu order this item should appear. + * * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. */ -function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { +function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) { global $submenu, $menu, $_wp_real_parent_file, $_wp_submenu_nopriv, $_registered_pages, $_parent_pages; @@ -1370,7 +1372,33 @@ function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, } } - $submenu[ $parent_slug ][] = array( $menu_title, $capability, $menu_slug, $page_title ); + $new_sub_menu = array( $menu_title, $capability, $menu_slug, $page_title ); + if ( null === $position ) { + $submenu[ $parent_slug ][] = $new_sub_menu; + } else { + // If position is equal or higher than the number of items in the array, append the submenu. + if ( $position >= count( $submenu[ $parent_slug ] ) ) { + $submenu[ $parent_slug ][] = $new_sub_menu; + } else { + // Test for a negative position. + $position = max( $position, 0 ); + if ( 0 === $position ) { + // For negative or `0` positions, prepend the submenu. + array_unshift( $submenu[ $parent_slug ], $new_sub_menu ); + } else { + // Grab all of the items before the insertion point. + $before_items = array_slice( $submenu[ $parent_slug ], 0, $position, true ); + // Grab all of the items after the insertion point. + $after_items = array_slice( $submenu[ $parent_slug ], $position, null, true ); + // Add the new item. + $before_items[] = $new_sub_menu; + // Merge the items. + $submenu[ $parent_slug ] = array_merge( $before_items, $after_items ); + } + } + } + // Sort the parent array + ksort( $submenu[ $parent_slug ] ); $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug ); if ( ! empty( $function ) && ! empty( $hookname ) ) { @@ -1409,10 +1437,11 @@ function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). * @param callable $function The function to be called to output the content for this page. + * @param int $position The position in the menu order this item should appear. * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. */ -function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { - return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function ); +function add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) { + return add_submenu_page( 'tools.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position ); } /** @@ -1431,10 +1460,11 @@ function add_management_page( $page_title, $menu_title, $capability, $menu_slug, * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). * @param callable $function The function to be called to output the content for this page. + * @param int $position The position in the menu order this item should appear. * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. */ -function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { - return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function ); +function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) { + return add_submenu_page( 'options-general.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position ); } /** @@ -1453,10 +1483,11 @@ function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $f * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). * @param callable $function The function to be called to output the content for this page. + * @param int $position The position in the menu order this item should appear. * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. */ -function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { - return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $function ); +function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) { + return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position ); } /** @@ -1475,10 +1506,11 @@ function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $fun * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). * @param callable $function The function to be called to output the content for this page. + * @param int $position The position in the menu order this item should appear. * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. */ -function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { - return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function ); +function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) { + return add_submenu_page( 'plugins.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position ); } /** @@ -1497,15 +1529,17 @@ function add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $f * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). * @param callable $function The function to be called to output the content for this page. + * @param int $position The position in the menu order this item should appear. * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. */ -function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { + +function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) { if ( current_user_can( 'edit_users' ) ) { $parent = 'users.php'; } else { $parent = 'profile.php'; } - return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function ); + return add_submenu_page( $parent, $page_title, $menu_title, $capability, $menu_slug, $function, $position ); } /** * Add submenu page to the Dashboard main menu. @@ -1523,10 +1557,11 @@ function add_users_page( $page_title, $menu_title, $capability, $menu_slug, $fun * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). * @param callable $function The function to be called to output the content for this page. + * @param int $position The position in the menu order this item should appear. * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. */ -function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { - return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function ); +function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) { + return add_submenu_page( 'index.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position ); } /** @@ -1545,10 +1580,11 @@ function add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). * @param callable $function The function to be called to output the content for this page. + * @param int $position The position in the menu order this item should appear. * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. */ -function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { - return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $function ); +function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) { + return add_submenu_page( 'edit.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position ); } /** @@ -1567,10 +1603,11 @@ function add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $fun * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). * @param callable $function The function to be called to output the content for this page. + * @param int $position The position in the menu order this item should appear. * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. */ -function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { - return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function ); +function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) { + return add_submenu_page( 'upload.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position ); } /** @@ -1589,10 +1626,11 @@ function add_media_page( $page_title, $menu_title, $capability, $menu_slug, $fun * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). * @param callable $function The function to be called to output the content for this page. + * @param int $position The position in the menu order this item should appear. * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. */ -function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { - return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function ); +function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) { + return add_submenu_page( 'link-manager.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position ); } /** @@ -1611,10 +1649,11 @@ function add_links_page( $page_title, $menu_title, $capability, $menu_slug, $fun * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). * @param callable $function The function to be called to output the content for this page. + * @param int $position The position in the menu order this item should appear. * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. */ -function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { - return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function ); +function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) { + return add_submenu_page( 'edit.php?post_type=page', $page_title, $menu_title, $capability, $menu_slug, $function, $position ); } /** @@ -1633,10 +1672,11 @@ function add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $fun * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu). * @param callable $function The function to be called to output the content for this page. + * @param int $position The position in the menu order this item should appear. * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. */ -function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) { - return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function ); +function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $position = null ) { + return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function, $position ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 2083c09da2..953c1455fe 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-alpha-46196'; +$wp_version = '5.3-alpha-46197'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.