Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

Thanks.

share|improve this question
add comment

2 Answers

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;
}
share|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
add comment

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' );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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