Add count for new registered user in Users tab

Is there a way or hooks that I can use to add counter in Users tab for new registered users like this?. http://prntscr.com/k1bxpn

Answers 1

  • Yes, there is. You can use admin_menu hook to loop through menu items and add span with notification. There are two classes that WP uses for these notifications update-plugins and awaiting-mod. The second one looks more appropriate in this case, I guess...

    Here's some code:

    function add_user_menu_notification() {
        global $menu;
    
        $user_count = count_users();  // get whatever count you need
        $user_count = $user_count['avail_roles']['administrator'];
    
        if ( $user_count ) {
            foreach ( $menu as $key => $value ) {
                if ( $menu[$key][2] == 'users.php' ) {
                    $menu[$key][0] .= ' <span class="awaiting-mod">' . $user_count . '</span>';
                    return;
                }
            }
        }
    }
    add_action( 'admin_menu', 'add_user_menu_notification' );
    

Related Questions