getherbert / herbert

The WordPress Plugin Framework:
http://getherbert.com/
631 stars 94 forks source link

How to add a cpt as a sub-panel? #128

Open JunaidQadirB opened 8 years ago

JunaidQadirB commented 8 years ago

My plugin uses Custom Post Type and when I register a CPT, it's added outside of the plugin panel. How can i move it to a subpanel?

jeremyzahner commented 8 years ago

@JeyKeu Could you provide us with some further explanations (or either screenshots) on what exactly you mean?

moazam1 commented 8 years ago

@JeyKeu I guess you have figured this out. If not try this: https://developer.wordpress.org/reference/functions/add_menu_page/

moazam1 commented 8 years ago

Sorry, ignore above message. Here is the complete example:

function add_manage_posts_link_for_YOUR_POST_TYPE() {
    global $submenu;
    $permalink = admin_url( 'edit.php' ).'?post_type=YOUR_POST_TYPE';
    $submenu['YOUR_MENU_SLUG'][] = array( 'Manage Posts', 'manage_options', $permalink, 'Manage Posts' );
}
add_action('admin_menu', 'add_manage_posts_link_for_YOUR_POST_TYPE');
webstractions commented 7 years ago

I had a similar problem to this. My scenario is that I wanted one Top-level admin menu for three custom post types and two submenu items for a dashboard and settings page. The CPTs were to be listed between the Dashboard and Settings menu items.

I was able to rename the top level to Dashboard and include the settings page. The problem was after including the CPTs, the CPT menu items were pushed to the top of the menu and Dashboard/Settings were at the bottom. I found out this was normal behavior unless you used priorities on your 'admin_menu' filter to a value lower than 10.

I tested this out by modifying a core file in Herbert to a priority of 5, but that pushed both Dashboard and Settings to the top. Hmmmph. I didn't want that, I wanted the CPTs between the Dashboard and Settings menu items.

After a little work, I did come up with a solution. If anyone is interested, I can publish it here. It would also make a nice tutorial. I am not that well versed on markdown, so give me some time to post it.

webstractions commented 7 years ago

I got one thumb on this. Gonna publish on a side note.

webstractions commented 7 years ago

Tutorial is at #175