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.



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');


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();
    return $all_caps;
| improve this answer | |
  • be warned, though, that this will remove the capability at the database level, not just during the current page request. As such, be sure to revert your code to use add_cap for each capability which you (at any point) decide to remove. You could alternatively somehow put this in a plugin with an activation hook which runs this, and a deactivation hook which runs the inverse. – William Apr 26 '12 at 19:14
  • to which file am i adding this? :) the /wp-admin/includes/user.php? – Anca F Apr 26 '12 at 19:37
  • @AncaF I would suggest that you should create this in a custom mu plugin of your creation (codex.wordpress.org/Must_Use_Plugins). This way it is activated for all blogs within your multisite network, and cannot be deactivated through the plugins interface. – William Apr 26 '12 at 20:27

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();
add_action( 'admin_footer', 'wpse50333_hide_current_theme' );
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.