List Installed Plugin on WP Dashboard

Introduction

Managing a WordPress website can be overwhelming, especially when it comes to keeping track of the plugins. Wouldn’t it be convenient to have a way to list all the installed plugins along with their versions, giving you a quick overview of your site’s health? Well, that’s where the “List Installed Plugin on WP Dashboard” plugin comes in handy. Let’s dive into how this plugin simplifies plugin management on your WordPress dashboard.

Installation Process
1. Upload the zip file
2. Click on "Install Now" and then activate the plugin.
3. Once activated, you will see a new option in your WordPress dashboard to view the list of installed plugins.Code language: PHP (php)
Functionality
- This plugin provides a comprehensive list of all the plugins currently installed on your WordPress website.
- It displays the version of each plugin, allowing you to quickly check if they are up to date.
- The plugin also indicates whether the installed version matches the version available in the WordPress repository, ensuring you stay informed about any updates.Code language: PHP (php)
Benefits
+ Easily track all installed plugins in one centralized location.
+ Save time by avoiding the need to navigate through multiple menus to view plugin information.
+ Stay updated on plugin versions to ensure your website is running smoothly and securely.
+ Enable efficient plugin management by identifying outdated plugins that need attention.

Save the bellow as dashboard_plugin_version_widget.php and then zip it

<?php
/*
	Plugin Name: Plugin Version on dashboard
    Plugin URI: https://tskamath.com/plugins
	Description: List on dashboard all the Installed Plugin and their Version both local and in Repo
	Version: 1.0.1
    Author: Srikanth Kamath
    Authro URI: https://tskamath.com
    
    @package install_plugin_verions        

*/

if ( ! defined( 'ABSPATH' ) ) {
	die( 'We\'re sorry, but you can not directly access this file.' );
}

// Set the MU plugin version.
// dashboard_plugin_version_widget DASHBOARD_PLUGIN_VERSION_WIDGET
// define( 'HEALTH_CHECK_TROUBLESHOOTING_MODE_PLUGIN_VERSION', '1.7.2' );
define( 'DASHBOARD_PLUGIN_VERSION_WIDGET_PLUGIN_VERSION', '1.0.1' );


if(is_admin()) { // make sure, the following code runs in back end

    // returns version of the plugin represented by $slug, from repository
    function getPluginVersionFromRepository($slug) {
        $url = "https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request[slugs][]={$slug}";
        $response = wp_remote_get($url); // WPOrg API call   
        $plugins = json_decode($response['body']);

        // traverse $response object
        foreach($plugins as $key => $plugin) {
        	if(isset($plugin->version)) {
	            $version = $plugin->version;
	        } else {
	        	$version = "No Licence";
	        }
        }
        return $version;
    }

    // dashboard widget's callback
    function activePluginsVersions() {
        $allPlugins = get_plugins(); // associative array of all installed plugins
        $activePlugins = get_option('active_plugins'); // simple array of active plugins

        // building active plugins table
        echo '<table width="100%">';
        echo '<thead>';
        echo '<tr>';
        echo '<th width="50%" style="text-align:left">Plugin</th>';
        echo '<th width="20%" style="text-align:left">currVer</th>';
        echo '<th width="20%" style="text-align:left">repoVer</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';

        // traversing $allPlugins array
        foreach($allPlugins as $key => $value) {
            if(in_array($key, $activePlugins)) { // display active only
                echo '<tr>';
                echo "<td>{$value['Name']}</td>";
                echo "<td>{$value['Version']}</td>";
                $slug = explode('/',$key)[0]; // get active plugin's slug

                // get newest version of active plugin from repository
                $repoVersion = getPluginVersionFromRepository($slug);

                echo "<td>{$repoVersion}</td>";
                echo '</tr>';
            }
        }
        echo '</tbody>';
        echo '</table>';
    }     

    // widget's registration
    function fpwAddDashboardWidget() {
        wp_add_dashboard_widget(
            'active_plugins_versions', // widget's ID
            'Active Plugins Versions', // widget's title
            'activePluginsVersions'    // widget's callback (content)
        );  
    }
    add_action('wp_dashboard_setup', 'fpwAddDashboardWidget');
}
Code language: PHP (php)

One comment

Leave a Reply

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