Make WordPress Core

Changeset 13579


Ignore:
Timestamp:
03/04/2010 12:15:55 AM (17 years ago)
Author:
ryan
Message:

Fix submenus for post types. Props TobiasBg. see #12453

Location:
trunk/wp-admin
Files:
5 edited

Legend:

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

    r12982 r13579  
    7373$editing = false;
    7474
    75 if (isset($_GET['page'])) {
     75if ( isset($_GET['page']) ) {
    7676        $plugin_page = stripslashes($_GET['page']);
    7777        $plugin_page = plugin_basename($plugin_page);
    7878}
     79
     80if ( isset($_GET['post_type']) )
     81        $typenow = sanitize_user($_GET['post_type'], true);
     82else
     83        $typenow = '';
    7984
    8085require(ABSPATH . 'wp-admin/menu.php');
     
    8287do_action('admin_init');
    8388
    84 if (isset($plugin_page) ) {
    85         if ( ! $page_hook = get_plugin_page_hook($plugin_page, $pagenow) ) {
     89if ( isset($plugin_page) ) {
     90        if ( !empty($typenow) )
     91                $the_parent = $pagenow . '?post_type=' . $typenow;
     92        else
     93                $the_parent = $pagenow;
     94        if ( ! $page_hook = get_plugin_page_hook($plugin_page, $the_parent) ) {
    8695                $page_hook = get_plugin_page_hook($plugin_page, $plugin_page);
    8796                // backwards compatibility for plugins using add_management_page
     
    96105                }
    97106        }
     107        unset($the_parent);
    98108}
    99109
     
    105115else if ( isset($pagenow) )
    106116        $hook_suffix = $pagenow;
    107 
    108 if ( isset($_GET['post_type']) )
    109         $typenow = $_GET['post_type'];
    110 else
    111         $typenow = '';
    112 // @todo validate typenow against post types.
    113117
    114118set_current_screen();
  • trunk/wp-admin/includes/plugin.php

    r13256 r13579  
    818818
    819819        $hookname = get_plugin_page_hookname( $menu_slug, '' );
     820
    820821        if (!empty ( $function ) && !empty ( $hookname ) && current_user_can( $capability ) )
    821822                add_action( $hookname, $function );
     
    11681169        global $submenu;
    11691170        global $pagenow;
     1171        global $typenow;
    11701172        global $plugin_page;
    11711173        global $_wp_real_parent_file;
     
    12161218                        if ( isset( $_wp_real_parent_file[$parent] ) )
    12171219                                $parent = $_wp_real_parent_file[$parent];
    1218                         if ( $submenu_array[2] == $pagenow && ( empty($parent_file) || false === strpos($parent_file, '?') ) ) {
     1220                        if ( !empty($typenow) && ($submenu_array[2] == "$pagenow?post_type=$typenow") ) {
     1221                                $parent_file = $parent;
     1222                                return $parent;
     1223                        } elseif ( $submenu_array[2] == $pagenow && empty($typenow) && ( empty($parent_file) || false === strpos($parent_file, '?') ) ) {
    12191224                                $parent_file = $parent;
    12201225                                return $parent;
     
    13271332        }
    13281333
     1334
    13291335        $plugin_name = preg_replace( '!\.php!', '', $plugin_page );
    13301336
     
    13511357
    13521358                $hookname = get_plugin_page_hookname($plugin_page, $parent);
     1359
    13531360                if ( !isset($_registered_pages[$hookname]) )
    13541361                        return false;
  • trunk/wp-admin/includes/template.php

    r13576 r13579  
    39483948                $current_screen->id = $typenow;
    39493949                $current_screen->post_type = $typenow;
    3950         } else {
    3951                 $typenow = '';
    39523950        }
    39533951
  • trunk/wp-admin/menu-header.php

    r12733 r13579  
    3434 */
    3535function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
    36         global $self, $parent_file, $submenu_file, $plugin_page, $pagenow;
     36        global $self, $parent_file, $submenu_file, $plugin_page, $pagenow, $typenow;
    3737
    3838        $first = true;
     
    4848                        $class[] = 'wp-has-submenu';
    4949
    50                 if ( ( $parent_file && $item[2] == $parent_file ) || ( false === strpos($parent_file, '?') && strcmp($self, $item[2]) == 0 ) ) {
     50                if ( ( $parent_file && $item[2] == $parent_file ) || ( false === strpos($parent_file, '?') && $self == $item[2] ) ) {
    5151                        if ( !empty($submenu[$item[2]]) )
    5252                                $class[] = 'wp-has-current-submenu wp-menu-open';
     
    113113
    114114                                $menu_file = $item[2];
     115
    115116                                if ( false !== $pos = strpos($menu_file, '?') )
    116117                                        $menu_file = substr($menu_file, 0, $pos);
     118
     119                                // Handle current for post_type=post|page|foo pages, which won't match $self.
     120                                if ( !empty($typenow) )
     121                                        $self_type = $self . '?post_type=' . $typenow;
     122                                else
     123                                        $self_type = 'nothing';
    117124
    118125                                if ( isset($submenu_file) ) {
     
    121128                                // If plugin_page is set the parent must either match the current page or not physically exist.
    122129                                // This allows plugin pages with the same hook to exist under different parents.
    123                                 } else if ( (isset($plugin_page) && $plugin_page == $sub_item[2] && (!file_exists($menu_file) || ($item[2] == $self))) || (!isset($plugin_page) && $self == $sub_item[2]) ) {
     130                                } else if ( (isset($plugin_page) && $plugin_page == $sub_item[2] && (!file_exists($menu_file) || ($item[2] == $self) || ($item[2] == $self_type))) || (!isset($plugin_page) && $self == $sub_item[2]) ) {
    124131                                        $class[] = 'current';
    125132                                }
     
    134141                                if ( ( ('index.php' != $sub_item[2]) && file_exists(WP_PLUGIN_DIR . "/$sub_file") ) || ! empty($menu_hook) ) {
    135142                                        // If admin.php is the current page or if the parent exists as a file in the plugins or admin dir
    136 
    137                                         $parent_exists = (!$admin_is_parent && file_exists(WP_PLUGIN_DIR . "/$menu_file") && !is_dir(WP_PLUGIN_DIR . "/{$item[2]}") ) || file_exists($menu_file);
    138                                         if ( $parent_exists )
    139                                                 echo "<li$class><a href='{$item[2]}?page={$sub_item[2]}'$class$tabindex>{$sub_item[0]}</a></li>";
    140                                         elseif ( 'admin.php' == $pagenow || !$parent_exists )
    141                                                 echo "<li$class><a href='admin.php?page={$sub_item[2]}'$class$tabindex>{$sub_item[0]}</a></li>";
     143                                        if ( (!$admin_is_parent && file_exists(WP_PLUGIN_DIR . "/$menu_file") && !is_dir(WP_PLUGIN_DIR . "/{$item[2]}")) || file_exists($menu_file) )
     144                                                $sub_item_url = add_query_arg( array('page' => $sub_item[2]), $item[2] );
    142145                                        else
    143                                                 echo "<li$class><a href='{$item[2]}?page={$sub_item[2]}'$class$tabindex>{$sub_item[0]}</a></li>";
     146                                                $sub_item_url = add_query_arg( array('page' => $sub_item[2]), 'admin.php' );
     147                                        echo "<li$class><a href='$sub_item_url'$class$tabindex>{$sub_item[0]}</a></li>";
    144148                                } else {
    145149                                        echo "<li$class><a href='{$sub_item[2]}'$class$tabindex>{$sub_item[0]}</a></li>";
  • trunk/wp-admin/menu.php

    r13533 r13579  
    178178// Create list of page plugin hook names.
    179179foreach ($menu as $menu_page) {
    180         $hook_name = sanitize_title(basename($menu_page[2], '.php'));
     180        if ( false !== $pos = strpos($menu_page[2], '?') ) {
     181                // Handle post_type=post|page|foo pages.
     182                $hook_name = substr($menu_page[2], 0, $pos);
     183                $hook_args = substr($menu_page[2], $pos + 1);
     184                wp_parse_str($hook_args, $hook_args);
     185                // Set the hook name to be the post type.
     186                if ( isset($hook_args['post_type']) )
     187                        $hook_name = $hook_args['post_type'];
     188                else
     189                        $hook_name = basename($hook_name, '.php');
     190                unset($hook_args);
     191        } else {
     192                $hook_name = basename($menu_page[2], '.php');
     193        }
     194        $hook_name = sanitize_title($hook_name);
    181195
    182196        // ensure we're backwards compatible
     
    184198                'index' => 'dashboard',
    185199                'edit' => 'posts',
     200                'post' => 'posts',
    186201                'upload' => 'media',
    187202                'link-manager' => 'links',
    188203                'edit-pages' => 'pages',
     204                'page' => 'pages',
    189205                'edit-comments' => 'comments',
    190206                'options-general' => 'settings',
Note: See TracChangeset for help on using the changeset viewer.