Displaying the number of updates available in the Admin area

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 s
2

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
        )

    Displaying the number of updates available in the Admin area => 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().

Leave a Comment