WordPress.org

Support

Support » Plugins and Hacks » Toolbar Theme Switcher » [Plugin: Toolbar Theme Switcher] Top bar only shows with Adminuser signed in

[Plugin: Toolbar Theme Switcher] Top bar only shows with Adminuser signed in

Viewing 9 replies - 1 through 9 (of 9 total)
  • The code should be able to handle that, but it is not use case that I actively target and test for.

    To completely remove restriction on who can see and use switcher:

    add_filter( 'tts_can_switch_themes', '__return_true' );

    However if you need this for non-logged-in users you will also need something to force toolbar itself to show. It’s not in scope for this plugin, but I am pretty sure there should be plugins and/or snippets for that around.

    Hi.
    thanks for your nice plugin.
    but how to add button for your theme switcher in somewhere other than toolbar?
    like as a button in footer or …

    but how to add button for your theme switcher in somewhere other than toolbar?
    like as a button in footer or …

    The toolbar is kinda the point… 🙂 However it’s possible to have plugin do magic behind the scenes but control it in alternative manner.

    Essentially the act of theme switching is following a simple URL (to WP Ajax endpoint) and coming back, having cookies adjusted with theme choice. Looking at plugin’s code to produce link to switch to specific theme you do:

    add_query_arg( array( 'action' => 'tts_set_theme', 'theme' => urlencode( $theme['Name'] ) ), admin_url( 'admin-ajax.php' ) )

    Even simpler way would be to copy link from toolbar menu and hardcode it.

    Then you just put that link wherever. Note that by default it will not work for users who are not allowed to switch themes, so worth showing only to those who can without further customization.

    Thanks for your answer .
    So it seems we can’t use toolbar theme switcher to provide theme switching ability for anonymous and guest users. right?
    Is there any way to provide a theme switching link for any user of site?

    So it seems we can’t use toolbar theme switcher to provide theme switching ability for anonymous and guest users. right?
    Is there any way to provide a theme switching link for any user of site?

    I’ve answered about tweaking permission to switch right above.

    Hi, I’m wondering why my users cant change/see the feature? specially the ‘editors’

    They cant see this at the admin toolbar mycode is like this

    static function can_switch_themes() {
    
    		$capability = apply_filters( 'tts_capability', 'switch_themes' );
    
    		return apply_filters( 'tts_can_switch_themes', current_user_can( $capability) );
    
    	}

    Hi, I’m wondering why my users cant change/see the feature? specially the ‘editors’

    As you see in code default capability required is switch_themes, which by default only Admins and Super Admins can do.

    You can use something like following code to filter capability and allow editors (and above so it will still include admins) access:

    add_filter( 'tts_capability', 'tts_editor_capability' );
    
    function tts_editor_capability() {
    
    	return 'editor';
    }

    I tried to replace my code with the code that you gave ad it gave me an error and i cant access my wordpress site lol~ I undo it already, where should I add that code sir? thanks in advance!! 🙂

    Ouch, that is not meant to replace anything and you almost never need to edit [properly coded] WordPress stuff, unless that is explicitly said. Among other things because version updates overwrite such changes.

    Small tweaks tend to go into functions.php file of theme, but since we are switching between themes here appropriate location would be to create small plugin for it.

    Or even more easily – use it as must use plugin – save in file with .php extension and put into wp-content/mu-plugins folder.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Plugin: Toolbar Theme Switcher] Top bar only shows with Adminuser signed in’ is closed to new replies.
Skip to toolbar