i need to get a list of all updates the wp site need (core, plugin and themes). i already know about wp_get_update_data(), but it give me back only the number. i need to get for example:

plugin1 | actual version | new version

plugin2 | actual version | new version

theme1 | actual version | new version

wp | actual version | new version

how can i save that information into some arrays to use them?

edit:
i managed to do this with what i found but it doesn’t work, it print to try only test

function data_report()
{
    // Get theme info
    $theme_data = wp_get_theme();
    $theme = $theme_data->Name . ' ' . $theme_data->Version;

    // Get plugins that have an update
    $updates = get_plugin_updates();

    // WordPress active plugins
    $fin_plug = "\n" . '-- WordPress Active Plugins' . "\n\n";
    $plugins = get_plugins();
    $active_plugins = get_option('active_plugins', array());
    foreach ($plugins as $plugin_path => $plugin) {
        if (!in_array($plugin_path, $active_plugins)) {
            continue;
        }
        $update = array_key_exists($plugin_path, $updates) ? ' (needs update - ' . $updates[$plugin_path]->update->new_version . ')' : '';
        $fin_plug .= $plugin['Name'] . ': ' . $plugin['Version'] . $update . "\n";
    }

}


add_action( 'wp_footer', 'stampa_prova' );

function stampa_prova (){   
        echo 'test';
        $cospi = data_report();
        echo $cospi;
}

3 Answers
3

When on the admin view you can use the following functions to get update data.

  • get_plugin_updates()
  • get_theme_updates()
  • get_core_updates()

If you want to build your own functions, then you can get update related data from site transients update_themes, update_plugins, and update_core. Then you can compare the plugin and theme transients with the theme and plugin arrays you can get with wp_get_themes() and get_plugins(). The above functions are more or less wrappers for these transients and functions.

Have a look at the source for the functions to see how WP handles this stuff.

Leave a Reply

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