I am working on a theme, where I want to get to know if the theme is network enabled or not for some functionality.
Can anyone explain me how can I get the list of network enabled themes? or just to know a theme is network enabled or not?
Any help is appreciated.
How about a 7.5 year too late answer?
I’m writing a plugin that needed this functionality too.
Unfortunately I couldn’t find any clearly defined “network-enabled” functions, hooks, or DB table keys related to themes. Plugins get a little bit more love in that regard.
DB Info
With that said, network-activated plugins are stored in the main wp_sitemeta table with the key “allowedthemes”.
Unfortunately, (yet again), it’s not a consistent array ready for use as-is.
It contains EVERY theme “slug” as an array value with standard number index keys, but ALSO contains the network-activated themes with the theme “slug” as the key and a boolean “1” as the value. Why? I have no idea, but surely it made sense to someone, somewhere, at some point in time.
DB Serialized Meta Value
Example meta_value for meta_key “allowedthemes” in wp_sitemeta table in the DB:
Retrieving Values
Getting this value depends on the type of multisite, and/or plugin compatibility you want to offer.
For single network multisite installs
For multinetwork multisite installs
Results
Results Breakdown
Array values with
[#] => theme_slug
are just installed/available themes.Array values with
[theme_slug] => 1
are network-activated themes.Again, WHY mix them in one array like this? Couldn’t tell you. It is what it is.
Making Results Useful
Now there’s plenty of ways to extract JUST the network activated themes, or JUST the installed/available themes with array_walk functions and other techniques.
One (less elegant, but more thorough) way I do this within the plugin I’m writing is to loop through all the themes from
wp_get_themes()
and wherever a “theme slug” is the key, append it to an array for later use:Once you have an array of JUST network-activated themes like this, you should be able to accomplish your goals with network-activated themes.
I realize that @nitin-yawalkar probably doesn’t need this help anymore, but due to the complete lack of answers here and elsewhere related to this question, I wanted to chime in and add SOMETHING to help steer people in the right direction.
UPDATE
I did find a filter of interest for this.
https://developer.wordpress.org/reference/hooks/allowed_themes/
It’s not very helpful as-is, but within proper context/scope, it’s quite handy.
Example ‘allowed_themes’ Filter on wp-admin/themes.php page
One aspect of the plugin I’m developing allows setting allowed themes on a per-site basis on multisites. This filter is network-wide, so to apply it on a per-site basis you can do something like this:
The ‘allowed_themes’ filter applies network-wide. Use context/scope like the example above to make it useful per-site / per-role / per-user, and limit it so that it’s only applied when / where you need to alter the allowed themes.