Make WordPress Core

Opened 21 months ago

Last modified 20 months ago

#56458 new feature request

Multisite Theme Details

Reported by: hopetommola's profile hopetommola Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.0.1
Component: Networks and Sites Keywords:
Focuses: ui, administration, multisite Cc:


It would be great if there were some accounting for the use of themes across a network. I'm thinking the /wp-admin/network/sites.php listing could show the active theme of each site.

Even if there was a counter so I could confirm the number of sites using a given Theme, that would work.

Or similar to the Users list, which has a column of Sites the user has access to, you could add a Sites column to the Themes listing.

Use Case: I have 8 themes installed, and 97 subsites. There doesn't seem to be any way to confirm which themes are active on 0 sites, confirming which I can uninstall.

Change History (5)

#1 @hopetommola
21 months ago

So ... I had an existing page template (below) that I figured I could output the theme by the title ... both attempts at $theme returned the PARENT theme, not the child, as described in get_bloginfo

                $bcount = get_blog_count();

                // global $wpdb;
                $blogs = $GLOBALS['wpdb']->get_results( "SELECT * FROM $wpdb->blogs WHERE 
                spam = '0' AND deleted = '0' and archived = '0' and public='1'", OBJECT );

                        foreach($blogs as $blog){
                            $details = get_blog_details($blog->blog_id);
                            // $theme = basename(get_bloginfo('stylesheet_directory'));
                            $theme = get_bloginfo('stylesheet_url');
                            if($details != false){
                                $addr = $details->siteurl;
                                $name = $details->blogname;
                                $id = $details->blog_id;
                                        $blogusers = get_users( 'blog_id='.$id.'&role=hope-admin' );
                                        if (!empty($blogusers)) {
                                                echo '<a href="'.$addr.'">'.$name.'</a> &mdash;'.$theme.'<ul>';
                                                foreach ( $blogusers as $user ) {
                                                echo '<li class="emails">'.$user->user_email .'</li>';
                                                echo '</ul>';

#2 follow-up: @bgoewert
21 months ago

I also think having the active theme displayed on the sites table list is a great idea. It's less of a hassle for me because I don't have nearly as many sites to administer. But having it on the sites panel would but more helpful for quick references instead of opening the site and going to the themes tab.

I've been using this WP-CLI snippet to export them in CSV format whenever I need a list.

echo url,theme,status,update,version; \
for url in $(wp site list --field=url 2>/dev/null); \
do \
    echo "$url,$(wp --url=$url theme list --status=active --format=csv --fields=name,status,update,version 2>/dev/null | tail -n +2)"; \

#3 in reply to: ↑ 2 @bananastalktome
20 months ago

@bgoewert @hopetommola
(disclaimer: this may not be the best way to accomplish this, but it has worked for me)

I have been able to accomplish this by hooking in to the existing hooks on WP_MS_Sites_List_Table, ex/:

if (is_network_admin()) {
  add_action('admin_init', function() {
    // `manage_{$screen->id}_columns` hook applied in `get_column_headers()` function
    add_filter('manage_sites-network_columns', function($columns) {
      $columns['site-theme'] = 'Theme';
      return $columns;

    // `manage_sites_custom_column` hook applied in `column_default()` from `WP_MS_Sites_List_Table` class.
    add_action('manage_sites_custom_column', function($column_name, $blog_id) {
      if ($column_name !== 'site-theme') {
      $theme = \wp_get_theme(); // Returns a `WP_Theme` object
      <div><?= esc_html($theme->get('Name')); ?></div>
      <div><?= esc_html($theme->get('Version')); ?></div>
    }, 10, 2);

You can check out WP_Theme to see what other properties are available to show as well.

#4 @hopetommola
20 months ago

@bananastalktome @bgoewert both good methods to achieve the easily accessible sites using a them. Having it listed in a Theme column of /network/sites.php would still be fantastic solution (and far more approachable than the Sites column of /network/users.php)

That all said, my first comment seems to indicate that there may be a bug with get_bloginfo or perhaps a lack of clarity in the docs. Have either of you experienced that?

#5 @bananastalktome
20 months ago

@hopetommola I couldn't tell from your comment, but wanted to let you know the solution I posted above does add a column to the /network/sites.php page to include the Theme as a separate column.

That said, from looking at your code, I think the issue you're facing with get_bloginfo is that you haven't called switch_to_blog($blog->blog_id); first - the bloginfo is being retrieved for the main network site (I believe). The get_blog_details() function looks like it handles switching to the provided blog for you, so it works without the need for an explicit switch_to_blog() call first. Try adding switch_to_blog($blog->blog_id); right after your foreach, and then restore_current_blog() right before the end of the foreach.

Note: See TracTickets for help on using tickets.