Hide active themes on multisite subdomains

Is it possible to hide the active themes in a network so that the subdomain users won’t see them as being available?

The problem is that i have 10 themes installed on the network and the subdomain users see the ones not assigned to them under Appearance -> Themes, and activate other themes. I am trying to remove this capability for the subdomain administrators.

Read More

Thanks.

Related posts

Leave a Reply

2 comments

  1. You could remove the 'switch_themes' capability from the 'administrator' role, which should prevent regular admins (as opposed to the network superadmin) from being able to switch their theme. Try this:

    add_action('admin_init', 'custom_remove_switch_themes_role_from_admins');
    function custom_remove_switch_themes_role_from_admins(){
      global $wp_roles;
      $wp_roles->remove_cap('administrator', 'switch_themes');
    }
    

    EDIT:

    From a bit more extended testing with this above function, I noticed some issues when I removed a cap and then did not explicitly add it back again when I was done testing (it seemed to actually remove it from the database rather than just for the current page). This is alright, but just be careful! If you are less comfortable with that, try the following, which intercepts capabilities for all roles, not just admins (note that network admins are excluded from this, since they have all capabilities):

    add_filter('user_has_cap', 'custom_remove_switch_themes_capability', 10, 3);
    function custom_remove_switch_themes_capability($all_caps, $caps, $args){
      if ('switch_themes' == $args[0]) // You can chain additional caps (using or) here if desired
        return array();
      else
        return $all_caps;
    }
    
  2. If you don’t mind an jQuery solution:

    function wpse50333_hide_current_theme()
    {
        echo '<script type="text/javascript">
            jQuery( '#current-theme' ).prev( 'h2' ).hide();
            jQuery( '#current-theme' ).hide();
        </script>';
    }
    add_action( 'admin_footer', 'wpse50333_hide_current_theme' );