Halloween Sale 15% off Ends in See the plans
PHP

Pending Updates Summary Widget

Adds a dashboard widget showing how many WordPress, plugin, theme and translation updates are waiting, with the names of the plugins and a link to install them.

Don’t have WPIDE yet? Install it on your site

Code

add_action( 'wp_dashboard_setup', function () {
    if ( ! current_user_can( 'update_plugins' ) ) {
        return;
    }

    wp_add_dashboard_widget( 'wpide_pending_updates', 'Pending updates', function () {
        $plugins      = get_site_transient( 'update_plugins' );
        $themes       = get_site_transient( 'update_themes' );
        $core         = get_site_transient( 'update_core' );
        $plugin_list  = ! empty( $plugins->response ) ? $plugins->response : array();
        $theme_count  = ! empty( $themes->response ) ? count( $themes->response ) : 0;
        $core_update  = ! empty( $core->updates[0] ) && 'upgrade' === $core->updates[0]->response;
        $translations = count( wp_get_translation_updates() );

        if ( ! $plugin_list && ! $theme_count && ! $core_update && ! $translations ) {
            echo '<p><span class="dashicons dashicons-yes-alt" style="color:#00a32a" aria-hidden="true"></span> Everything is up to date.</p>';
            return;
        }

        echo '<ul>';
        if ( $core_update ) {
            printf( '<li><strong>WordPress %s</strong> is available.</li>', esc_html( $core->updates[0]->version ) );
        }
        if ( $plugin_list ) {
            if ( ! function_exists( 'get_plugins' ) ) {
                require_once ABSPATH . 'wp-admin/includes/plugin.php';
            }
            $all   = get_plugins();
            $names = array();
            foreach ( $plugin_list as $file => $update ) {
                $names[] = ( $all[ $file ]['Name'] ?? $file ) . ' ' . $update->new_version;
            }
            printf( '<li><strong>%d plugin updates:</strong> %s</li>', count( $plugin_list ), esc_html( implode( ', ', $names ) ) );
        }
        if ( $theme_count ) {
            printf( '<li><strong>%d theme updates</strong></li>', (int) $theme_count );
        }
        if ( $translations ) {
            printf( '<li><strong>%d translation updates</strong></li>', (int) $translations );
        }
        echo '</ul>';
        printf( '<p><a class="button button-primary" href="%s">Go to updates</a></p>', esc_url( admin_url( 'update-core.php' ) ) );
    } );
} );

Notes

Uses the update data WordPress already checks twice a day, so it adds no remote requests.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.