Admin menu and toolbar hacks
-
Hi all! I’ve spent the last few days googling trying to solve this but I haven’t been able to do so…
1- In wp-admin, under posts on the left menu, I would like to add a submenu item that shows the posts filtered by a category. I have made the same for drafts, and tweaked the code to achieve this, but it isn’t working. Currently it displays all the posts.
// Add menu item for categories function add_cat_admin_menu_item() { // $page_title, $menu_title, $capability, $menu_slug, $callback_function add_posts_page(__('category1'), __('category1'), 'read', 'edit.php?post_type=post&post_category=34'); } add_action('admin_menu', 'add_cat_admin_menu_item');
2- When logged in, I can see the admin toolbar on top if I am on a post. I would like to see it everywhere i.e. pages, index… But only if logged in, not for unregistered users/visitors.
Everything I find on this is how to completely disable the toolbar…3- Once I have the toolbar visible, I would like to add a “button” or “section” that, if there are drafts, will display “Drafts X”, being X the count of drafts (just like when there are plugin updates). If there are no drafts, that “button” should not show up.
I achieved this on the wp-admin menu with this snippet, but can’t figure out how to do it on the toolbarif(!class_exists('KWM_Pending_Posts_Indicator')) { class KWM_Pending_Posts_Indicator { function KWM_Pending_Posts_Indicator() { } function show_pending_number($menu) { $num_posts = wp_count_posts( 'post', 'readable' ); $status = "draft"; $pending_count = 0; if ( !empty($num_posts->$status) ) $pending_count = $num_posts->$status; foreach ( $GLOBALS['menu'] as $menuKey => $menuitem ) { if( $menuitem[1] == 'edit_posts') { // Use 'plugins' classes for now. May add specific ones to this later. $menu[$menuKey][0] = sprintf( __('Posts %s'), "<span class='update-plugins count-$pending_count'><span class='plugin-count'>" . number_format_i18n($pending_count) . "</span></span>"); break; } } return $menu; } } } add_filter('add_menu_classes', array('KWM_Pending_Posts_Indicator', 'show_pending_number'), 8);
Thanks for the help!!
- The topic ‘Admin menu and toolbar hacks’ is closed to new replies.