Ticket #785: plugin_page_hooks.diff
| File plugin_page_hooks.diff, 6.1 kB (added by morganiq, 4 years ago) |
|---|
-
admin-functions.php
old new 773 773 } 774 774 775 775 function add_menu_page($page_title, $menu_title, $access_level, $file) { 776 global $menu ;776 global $menu, $admin_page_hooks; 777 777 778 778 $file = plugin_basename($file); 779 779 780 780 $menu[] = array($menu_title, $access_level, $file, $page_title); 781 782 $admin_page_hooks[$file] = sanitize_title($menu_title); 781 783 } 782 784 783 function add_submenu_page($parent, $page_title, $menu_title, $access_level, $file ) {785 function add_submenu_page($parent, $page_title, $menu_title, $access_level, $file, $function = '') { 784 786 global $submenu; 785 787 global $menu; 786 788 … … 800 802 } 801 803 802 804 $submenu[$parent][] = array($menu_title, $access_level, $file, $page_title); 805 806 $hookname = get_plugin_page_hookname($file, $parent); 807 if ( !empty($function) && !empty($hookname) ) 808 add_action($hookname, $function); 809 810 return $hookname; 803 811 } 804 812 805 function add_options_page($page_title, $menu_title, $access_level, $file ) {806 add_submenu_page('options-general.php', $page_title, $menu_title, $access_level, $file);813 function add_options_page($page_title, $menu_title, $access_level, $file, $function = '') { 814 return add_submenu_page('options-general.php', $page_title, $menu_title, $access_level, $file, $function); 807 815 } 808 816 809 function add_management_page($page_title, $menu_title, $access_level, $file ) {810 add_submenu_page('edit.php', $page_title, $menu_title, $access_level, $file);817 function add_management_page($page_title, $menu_title, $access_level, $file, $function = '') { 818 return add_submenu_page('edit.php', $page_title, $menu_title, $access_level, $file, $function); 811 819 } 812 820 813 821 function validate_file($file, $allowed_files = '') { … … 999 1007 return $wp_plugins; 1000 1008 } 1001 1009 1010 function get_plugin_page_hookname($plugin_page, $parent_page) { 1011 global $admin_page_hooks; 1012 1013 if ( isset($admin_page_hooks[$parent_page]) ) 1014 $page_type = $admin_page_hooks[$parent_page]; 1015 else 1016 $page_type = 'admin'; 1017 1018 $plugin_name = preg_replace('!\.php!', '', $plugin_page); 1019 1020 return $page_type . '_page_' . $plugin_name; 1021 } 1022 1023 function get_plugin_page_hook($plugin_page, $parent_page) { 1024 global $wp_filter; 1025 1026 $hook = get_plugin_page_hookname($plugin_page, $parent_page); 1027 1028 if ( isset($wp_filter[$hook]) ) 1029 return $hook; 1030 else 1031 return ''; 1032 } 1033 1002 1034 ?> -
admin.php
old new 41 41 // Handle plugin admin pages. 42 42 if (isset($_GET['page'])) { 43 43 $plugin_page = plugin_basename($_GET['page']); 44 if ( validate_file($plugin_page) ) { 45 die(__('Invalid plugin page')); 46 } 47 48 if (! file_exists(ABSPATH . "wp-content/plugins/$plugin_page")) 49 die(sprintf(__('Cannot load %s.'), $plugin_page)); 44 $page_hook = get_plugin_page_hook($plugin_page, $pagenow); 50 45 51 if (! isset($_GET['noheader'])) 52 require_once(ABSPATH . '/wp-admin/admin-header.php'); 46 if ( $page_hook ) { 47 if (! isset($_GET['noheader'])) 48 require_once(ABSPATH . '/wp-admin/admin-header.php'); 49 50 do_action($page_hook); 51 } else { 52 if ( validate_file($plugin_page) ) { 53 die(__('Invalid plugin page')); 54 } 55 56 if (! file_exists(ABSPATH . "wp-content/plugins/$plugin_page")) 57 die(sprintf(__('Cannot load %s.'), $plugin_page)); 53 58 54 include(ABSPATH . "wp-content/plugins/$plugin_page"); 59 if (! isset($_GET['noheader'])) 60 require_once(ABSPATH . '/wp-admin/admin-header.php'); 61 62 include(ABSPATH . "wp-content/plugins/$plugin_page"); 63 } 64 65 include(ABSPATH . 'wp-admin/admin-footer.php'); 55 66 56 include(ABSPATH . 'wp-admin/admin-footer.php');67 exit(); 57 68 } 58 69 59 70 ?> -
menu-header.php
old new 35 35 continue; 36 36 } 37 37 38 if ( ( substr($self, -10) == substr($item[2], -10)) || (isset($plugin_page) && $plugin_page == $item[2]) ) $class = ' class="current"';38 if ( (isset($plugin_page) && $plugin_page == $item[2]) || (!isset($plugin_page) && substr($self, -10) == substr($item[2], -10)) ) $class = ' class="current"'; 39 39 else if (isset($submenu_file) && $submenu_file == substr($item[2], -10)) $class = ' class="current"'; 40 40 else $class = ''; 41 41 42 if (file_exists(ABSPATH . "wp-content/plugins/{$item[2]}")) 43 echo "\n\t<li><a href='" . get_settings('siteurl') . "/wp-admin/admin.php?page={$item[2]}'$class>{$item[0]}</a></li>"; 44 else 42 if (file_exists(ABSPATH . "wp-content/plugins/{$item[2]}")) { 43 $page_hook = get_plugin_page_hook($item[2], $parent_file); 44 if ( $page_hook ) 45 echo "\n\t<li><a href='" . get_settings('siteurl') . "/wp-admin/{$parent_file}?page={$item[2]}'$class>{$item[0]}</a></li>"; 46 else 47 echo "\n\t<li><a href='" . get_settings('siteurl') . "/wp-admin/admin.php?page={$item[2]}'$class>{$item[0]}</a></li>"; 48 } else { 45 49 echo "\n\t<li><a href='" . get_settings('siteurl') . "/wp-admin/{$item[2]}'$class>{$item[0]}</a></li>"; 50 } 46 51 endforeach; 47 52 ?> 48 53 -
menu.php
old new 48 48 $submenu['themes.php'][5] = array(__('Themes'), 8, 'themes.php'); 49 49 $submenu['themes.php'][10] = array(__('Theme Editor'), 8, 'theme-editor.php'); 50 50 51 // Create list of page plugin hook names. 52 foreach ($menu as $menu_page) { 53 $admin_page_hooks[$menu_page[2]] = sanitize_title($menu_page[0]); 54 } 55 51 56 do_action('admin_menu', ''); 52 57 ksort($menu); // make it all pretty 53 58
