| 1 | Index: admin-functions.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | RCS file: /cvsroot/cafelog/wordpress/wp-admin/admin-functions.php,v |
|---|
| 4 | retrieving revision 1.78 |
|---|
| 5 | diff -u -r1.78 admin-functions.php |
|---|
| 6 | --- admin-functions.php 1 Feb 2005 06:59:44 -0000 1.78 |
|---|
| 7 | +++ admin-functions.php 6 Feb 2005 06:35:09 -0000 |
|---|
| 8 | @@ -773,14 +773,16 @@ |
|---|
| 9 | } |
|---|
| 10 | |
|---|
| 11 | function add_menu_page($page_title, $menu_title, $access_level, $file) { |
|---|
| 12 | - global $menu; |
|---|
| 13 | + global $menu, $admin_page_hooks; |
|---|
| 14 | |
|---|
| 15 | $file = plugin_basename($file); |
|---|
| 16 | |
|---|
| 17 | $menu[] = array($menu_title, $access_level, $file, $page_title); |
|---|
| 18 | + |
|---|
| 19 | + $admin_page_hooks[$file] = sanitize_title($menu_title); |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | -function add_submenu_page($parent, $page_title, $menu_title, $access_level, $file) { |
|---|
| 23 | +function add_submenu_page($parent, $page_title, $menu_title, $access_level, $file, $function = '') { |
|---|
| 24 | global $submenu; |
|---|
| 25 | global $menu; |
|---|
| 26 | |
|---|
| 27 | @@ -800,14 +802,20 @@ |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | $submenu[$parent][] = array($menu_title, $access_level, $file, $page_title); |
|---|
| 31 | + |
|---|
| 32 | + $hookname = get_plugin_page_hookname($file, $parent); |
|---|
| 33 | + if ( !empty($function) && !empty($hookname) ) |
|---|
| 34 | + add_action($hookname, $function); |
|---|
| 35 | + |
|---|
| 36 | + return $hookname; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | -function add_options_page($page_title, $menu_title, $access_level, $file) { |
|---|
| 40 | - add_submenu_page('options-general.php', $page_title, $menu_title, $access_level, $file); |
|---|
| 41 | +function add_options_page($page_title, $menu_title, $access_level, $file, $function = '') { |
|---|
| 42 | + return add_submenu_page('options-general.php', $page_title, $menu_title, $access_level, $file, $function); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | -function add_management_page($page_title, $menu_title, $access_level, $file) { |
|---|
| 46 | - add_submenu_page('edit.php', $page_title, $menu_title, $access_level, $file); |
|---|
| 47 | +function add_management_page($page_title, $menu_title, $access_level, $file, $function = '') { |
|---|
| 48 | + return add_submenu_page('edit.php', $page_title, $menu_title, $access_level, $file, $function); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | function validate_file($file, $allowed_files = '') { |
|---|
| 52 | @@ -999,4 +1007,28 @@ |
|---|
| 53 | return $wp_plugins; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | +function get_plugin_page_hookname($plugin_page, $parent_page) { |
|---|
| 57 | + global $admin_page_hooks; |
|---|
| 58 | + |
|---|
| 59 | + if ( isset($admin_page_hooks[$parent_page]) ) |
|---|
| 60 | + $page_type = $admin_page_hooks[$parent_page]; |
|---|
| 61 | + else |
|---|
| 62 | + $page_type = 'admin'; |
|---|
| 63 | + |
|---|
| 64 | + $plugin_name = preg_replace('!\.php!', '', $plugin_page); |
|---|
| 65 | + |
|---|
| 66 | + return $page_type . '_page_' . $plugin_name; |
|---|
| 67 | +} |
|---|
| 68 | + |
|---|
| 69 | +function get_plugin_page_hook($plugin_page, $parent_page) { |
|---|
| 70 | + global $wp_filter; |
|---|
| 71 | + |
|---|
| 72 | + $hook = get_plugin_page_hookname($plugin_page, $parent_page); |
|---|
| 73 | + |
|---|
| 74 | + if ( isset($wp_filter[$hook]) ) |
|---|
| 75 | + return $hook; |
|---|
| 76 | + else |
|---|
| 77 | + return ''; |
|---|
| 78 | +} |
|---|
| 79 | + |
|---|
| 80 | ?> |
|---|
| 81 | Index: admin.php |
|---|
| 82 | =================================================================== |
|---|
| 83 | RCS file: /cvsroot/cafelog/wordpress/wp-admin/admin.php,v |
|---|
| 84 | retrieving revision 1.7 |
|---|
| 85 | diff -u -r1.7 admin.php |
|---|
| 86 | --- admin.php 27 Jan 2005 15:20:47 -0000 1.7 |
|---|
| 87 | +++ admin.php 6 Feb 2005 06:35:10 -0000 |
|---|
| 88 | @@ -41,19 +41,30 @@ |
|---|
| 89 | // Handle plugin admin pages. |
|---|
| 90 | if (isset($_GET['page'])) { |
|---|
| 91 | $plugin_page = plugin_basename($_GET['page']); |
|---|
| 92 | - if ( validate_file($plugin_page) ) { |
|---|
| 93 | - die(__('Invalid plugin page')); |
|---|
| 94 | - } |
|---|
| 95 | - |
|---|
| 96 | - if (! file_exists(ABSPATH . "wp-content/plugins/$plugin_page")) |
|---|
| 97 | - die(sprintf(__('Cannot load %s.'), $plugin_page)); |
|---|
| 98 | + $page_hook = get_plugin_page_hook($plugin_page, $pagenow); |
|---|
| 99 | |
|---|
| 100 | - if (! isset($_GET['noheader'])) |
|---|
| 101 | - require_once(ABSPATH . '/wp-admin/admin-header.php'); |
|---|
| 102 | + if ( $page_hook ) { |
|---|
| 103 | + if (! isset($_GET['noheader'])) |
|---|
| 104 | + require_once(ABSPATH . '/wp-admin/admin-header.php'); |
|---|
| 105 | + |
|---|
| 106 | + do_action($page_hook); |
|---|
| 107 | + } else { |
|---|
| 108 | + if ( validate_file($plugin_page) ) { |
|---|
| 109 | + die(__('Invalid plugin page')); |
|---|
| 110 | + } |
|---|
| 111 | + |
|---|
| 112 | + if (! file_exists(ABSPATH . "wp-content/plugins/$plugin_page")) |
|---|
| 113 | + die(sprintf(__('Cannot load %s.'), $plugin_page)); |
|---|
| 114 | |
|---|
| 115 | - include(ABSPATH . "wp-content/plugins/$plugin_page"); |
|---|
| 116 | + if (! isset($_GET['noheader'])) |
|---|
| 117 | + require_once(ABSPATH . '/wp-admin/admin-header.php'); |
|---|
| 118 | + |
|---|
| 119 | + include(ABSPATH . "wp-content/plugins/$plugin_page"); |
|---|
| 120 | + } |
|---|
| 121 | + |
|---|
| 122 | + include(ABSPATH . 'wp-admin/admin-footer.php'); |
|---|
| 123 | |
|---|
| 124 | - include(ABSPATH . 'wp-admin/admin-footer.php'); |
|---|
| 125 | + exit(); |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | ?> |
|---|
| 129 | \ No newline at end of file |
|---|
| 130 | Index: menu-header.php |
|---|
| 131 | =================================================================== |
|---|
| 132 | RCS file: /cvsroot/cafelog/wordpress/wp-admin/menu-header.php,v |
|---|
| 133 | retrieving revision 1.4 |
|---|
| 134 | diff -u -r1.4 menu-header.php |
|---|
| 135 | --- menu-header.php 24 Dec 2004 20:55:36 -0000 1.4 |
|---|
| 136 | +++ menu-header.php 6 Feb 2005 06:35:10 -0000 |
|---|
| 137 | @@ -35,14 +35,19 @@ |
|---|
| 138 | continue; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | -if ( (substr($self, -10) == substr($item[2], -10)) || (isset($plugin_page) && $plugin_page == $item[2]) ) $class = ' class="current"'; |
|---|
| 142 | +if ( (isset($plugin_page) && $plugin_page == $item[2]) || (!isset($plugin_page) && substr($self, -10) == substr($item[2], -10)) ) $class = ' class="current"'; |
|---|
| 143 | else if (isset($submenu_file) && $submenu_file == substr($item[2], -10)) $class = ' class="current"'; |
|---|
| 144 | else $class = ''; |
|---|
| 145 | |
|---|
| 146 | -if (file_exists(ABSPATH . "wp-content/plugins/{$item[2]}")) |
|---|
| 147 | - echo "\n\t<li><a href='" . get_settings('siteurl') . "/wp-admin/admin.php?page={$item[2]}'$class>{$item[0]}</a></li>"; |
|---|
| 148 | - else |
|---|
| 149 | +if (file_exists(ABSPATH . "wp-content/plugins/{$item[2]}")) { |
|---|
| 150 | + $page_hook = get_plugin_page_hook($item[2], $parent_file); |
|---|
| 151 | + if ( $page_hook ) |
|---|
| 152 | + echo "\n\t<li><a href='" . get_settings('siteurl') . "/wp-admin/{$parent_file}?page={$item[2]}'$class>{$item[0]}</a></li>"; |
|---|
| 153 | + else |
|---|
| 154 | + echo "\n\t<li><a href='" . get_settings('siteurl') . "/wp-admin/admin.php?page={$item[2]}'$class>{$item[0]}</a></li>"; |
|---|
| 155 | + } else { |
|---|
| 156 | echo "\n\t<li><a href='" . get_settings('siteurl') . "/wp-admin/{$item[2]}'$class>{$item[0]}</a></li>"; |
|---|
| 157 | + } |
|---|
| 158 | endforeach; |
|---|
| 159 | ?> |
|---|
| 160 | |
|---|
| 161 | Index: menu.php |
|---|
| 162 | =================================================================== |
|---|
| 163 | RCS file: /cvsroot/cafelog/wordpress/wp-admin/menu.php,v |
|---|
| 164 | retrieving revision 1.39 |
|---|
| 165 | diff -u -r1.39 menu.php |
|---|
| 166 | --- menu.php 5 Feb 2005 04:53:19 -0000 1.39 |
|---|
| 167 | +++ menu.php 6 Feb 2005 06:35:10 -0000 |
|---|
| 168 | @@ -48,6 +48,11 @@ |
|---|
| 169 | $submenu['themes.php'][5] = array(__('Themes'), 8, 'themes.php'); |
|---|
| 170 | $submenu['themes.php'][10] = array(__('Theme Editor'), 8, 'theme-editor.php'); |
|---|
| 171 | |
|---|
| 172 | +// Create list of page plugin hook names. |
|---|
| 173 | +foreach ($menu as $menu_page) { |
|---|
| 174 | + $admin_page_hooks[$menu_page[2]] = sanitize_title($menu_page[0]); |
|---|
| 175 | +} |
|---|
| 176 | + |
|---|
| 177 | do_action('admin_menu', ''); |
|---|
| 178 | ksort($menu); // make it all pretty |
|---|
| 179 | |
|---|