3

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?

  • I know there is a function get_plugin_updates(), but I have difficulty reading the source code as how to extract the plugin names. I also know how I could deliver the information as a menu item, but I would like to have it in the title tag (I could do this with javascript, but maybe there's is a hook I'm not aware of) – cjbj May 27 '16 at 16:13
  • 1
    You've got the answer already. loop through the list $list = get_plugin_updates(); foreach( $list as $item ) { print_r( $item->Name ); }.. – Samuel Elh May 27 '16 at 16:20
  • 1
    I feel your pain, but I don't think that a list of plugins without a changelog will actually help you much – Mark Kaplun May 27 '16 at 16:20
  • 1
    @MarkKaplun That would be true if the changelog was always meaningful (or, hey, I'll include the changelog in the title tag). Basically, I just want to know if there is an update to my security plugin and postpone the rest. – cjbj May 27 '16 at 16:28
0

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 );
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.