Last active
September 15, 2023 23:00
-
-
Save EarthmanWeb/665d90bda273d4367ab94180204e75be to your computer and use it in GitHub Desktop.
Adds plugin status page to network admin for WPMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Plugin Versions | |
* Description: Adds a Plugin Versions menu in WordPress Network Admin under Plugins. | |
* Author: Terrance Orletsky - Earthman Media | |
* Author URI: https://earthmanmedia.com | |
* Version: 1.0 | |
*/ | |
// Hook to add submenu under Network Admin > Plugins | |
add_action( 'network_admin_menu', 'add_plugin_versions_menu' ); | |
// Function to add submenu | |
function add_plugin_versions_menu() { | |
add_submenu_page( | |
'plugins.php', | |
'Plugin Versions', | |
'Plugin Versions', | |
'manage_network_options', | |
'plugin-versions', | |
'display_plugin_versions' | |
); | |
} | |
// Function to display plugin versions | |
function display_plugin_versions() { | |
// Fetch all installed plugins | |
$all_plugins = get_plugins(); | |
// Trigger update check for plugins | |
do_action( 'wp_update_plugins' ); | |
// Fetch transient data for plugin updates | |
$plugin_updates = get_site_transient( 'update_plugins' ); | |
// Counter to keep track of plugins needing updates | |
$update_count = 0; | |
$counter = 0; | |
$row_output = ''; | |
// Loop through each plugin and output versions | |
foreach ( $all_plugins as $plugin_path => $plugin_data ) { | |
$counter++; | |
$current_version = $plugin_data['Version']; | |
$plugin_name = $plugin_data['Name']; | |
$plugin_url = ! empty( $plugin_data['PluginURI'] ) ? $plugin_data['PluginURI'] : $plugin_data['AuthorURI']; | |
$available_version = '-'; | |
$row_style = 'margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline;'; | |
$td_style = 'border-top-color:rgb(221, 221, 221);border-top-style:solid;border-top-width:0.555556px;'; | |
// Check for updates | |
if ( isset( $plugin_updates->response[ $plugin_path ] ) ) { | |
$update_data = $plugin_updates->response[ $plugin_path ]; | |
$available_version = $update_data->new_version; | |
$update_count++; | |
$td_style .= ' background-color: #faefb3;'; | |
} | |
// Output each plugin row | |
$row_output .= "<tr style='{$row_style}'>"; | |
$row_output .= "<td style='{$td_style}'><a href='{$plugin_url}' target='_blank' style='text-decoration: none; color: #000;'>{$plugin_name}</a></td>"; | |
$row_output .= "<td style='{$td_style}'>{$current_version}</td>"; | |
$row_output .= "<td style='{$td_style}'>{$available_version}</td>"; | |
$row_output .= '</tr>'; | |
} | |
// table output | |
echo '<hr><h4>Plugins Update Status: <small> ' . $update_count . ' plugins to be updated.</small></h4><table style="margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline;"><thead style="margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline;"><tr style="margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline;"><th style="margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline;text-align:left;font-weight: bold;">Plugin Name / Link</th><th style="margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline;text-align:left;font-weight: bold;">Current Version</th><th style="margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline;text-align:left;font-weight: bold;">Update Available</th></tr></thead><tbody style="margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline;">' . $row_output . '</tbody></table><br><br><hr>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment