Last active
September 19, 2023 20:12
-
-
Save EarthmanWeb/1e96a373088f53f8d933173f364ba94c to your computer and use it in GitHub Desktop.
mu-plugin to show status of plugins for all sites in wpms (WordPress multisite)
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: Plugins Enabled | |
* Description: Displays the plugin status across all sites in a WordPress Multisite network. | |
* Author: Terrance Orletsky - Earthman Media | |
* Author URI: https://earthmanmedia.com | |
* Version: 1.0.7 | |
*/ | |
add_action( 'network_admin_menu', 'wpms_plugin_list_menu' ); | |
function wpms_plugin_list_menu() { | |
add_submenu_page( 'plugins.php', 'Plugins Enabled', 'Plugins Enabled', 'manage_network_plugins', 'wpms-plugin-list', 'wpms_plugins_enabled_page' ); | |
} | |
function wpms_plugins_enabled_page() { | |
global $wpdb; | |
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); | |
$all_plugins = get_plugins(); | |
$network_active_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); | |
$headerRowStyle = 'background-color: white; min-height: 50px; border: 1px solid #ccc;'; | |
$headerColumnStyle = 'background-color: white; padding: 10px; border: 1px solid #ccc;'; | |
$columnStyle = 'background-color: white; padding: 10px; border: 1px solid #ccc;'; | |
$stickyColumnStyle = 'min-width: 312px; font-weight: bold; background-color: white; padding: 10px; border: 1px solid #ccc;'; | |
echo '<hr /><br /><br /><table style="border-collapse: collapse; width: 100%;">'; | |
function output_header_row( $all_plugins, $stickyColumnStyle, $headerColumnStyle, $headerRowStyle, $repeat = false ) { | |
if ( $repeat ) { | |
$repeat_class = 'class="repeatedHeader"'; | |
} else { | |
$repeat_class = ''; | |
} | |
echo "<tr $repeat_class style=\"$headerRowStyle\">"; | |
echo "<th style=\"$stickyColumnStyle\">"; | |
if ( ! $repeat ) { | |
echo '<h1>Plugins Enabled by Site</h1>'; | |
} | |
echo '<input type="checkbox" id="toggleHeader" checked="checked"><label for="toggleHeader">Show repeating headers</label>'; | |
echo '</th>'; | |
$colCount = 0; | |
foreach ( $all_plugins as $plugin_file => $plugin_data ) { | |
if ( $colCount % 12 == 0 && $colCount > 0 ) { | |
echo "<th class=\"repeatedColumn\" style=\"$stickyColumnStyle\">"; | |
echo '<input type="checkbox" id="toggleHeader" checked="checked"><label for="toggleHeader">Show repeating headers</label>'; | |
echo '</th>'; | |
} | |
$plugin_url = ! empty( $plugin_data['PluginURI'] ) ? $plugin_data['PluginURI'] : $plugin_data['AuthorURI']; | |
echo "<th style=\"$headerColumnStyle\"><a href='" . esc_url( $plugin_url ) . "' target='_blank'>" . esc_html( $plugin_data['Name'] ) . '</a></th>'; | |
$colCount++; | |
} | |
echo '</tr>'; | |
} | |
output_header_row( $all_plugins, $stickyColumnStyle, $headerColumnStyle, $headerRowStyle ); | |
$rowCount = 0; | |
foreach ( $blog_ids as $blog_id ) { | |
switch_to_blog( $blog_id ); | |
$site_url = get_site_url(); | |
$admin_plugins_url = $site_url . '/wp-admin/plugins.php'; | |
$active_plugins = get_option( 'active_plugins', array() ); | |
$clean_url = str_replace( 'https://', '', $site_url ); | |
echo '<tr style="background-color: white;">'; | |
echo "<td style=\"$stickyColumnStyle\"><a href='" . esc_url( $admin_plugins_url ) . "' target='_blank'>" . esc_html( $clean_url ) . '</a></td>'; | |
$colCount = 0; | |
foreach ( array_keys( $all_plugins ) as $plugin_file ) { | |
if ( $colCount % 12 == 0 && $colCount > 0 ) { | |
echo "<td class=\"repeatedColumn\" style=\"$stickyColumnStyle\"><a href='" . esc_url( $admin_plugins_url ) . "' target='_blank'>" . esc_html( $clean_url ) . '</a></td>'; | |
} | |
$isActive = in_array( $plugin_file, $active_plugins ) || in_array( $plugin_file, $network_active_plugins ); | |
$icon = $isActive ? '✓' : '✗'; | |
$color = $isActive ? 'rgb(227 248 227)' : 'rgb(255 222 222)'; | |
echo "<td style=\"$columnStyle; background-color: $color; text-align: center; vertical-align: middle;\">$icon</td>"; | |
$colCount++; | |
} | |
echo '</tr>'; | |
$rowCount++; | |
if ( $rowCount % 12 == 0 ) { | |
output_header_row( $all_plugins, $stickyColumnStyle, $headerColumnStyle, $headerRowStyle, true ); | |
} | |
restore_current_blog(); | |
} | |
echo '</table><br /><br /><hr />'; | |
echo <<<HTML | |
<script> | |
jQuery(document).ready(function() { | |
// jQuery('.repeatedColumn').hide(); | |
// jQuery('.repeatedHeader').hide(); | |
jQuery('#toggleHeader').change(function() { | |
if(this.checked) { | |
jQuery('.repeatedColumn').show(); | |
jQuery('.repeatedHeader').show(); | |
} else { | |
jQuery('.repeatedColumn').hide(); | |
jQuery('.repeatedHeader').hide(); | |
} | |
}); | |
}); | |
</script> | |
HTML; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment