Last active
March 25, 2021 13:19
-
-
Save neilbannet/df39198538c522fdce932f1a92f6ca47 to your computer and use it in GitHub Desktop.
Update like notification bubble or pending post count bubble with post type name (Admin 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
<?php | |
// Calculate and display count number with any CPT or PT in admin menu (WordPress) | |
// You can paste this code directly by adding it into your functions.php file or | |
// Add this line of code at the bottom of functions.php file: include( 'notification_bubble.php' ); | |
// Please take a backup of functions.php file first. | |
// last updated on: July/24th/2017 06:30PM (London Time) | |
add_filter( 'add_menu_classes', 'cpt_notification_bubble'); | |
public function cpt_notification_bubble( $menu ) | |
{ | |
$types = array("POST_SLUG_HERE"); //You can provide the name of your post type here .e.g, array("POST_SLUG_HERE","clients") | |
$statuses = array("POST_STATUS_HERE", "draft", "pending"); // Here you can provide the statuses that you want to count and show. | |
foreach ($types as $type) | |
{ | |
$count = 0; | |
foreach ($statuses as $status) | |
{ | |
$num_posts = wp_count_posts( $type, 'readable' ); | |
if ( !empty($num_posts->$status) ) | |
$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-$count'><span class='plugin-count'>" . number_format_i18n($count) . '</span></span>'; | |
} | |
} | |
return $menu; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment