Wordpress - The Great WordPress Admin Menu Challenge of Jan 2011 (a.k.a. How to Resolve Some Challenges when Modifying the WordPress Admin Menu System?)

Mike, I've taken a look at the code and your ideal end use case ... and some of them, frankly, aren't possible with the current system. Again, your requirements:

  1. Get the "Microsite" submenu page to be highlighted when editing an Attorney
  2. Get the Attorney Menu Page link to link to /wp-admin/edit.php?post_type=attorney when editing an Attorney
  3. Get the "Microsite" link not to trigger a "You do not have sufficient permissions to access this page" error

And the key issue here is #2.

What I tried

I tried adding a custom post type for Attorneys and was immediately reminded that /wp-admin/edit.php?post_type=attorney will give you a list of attorneys, not an actual edit screen. The actual editing take place on /wp-admin/post.php?post=10&action=edit. So if you're really tied to #2 ... the other two criteria won't work.

This is why #3 fails in implementation ... and I wasn't even able to attempt #1 because I couldn't get that far.


Hey Mike, your issue #3 is due to you specifying ($microsite, 'the_microsite_editor'), where it should be (__CLASS__, 'the_microsite_editor').

Update: After spending way too much time trying to solve some similar trouble for my own plugin, here's something I found that may help with your Challenge (note that the functions are methods underneath your class):

function add_posttype_submenu_page($mytype, $label, $cap, $slug) {  
    /* we add two submenu pages to work around the 
       edit.php?post_type=...&page=...problem and have 
       our page called as admin.php?page=... instead */
    //first create a 'blind' pseudo-entry to register our page callback
    add_submenu_page($mytype, $label, $label, $cap, $slug, 
                     array( &$this, 'admin_'.$mytype ));
    //then create a real entry that 'calls' our pseudo-entry
    add_submenu_page('edit.php?post_type='.$mytype, $label, 
                     $label, $cap, 'admin.php?page='.$slug);
    /* then lets fix/hack the highlighting */
    global $plugin_page;
    global $submenu_file;
    if ($plugin_page == $slug) {
        // this next line highlights the submenu entry
        $submenu_file = 'admin.php?page='.$slug; 
        add_filter('parent_file', 
                   array(&$this, 'evil_parent_file_hack'));
    }
} 

function evil_parent_file_hack() {
    //we do this to get the parent menu properly highlighted, too
    //it only gets called on the submenu menu page in question
    global $self;
    global $parent_file;
    $self = $parent_file;
    remove_filter('parent_file', array(&$this, 'evil_parent_file_hack'));
}

Then you simply call add_posttype_submenu_page() with the according parameters. This should properly add a submenu item to a menu that was auto-created during a register_post_type() call.

Tags:

Admin Menu