Created
November 10, 2014 18:58
-
-
Save rodrigoea/c853a1f89156147fd93c to your computer and use it in GitHub Desktop.
Show bubble notification in Wordpress Menu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'add_menu_classes', 'show_pending_number'); | |
function show_pending_number( $menu ) { | |
$type = "post_type"; | |
$status = "draft"; | |
$num_posts = wp_count_posts( $type, 'readable' ); | |
$pending_count = 0; | |
if ( !empty($num_posts->$status) ) | |
$pending_count = $num_posts->$status; | |
// build string to match in $menu array | |
if ($type == 'post') { | |
$menu_str = 'edit.php'; | |
} else { | |
$menu_str = 'edit.php?post_type=' . $type; | |
} | |
// loop through $menu items, find match, add indicator | |
foreach( $menu as $menu_key => $menu_data ) { | |
if( $menu_str != $menu_data[2] ) | |
continue; | |
$menu[$menu_key][0] .= " <span class='update-plugins count-$pending_count'><span class='plugin-count'>" . number_format_i18n($pending_count) . '</span></span>'; | |
} | |
return $menu; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment