• Resolved theinnographer

    (@theinnographer)


    Hi again,

    I understand the use of the status in style.css to display (or not display) a theme.

    But is there a functions.php change you could provide that would allow us to exclude a theme by name? Or data slug? Something unique to a given theme?

    Or by whether it’s a parent theme? (It’d be great if we could only show child themes.)

    I’m trying to only allow the user to select from our child themes. This avoids them having access to the parent theme once that gets updated (and for which I assume the style.css including status is overwritten).

    Thanks!

    Alex.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter theinnographer

    (@theinnographer)

    Also, I understand that the theme is activated using the Appearance > Themes settings.

    I know I can make a theme private for use through your plugin, but is it possible to hide it from the user on the theme settings page?

    Something like this?

    add_filter( ?? , ‘hide_the7_theme_from_browser_for_non_admins’);
    
    function hide_the7_theme_from_browser_for_non_admins() {
       if (!current_user_can(‘install_themes’)) {
           // ??
       }
    }

    Thanks again!

    Alex.

    Thread Starter theinnographer

    (@theinnographer)

    Scratch that last question. (Answer below for those who might be seeking it.)

    I guess my question is how to avoid theme updates overwriting the status in style.css for parent themes, or whether we can somehow only display child themes in your plugin? Thanks!

    /* Hide theme from non-admins under Appearance > Themes */
    
    function hide_theme_from_non_admins($arr){
        if (!current_user_can('install_themes')) {
            unset($arr["theme-name"]);
        }
        return $arr;
    }
    add_filter( 'wp_prepare_themes_for_js', 'hide_theme_from_non_admins');
    Plugin Author Jeff Starr

    (@specialk)

    Glad to help:

    “But is there a functions.php change you could provide that would allow us to exclude a theme by name? Or data slug? Something unique to a given theme?”

    The only way that I know of is the “status” line in the theme file header (as explained in the documentation).

    2) “Also, I understand that the theme is activated using the Appearance > Themes settings.”

    The site’s primary active theme is set via the Themes > Settings, and you do not need the plugin to do it; WordPress can change primary active themes anytime via the Themes settings screen.

    3) “I guess my question is how to avoid theme updates overwriting the status in style.css for parent themes, or whether we can somehow only display child themes in your plugin?”

    It may be possible to do programmatically, but I don’t know it offhand. Maybe check the WordPress Codex and/or try the code you’re posting, etc.

    I hope this helps, let me know if I can provide any further infos.

    Thread Starter theinnographer

    (@theinnographer)

    Thanks! The code I posted does the trick for the themes at Appearance > Themes.

    Can you help me do the same thing, i.e. unset a theme by name such as theme_name from showing with your plugin when displayed via your [theme_switcha_thumbs style=”true”]?

    Much appreciated.

    Alex.

    Thread Starter theinnographer

    (@theinnographer)

    Something like this?

    /* Hide theme_name theme from non-admins when the Theme Switcha plugin displays thumbs: */
    
    function hide_theme_name_from_non_admins_theme_switcha_thumbs($themes){
    
        if (!current_user_can('install_themes')) {
            unset($themes["theme_name"]);
        }
        return $themes;
        
    }
    
    add_filter( 'theme_switcha_display_thumbs', 'hide_theme_name_from_non_admins_theme_switcha_thumbs');
    Plugin Author Jeff Starr

    (@specialk)

    Yeah that looks correct.

    Thread Starter theinnographer

    (@theinnographer)

    Hi Jeff.

    Thanks again for the great plugin.

    That code didn’t work, I believe because your function doesn’t have apply_filters(), i.e. doesn’t have the hook.

    Would love your help with that.

    Cheers, Alex.

    Plugin Author Jeff Starr

    (@specialk)

    I would be glad to take a look and add any necessary hooks for the next plugin update. No problem. Thanks for the feedback, Alex.

    Plugin Author Jeff Starr

    (@specialk)

    Just to follow up with this, I’ve added a new filter hook:

    theme_switcha_themes

    That can be used to modify themes as you have done in your previous code snippet.

    New plugin version should be available before release of WP 5.4.

    Thanks again for the feedback, Alex.

    Thread Starter theinnographer

    (@theinnographer)

    Hi Jeff,

    I missed the notification on this and am just seeing it now.

    Thanks for making that happen!

    To confirm would it be as follows?

    function hide_theme_name_from_non_admins_theme_switcha_thumbs($themes){
    
        if (!current_user_can('install_themes')) {
            unset($themes["theme_name"]);
        }
        return $themes;
        
    }
    
    add_filter( 'theme_switcha_themes', 'hide_theme_name_from_non_admins_theme_switcha_thumbs');

    And is it already in the current version of your plugin?

    Asking because it doesn’t seem to be working for me.

    Thanks again for the great support!

    Alex.

    Plugin Author Jeff Starr

    (@specialk)

    I can’t test your code right now but yeah that looks correct.

    Yes the theme_switcha_themes hook exists in the current version. You can find it in /inc/plugin-core.php, various instances across several functions.

    Thread Starter theinnographer

    (@theinnographer)

    Oops. It was a caching issue on my end.

    Works great!

    Thanks for the quick reply and great support Jeff!

    Alex.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘On excluding a theme’ is closed to new replies.