Pro Sites: get object of allowed themes for current site

I have some custom js that I'm working with to create an entirely unique wp customizer experience. Part of this is creating a custom theme preview and installation experience.
So this means I need to get a list of all themes that are available to that prosite blog.

I can get a array of theme objects via wp_get_themes().

However, what I really need is the ability to get only themes that are allowed for that site via prosites.

I have the prosites theme module installed and set up with themes for different levels.

I've tried this:

$test = $psts->get_setting('pt_allowed_themes');

this prints out the name of the theme with it's level associated. It's a start but no bueno.

Do you have anything I can use that returns more detail? Similar to wp_get_themes() but also showing which level it belongs to?

Ideally, the object would be something similar to the wp_get_themes object like this:


    [solo-theme] = Object
            [update] = ;
            [theme_root:WP_Theme:private] =>; /home/path/Web/web/app/themes
            [headers:WP_Theme:private] =>; Array
                    [Name] =>; Solo Theme
                    [ThemeURI] =>;
                    [Description] =>; The Solo theme
                    [Author] =>; some author name
                    [AuthorURI] =>;
                    [Version] =>; 1.0
                    [Template] =>; some-parent-theme
                    [Status] =>;
                    [Tags] =>; sometag
                    [TextDomain] =>;
                    [DomainPath] =>;
                    [prositeLevel] => 1;


I can always loop through them in JS and do the work there.

Right now, just using $psts->get_setting('pt_allowed_themes'); to get a theme name and it's level would require me to do a bunch of extra work that seems unnecessary.

Let me know and thanks yall! I signed back up just to ask this question.

P.S You really need some developer docs - desperately.

  • Luís

    Hi m33 ,

    Hope you're doing well today!

    I spoke with the developer and he suggested to try something like:

    if( class_exists('ProSites_Module_PremiumThemes') && method_exists('ProSites_Module_PremiumThemes', 'site_option_allowedthemes') ) {
                $themes              = wp_get_themes();
                $allowed_themes = ProSites_Module_PremiumThemes::site_option_allowedthemes( $themes );
                echo "<pre>";
                print_r( $allowed_themes );
                echo "</pre>";

    That should return the allowed themes for a particular blog, but the function needs to run inside the particular blog itself, as it fetches the current blog ID to return a list of the allowed themes.

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

  • m33

    Thanks but I'm a bit confused - this just returns all themes on the network.

    I have confirmed that no themes are network activated.
    I have the pro-sites theme module installed.
    Levels are set up.
    I have various themes set up for different levels.

    When I login as a site that is on the lowest level, I see all themes on the network using this if block.

    I just reread your comment and saw that it needs to run inside the blog context. I'm using this in a plugin and I'm visiting the blog as one of it's users to view the output. I also tried to put get_current_blog_id() inside the wp_get_themes() function but still not working. Is there something more I should do here?

    What am I missing?

  • m33

    Actually, I take all this back. I saw the right themes once but not anymore.

    It's the same setup but now I'm getting one complete them object (that's not even active for this level) and then 3 theme names with their associated level. These items have no other properties or values associated with them.

    Super weird.

    Here's my code:

    $theme_args = array( 'errors' => false , 'allowed' => true, 'blog_id' => 0 );
    	       if ( class_exists('ProSites_Module_PremiumThemes') && method_exists('ProSites_Module_PremiumThemes', 'site_option_allowedthemes') ) {
                    $themes              = wp_get_themes($theme_args);
                    $allowed_themes = ProSites_Module_PremiumThemes::site_option_allowedthemes( $themes );
                    echo '<pre>';
                    print_r( $allowed_themes );
                    echo '</pre>';
  • Ivan Shulev

    Hey m33 ,

    I hope you are having a nice day so far!

    I looked at the premium themes code in the pro sites plugin and the following caught my eye:

    if ( is_network_admin() ) {
    	return $themes;

    This means that if the function is called by the network admin, the themes you pass to the function are returned, or in other words you get all the themes back. Just create another user and see what you get.

    If that does not show you the themes you want, please consider the following.

    I would try experimenting with this filter:

    function wpmu_5433_show_themes(){
    	return true;
    add_filter('prosites_show_themes_prosites_only', 'wpmu_5433_show_themes');

    Set the return value to false if nothing changes.

    You can see the ProSites_Module_PremiumThemes::site_option_allowedthemes() function in /wp-content/plugins/pro-sites/pro-sites-files/modules/premium-themes.php

    I hope this helps and I wish you an awesome day ahead!