How to add notification bubble for my custom admin menu page

OK, so it has nothing to do with WP_List_Table, to be precise. All you need to do is to add some additional info during registration of your custom admin page.

There are two classes used by WordPress to display these notification bubbles:

  • update-plugins
  • awaiting-mod

Your notifications have nothing to do with plugins, so it will be nicer to use the second class. You should change your function like this:

function contact_form_create() {
    $notification_count = 2; // <- here you should get correct count of forms submitted since last visit

    add_menu_page(
        'Contact Forms',
        $notification_count ? sprintf('Contact Forms <span class="awaiting-mod">%d</span>', $notification_count) : 'Contact Forms',
        'administrator', // <- it would be nicer to use capability in here 'manage_options' 
        'contact-form',
        'contact_form_page_handler'
    );
}

add_action('admin_menu', 'contact_form_create');

So the main change is that if there are some notifications to show, then we add <span class="awaiting-mod">%d</span> to title of that page.

The only thing you’ll have to do now is to get correct number of form submits since last visit. The easiest way to do this would be store last ID of submited form record in your custom DB table as some option and counting new records based on this ID. But it’s hard to say exactly how to count them, since I have no info about how you store this submitted forms and so on, so I leave this part to you.

Leave a Comment