10

I am having an issue finding out how to display the number of plugins/updates available to call somewhere else other than the admin header. I found the function wp_get_update_data should be what I need:

How is the " wp_get_update_data " function used?

However, I wasn't sure how to get this to display as an actual count of the total plugins and updates available or any working example on the internet of how to use it.

Any suggestions would be much appreciated.

2 Answers 2

10

Here's an example of the data returned from the wp_get_update_data() function:

Array
(
    [counts] => Array
        (
            [plugins] => 3
            [themes] => 2
            [wordpress] => 0
            [translations] => 0
            [total] => 5
        )

    [title] => 3 Plugin Updates, 2 Theme Updates
)

So the number of available plugin updates should be available with:

// Number of available plugin updates:
$update_data = wp_get_update_data();
echo $update_data['counts']['plugins'];

Update:

To display the following plugin info in the admin area:

There are available updates for 3 plugins out of 22

we can additionally use the get_plugins() function:

if ( ! function_exists( 'get_plugins' ) )
{
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

$data = array( 
    'updates'   =>  $update_data['counts']['plugins'],
    'total'     =>  count( get_plugins() ),
);

printf( 
    "There are available updates for <strong>%d</strong> plugins  
     out of <strong>%d</strong>",
    $data['updates'],
    $data['total']
);

We can add more info, in a similar way, with get_mu_plugins() and get_dropins().

3
  • 1
    Sorry, but I had to undelete your answer. It adds slightly different information and clearly has its value. I hope you understand that.
    – kaiser
    Commented Aug 18, 2014 at 16:46
  • @kaiser if you say so ;-) I updated the answer to make it a little bit different from the other one.
    – birgire
    Commented Aug 18, 2014 at 18:37
  • 1
    Worked perfectly, thank you for taking the time to explain in more detail!
    – Tom
    Commented Aug 18, 2014 at 22:08
6

wp_get_update_data() returns an array in this format

  • counts
    • plugins
    • themes
    • wordpress
    • translations
    • total
  • title

So, if you want total count, you need to use it like this

$updates = wp_get_update_data();
echo $updates['counts']['total'];
2
  • 1
    You just beat me to it by few seconds, so I will remove my answer (+1)
    – birgire
    Commented Aug 18, 2014 at 16:38
  • @birgire Great sportmanship. +1 Commented Aug 18, 2014 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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