Make WordPress Core

Changeset 11856


Ignore:
Timestamp:
08/20/2009 09:00:52 PM (15 years ago)
Author:
westi
Message:

Make add_object_page() and add_utility_page() use add_menu_page() rather than duplicated code. Fixes #9942 props scribu.

File:
1 edited

Legend:

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

    r11717 r11856  
    585585//
    586586
    587 function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '' ) {
     587function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '', $position = NULL ) {
    588588    global $menu, $admin_page_hooks, $_registered_pages;
    589589
     
    596596        add_action( $hookname, $function );
    597597
    598     if ( empty($icon_url) )
     598    if ( empty($icon_url) ) {
    599599        $icon_url = 'images/generic.png';
    600     elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') )
     600    } elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') ) {
    601601        $icon_url = 'https://' . substr($icon_url, 7);
    602 
    603     $menu[] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
    604 
     602    }
     603
     604    $new_menu = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
     605
     606    if ( NULL === $position  ) {
     607        $menu[] = $new_menu;
     608    } else {
     609        $menu[$position] = $new_menu;
     610    }
     611   
    605612    $_registered_pages[$hookname] = true;
    606613
     
    609616
    610617function add_object_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '') {
    611     global $menu, $admin_page_hooks, $_wp_last_object_menu, $_registered_pages;
    612 
    613     $file = plugin_basename( $file );
    614 
    615     $admin_page_hooks[$file] = sanitize_title( $menu_title );
    616 
    617     $hookname = get_plugin_page_hookname( $file, '' );
    618     if (!empty ( $function ) && !empty ( $hookname ))
    619         add_action( $hookname, $function );
    620 
    621     if ( empty($icon_url) )
    622         $icon_url = 'images/generic.png';
    623     elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') )
    624         $icon_url = 'https://' . substr($icon_url, 7);
    625 
     618    global $_wp_last_object_menu;
     619   
    626620    $_wp_last_object_menu++;
    627 
    628     $menu[$_wp_last_object_menu] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
    629 
    630     $_registered_pages[$hookname] = true;
    631 
    632     return $hookname;
     621   
     622    return add_menu_page($page_title, $menu_title, $access_level, $file, $function, $icon_url, $_wp_last_object_menu);
    633623}
    634624
    635625function add_utility_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '') {
    636     global $menu, $admin_page_hooks, $_wp_last_utility_menu, $_registered_pages;
    637 
    638     $file = plugin_basename( $file );
    639 
    640     $admin_page_hooks[$file] = sanitize_title( $menu_title );
    641 
    642     $hookname = get_plugin_page_hookname( $file, '' );
    643     if (!empty ( $function ) && !empty ( $hookname ))
    644         add_action( $hookname, $function );
    645 
    646     if ( empty($icon_url) )
    647         $icon_url = 'images/generic.png';
    648     elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') )
    649         $icon_url = 'https://' . substr($icon_url, 7);
    650 
     626    global $_wp_last_utility_menu;
     627   
    651628    $_wp_last_utility_menu++;
    652 
    653     $menu[$_wp_last_utility_menu] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
    654 
    655     $_registered_pages[$hookname] = true;
    656 
    657     return $hookname;
     629   
     630    return add_menu_page($page_title, $menu_title, $access_level, $file, $function, $icon_url, $_wp_last_utility_menu);
    658631}
    659632
Note: See TracChangeset for help on using the changeset viewer.