Assume we have a multisite network. All sites in the network are separated into groups by some option value. What I want to do is to separate network available themes to be available to specific groups.
For instance, I have A-Z
themes installed. I want to activate A-K
themes to group 1, L-O
themes to group 2 and P-Z
themes to group 3.
Is there an easy way to do it?
You’d have to make you site categories slug match your theme categories folder names.
Here’s how to filter themes: Hide a theme on list of themes in wp-admin without editing core files
And then, supposing a site has the category a-p
and the themes are stored in themes/a-p/
, this will filter them out:
add_filter( 'all_themes', 'remove_themes_ms_wpse_117537' );
function remove_themes_ms_wpse_117537( $themes )
{
if( 'site-themes-network' != get_current_screen()->id )
return $themes;
$site_cat = get_blog_option( absint( $_GET['id'] ), 'site_category' );
if( $site_cat )
{
# Unset themes not in the folder /themes/$site_cat/
foreach( $themes as $key => $theme )
{
if( strpos( $key, "$site_cat/" ) === false )
unset($themes[$key]);
}
}
return $themes;
}