Make WordPress Core

Changeset 2381


Ignore:
Timestamp:
02/25/2005 04:11:27 PM (21 years ago)
Author:
ryan
Message:

Add callback API to add_menu_page(). Fix some menu bugs. http://mosquito.wordpress.org/view.php?id=975 Reviewed by Owen.

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r2346 r2381  
    745745function get_admin_page_parent() {
    746746        global $parent_file;
     747        global $menu;
    747748        global $submenu;
    748749        global $pagenow;
     
    753754        }
    754755
     756        if ($pagenow == 'admin.php' && isset($plugin_page)) {
     757                foreach ($menu as $parent_menu) {
     758                        if ($parent_menu[2] == $plugin_page) {
     759                                $parent_file = $plugin_page;
     760                                return $plugin_page;
     761                        }
     762                }
     763        }
     764               
    755765        foreach (array_keys($submenu) as $parent) {
    756766                foreach ($submenu[$parent] as $submenu_array) {
     
    770780
    771781function plugin_basename($file) {
    772         return preg_replace('#^.*wp-content/plugins/#', '', $file);
    773 }
    774 
    775 function add_menu_page($page_title, $menu_title, $access_level, $file) {
     782        return preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', $file);
     783}
     784
     785function add_menu_page($page_title, $menu_title, $access_level, $file, $function = '') {
    776786        global $menu, $admin_page_hooks;
    777787
     
    781791
    782792        $admin_page_hooks[$file] = sanitize_title($menu_title);
     793
     794        $hookname = get_plugin_page_hookname($file, '');
     795        if ( !empty($function) && !empty($hookname) )
     796                add_action($hookname, $function);
     797
     798        return $hookname;
    783799}
    784800
     
    10151031        global $admin_page_hooks;
    10161032
    1017         if ( isset($admin_page_hooks[$parent_page]) )
     1033        $parent = get_admin_page_parent();
     1034
     1035        if ( empty($parent_page) || 'admin.php' == $parent_page ) {
     1036                if ( isset($admin_page_hooks[$plugin_page]) )
     1037                        $page_type = 'toplevel';
     1038                else if ( isset($admin_page_hooks[$parent]) )
     1039                        $page_type = $admin_page_hooks[$parent];
     1040        } else if ( isset($admin_page_hooks[$parent_page]) ) {
    10181041                $page_type = $admin_page_hooks[$parent_page];
    1019         else
     1042        } else {
    10201043                $page_type = 'admin';
     1044        }
    10211045
    10221046        $plugin_name = preg_replace('!\.php!', '', $plugin_page);
     
    10271051function get_plugin_page_hook($plugin_page, $parent_page) {
    10281052        global $wp_filter;
    1029 
     1053       
    10301054        $hook = get_plugin_page_hookname($plugin_page, $parent_page);
    1031 
    10321055        if ( isset($wp_filter[$hook]) )
    10331056                return $hook;
  • trunk/wp-admin/menu-header.php

    r2362 r2381  
    4040else $class = '';
    4141
    42 if (file_exists(ABSPATH . "wp-content/plugins/{$item[2]}")) {
    43         $menu_hook = get_plugin_page_hook($item[2], $parent_file);
    44         if ( $menu_hook )
    45                 echo "\n\t<li><a href='" . get_settings('siteurl') . "/wp-admin/{$parent_file}?page={$item[2]}'$class>{$item[0]}</a></li>";             
     42$menu_hook = get_plugin_page_hook($item[2], $parent_file);
     43
     44if (file_exists(ABSPATH . "wp-content/plugins/{$item[2]}") || ! empty($menu_hook)) {
     45        if ( 'admin.php' == $pagenow )
     46                echo "\n\t<li><a href='" . get_settings('siteurl') . "/wp-admin/admin.php?page={$item[2]}'$class>{$item[0]}</a></li>";
    4647        else
    47                 echo "\n\t<li><a href='" . get_settings('siteurl') . "/wp-admin/admin.php?page={$item[2]}'$class>{$item[0]}</a></li>";
     48                echo "\n\t<li><a href='" . get_settings('siteurl') . "/wp-admin/{$parent_file}?page={$item[2]}'$class>{$item[0]}</a></li>";
    4849 } else {
    4950        echo "\n\t<li><a href='" . get_settings('siteurl') . "/wp-admin/{$item[2]}'$class>{$item[0]}</a></li>";
Note: See TracChangeset for help on using the changeset viewer.