• Resolved Norm Sash

    (@normsash)


    I’m trying to figure out how to switch themes based on the user’s login ID (not the user number). Here’s what I have been trying but I can’t seem to get it to work. Would someone glance at this and tell me what I need to change?

    add_action( 'plugins_loaded', 'my_conditional_themes_setup', 100 );
    
    function my_conditional_themes_setup() {
    
    	//Switch to channel66 theme if user ID matches
    	Conditional_Themes_Manager::register( 'channel66', function() {
        	        get_currentuserinfo();
    		return ( $current_user->user_login === '7ff6xi' );
    	} );
    }

    Thanks,
    -Norm

    https://wordpress.org/plugins/wp-conditional-themes/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Nashwan D

    (@alex-ye)

    Hi Norm! .. Could you mind trying this code?

    add_action( 'plugins_loaded', 'my_conditional_themes_setup', 100 );
    
    function my_conditional_themes_setup() {
    
    	//Switch to channel66 theme if user ID matches
    	Conditional_Themes_Manager::register( 'channel66', function() {
    		$current_user = wp_get_current_user();
    		return ( ! empty( $current_user ) && $current_user->user_login === '7ff6xi' );
    	} );
    
    }
    Thread Starter Norm Sash

    (@normsash)

    Awesome Nashwan! Thanks… that worked and I see what you are doing different than what I did. I’m not really sure why mine didn’t work, but I’m also not a php expert.

    If you have the time, would you mind telling me how to make the two conditionals below OR’d? So that either condition can make the theme active. Each works as a standalone, but not if they are together. I thought the php ‘return’ statement would immediately return out of the function call when it evaluated to true.

    add_action( 'plugins_loaded', 'my_conditional_themes_setup', 100 );
    
    function my_conditional_themes_setup() {
    
    	//Switch to channel66 theme if user ID matches
    	Conditional_Themes_Manager::register( 'channel66', function() {
    		$current_user = wp_get_current_user();
    		return ( ! empty( $current_user ) && $current_user->user_login === '7ff6xi' );
    	} );
    
        // Switch to channel66 theme if the visitor use Internet Explorer.
        Conditional_Themes_Manager::register( 'channel66', function() {
            global $is_IE;
            return (bool) $is_IE;
        } );
    
    }

    ps… I know this little php help is beyond the scope of your plugin 😉

    Plugin Author Nashwan D

    (@alex-ye)

    You mean like this?

    add_action( 'plugins_loaded', 'my_conditional_themes_setup', 100 );
    
    function my_conditional_themes_setup() {
    
    	Conditional_Themes_Manager::register( 'channel66', function() {
    		global $is_IE;
    		$u = wp_get_current_user();
    		return ( $is_IE || ( $u && $u->user_login === '7ff6xi' ) );
    	} );
    
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘different theme based on login ID’ is closed to new replies.