Make add_object_page() and add_utility_page() use add_menu_page() rather than duplicated code. Fixes #9942 props scribu.
git-svn-id: http://svn.automattic.com/wordpress/trunk@11856 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
22d0a6c641
commit
ffc53b56ea
|
@ -584,7 +584,7 @@ function uninstall_plugin($plugin) {
|
||||||
// Menu
|
// Menu
|
||||||
//
|
//
|
||||||
|
|
||||||
function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '' ) {
|
function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '', $position = NULL ) {
|
||||||
global $menu, $admin_page_hooks, $_registered_pages;
|
global $menu, $admin_page_hooks, $_registered_pages;
|
||||||
|
|
||||||
$file = plugin_basename( $file );
|
$file = plugin_basename( $file );
|
||||||
|
@ -595,12 +595,19 @@ function add_menu_page( $page_title, $menu_title, $access_level, $file, $functio
|
||||||
if (!empty ( $function ) && !empty ( $hookname ))
|
if (!empty ( $function ) && !empty ( $hookname ))
|
||||||
add_action( $hookname, $function );
|
add_action( $hookname, $function );
|
||||||
|
|
||||||
if ( empty($icon_url) )
|
if ( empty($icon_url) ) {
|
||||||
$icon_url = 'images/generic.png';
|
$icon_url = 'images/generic.png';
|
||||||
elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') )
|
} elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') ) {
|
||||||
$icon_url = 'https://' . substr($icon_url, 7);
|
$icon_url = 'https://' . substr($icon_url, 7);
|
||||||
|
}
|
||||||
|
|
||||||
$menu[] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
|
$new_menu = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
|
||||||
|
|
||||||
|
if ( NULL === $position ) {
|
||||||
|
$menu[] = $new_menu;
|
||||||
|
} else {
|
||||||
|
$menu[$position] = $new_menu;
|
||||||
|
}
|
||||||
|
|
||||||
$_registered_pages[$hookname] = true;
|
$_registered_pages[$hookname] = true;
|
||||||
|
|
||||||
|
@ -608,53 +615,19 @@ function add_menu_page( $page_title, $menu_title, $access_level, $file, $functio
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_object_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '') {
|
function add_object_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '') {
|
||||||
global $menu, $admin_page_hooks, $_wp_last_object_menu, $_registered_pages;
|
global $_wp_last_object_menu;
|
||||||
|
|
||||||
$file = plugin_basename( $file );
|
|
||||||
|
|
||||||
$admin_page_hooks[$file] = sanitize_title( $menu_title );
|
|
||||||
|
|
||||||
$hookname = get_plugin_page_hookname( $file, '' );
|
|
||||||
if (!empty ( $function ) && !empty ( $hookname ))
|
|
||||||
add_action( $hookname, $function );
|
|
||||||
|
|
||||||
if ( empty($icon_url) )
|
|
||||||
$icon_url = 'images/generic.png';
|
|
||||||
elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') )
|
|
||||||
$icon_url = 'https://' . substr($icon_url, 7);
|
|
||||||
|
|
||||||
$_wp_last_object_menu++;
|
$_wp_last_object_menu++;
|
||||||
|
|
||||||
$menu[$_wp_last_object_menu] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
|
return add_menu_page($page_title, $menu_title, $access_level, $file, $function, $icon_url, $_wp_last_object_menu);
|
||||||
|
|
||||||
$_registered_pages[$hookname] = true;
|
|
||||||
|
|
||||||
return $hookname;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_utility_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '') {
|
function add_utility_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '') {
|
||||||
global $menu, $admin_page_hooks, $_wp_last_utility_menu, $_registered_pages;
|
global $_wp_last_utility_menu;
|
||||||
|
|
||||||
$file = plugin_basename( $file );
|
|
||||||
|
|
||||||
$admin_page_hooks[$file] = sanitize_title( $menu_title );
|
|
||||||
|
|
||||||
$hookname = get_plugin_page_hookname( $file, '' );
|
|
||||||
if (!empty ( $function ) && !empty ( $hookname ))
|
|
||||||
add_action( $hookname, $function );
|
|
||||||
|
|
||||||
if ( empty($icon_url) )
|
|
||||||
$icon_url = 'images/generic.png';
|
|
||||||
elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') )
|
|
||||||
$icon_url = 'https://' . substr($icon_url, 7);
|
|
||||||
|
|
||||||
$_wp_last_utility_menu++;
|
$_wp_last_utility_menu++;
|
||||||
|
|
||||||
$menu[$_wp_last_utility_menu] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
|
return add_menu_page($page_title, $menu_title, $access_level, $file, $function, $icon_url, $_wp_last_utility_menu);
|
||||||
|
|
||||||
$_registered_pages[$hookname] = true;
|
|
||||||
|
|
||||||
return $hookname;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function = '' ) {
|
function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function = '' ) {
|
||||||
|
|
Loading…
Reference in New Issue