In the admin bar, there is an icon that will tell you if there are plugin updates. Whenever you hover over it, it will say something like “1 plugin update”. You have to click on it to go to the update page, where you will see which plugin needs an update.

I’m too lazy to do that. I would like to have a list of the plugins that need an update in the title tag of the icon. This would give me a clue about how critical the update is (yes, I know I should update all plugins all the time, but I prefer to give priority to security plugins over, say, SEO).

So what I would like to know is:

1 How do I access the list of available updates?

2 How do I deliver this information to the update icon in the admin bar?

1 Answer
1

Here’s the code that extracts update plugin information with get_plugin_updates and wrestles some info from the returned objects, which sadly do not contain changelog information. A node is created in the admin bar for every available update.

I suppose I could expand this to a plugin that also lists core, theme and translation updates if anyone is interested.

add_action( 'admin_bar_menu', 'wpse_228026_toolbar_show_updates', 999 );

function wpse_228026_toolbar_show_updates ($wp_admin_bar) {
    if (!function_exists('get_plugin_updates')) require_once ABSPATH . 'wp-admin/includes/update.php';
    $plugin_updates = get_plugin_updates();
    foreach ($plugin_updates as $update) {
        $args = array(
            'id'            => $update->update->slug,
            'title'         => 'Plugin update: ' . $update->Name,
            'parent'        => 'updates',
            'meta'          => array( 
                                'class' => 'update-available ' . $update->update->slug,
                                'title' => 'Current version: ' . $update->Version . ' | ' . 'New version: ' . $update->update->new_version)
            );
        $wp_admin_bar->add_node( $args );
        }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *