WordPress.org

Ready to get started?Download WordPress

Forums

Toolbar Theme Switcher
Top bar only shows with Adminuser signed in (10 posts)

  1. iToniPhotos
    Member
    Posted 2 years ago #

    The bar works fine but only displays when an Admin User is signed in. Am I able to set this for non members to view the bar and change the theme?

    http://wordpress.org/extend/plugins/toolbar-theme-switcher/

  2. Andrey "Rarst" Savchenko
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  3. th90
    Member
    Posted 2 years ago #

    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 ...

  4. Andrey "Rarst" Savchenko
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  5. th90
    Member
    Posted 2 years ago #

    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?

  6. Andrey "Rarst" Savchenko
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  7. yuufa10182006
    Member
    Posted 1 year ago #

    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) );
    
    	}
  8. Andrey "Rarst" Savchenko
    Member
    Plugin Author

    Posted 1 year ago #

    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';
    }
  9. yuufa10182006
    Member
    Posted 1 year ago #

    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!! :)

  10. Andrey "Rarst" Savchenko
    Member
    Plugin Author

    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.