Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* @package jd-check-theme-activity
* @version 1.0
*/
/*
Plugin Name: Check Theme Activity
Plugin URI: https://joseph-dickson.com
Description: Dashboard widgets that display which themes are active.
Author: Joseph Dickson
Version: 1.0
Author URI: https://joseph-dickson.com
*/
/**
* Adapted from https://wordpress.stackexchange.com/questions/54742/how-to-do-i-get-a-list-of-active-plugins-on-my-wordpress-blog-programmatically
*/
/**
* ## Display Dashbord Widgets
*
* Display Single Site Dashboard Widget
*/
add_action('wp_dashboard_setup', 'jd_dashboard_setup_themes');
function jd_dashboard_setup_themes() {
// Site Active Themes
wp_add_dashboard_widget( 'jd_active_site_themes', __( 'Active Theme' ), 'jd_active_site_themes' );
// Network Active Themes
if( is_multisite() ) {
wp_add_dashboard_widget( 'jd_active_network_themes', __( 'Network Enabled Themes' ), 'jd_active_network_themes' );
}
}
/**
* Display Multisite Dashboard Widget
*/
add_action('wp_network_dashboard_setup', 'jd_network_dashboard_setup_themes');
function jd_network_dashboard_setup_themes() {
// Network Active Themes
wp_add_dashboard_widget( 'jd_active_network_themes', __( 'Network Enabled Themes' ), 'jd_active_network_themes' );
// Sites on this Network
wp_add_dashboard_widget( 'jd_single_site_themes', __( 'Themes Running on the Network' ), 'jd_single_site_themes' );
}
/**
* ## Get Activated Plugin Information
*
* Locally Activated Themes
*/
function jd_active_site_themes() {
$the_theme = get_option( 'template' );
echo $the_theme;
}
/**
* Network Activated Themes
*/
if( is_multisite() ) {
function jd_active_network_themes() {
$the_themes = wp_get_themes( array( 'allowed' => true ) );
echo '<p>Network themes available.</p>';
echo '<ul>';
foreach($the_themes as $key => $value) {
$string = explode('/',$key); // plugin slug will be displayed
echo '<li>'.$string[0] .'</li>';
}
echo '</ul>';
}
}
/**
* Themes Activated Locally on Each Site
*/
function jd_single_site_themes() {
global $wpdb;
$blogs = $wpdb->get_results("
SELECT blog_id
FROM {$wpdb->blogs}
WHERE site_id = '{$wpdb->siteid}'
AND spam = '0'
AND deleted = '0'
AND archived = '0'
");
foreach ($blogs as $blog) {
$active_theme = wp_get_theme();
echo '<h1>' . get_blog_option($blog->blog_id, 'blogname') . '</h1>';
echo '<p><strong>Active Theme:</strong> ' . $active_theme . '</p>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.