Functions – under the hood
While is_user_logged_in()
can be used to determine the difference between a guest and a logged in (and therefore registered) user, switch_theme( $stylesheet )
alters actual database entries in the {$wpdb->options}
table:
update_option( 'template', $template );
update_option( 'stylesheet', $stylesheet );
update_option( 'current_theme', $new_name );
if ( count( $wp_theme_directories ) > 1 ) {
update_option( 'template_root', get_raw_theme_root( $template, true ) );
update_option( 'stylesheet_root', get_raw_theme_root( $stylesheet, true ) );
} else {
delete_option( 'template_root' );
delete_option( 'stylesheet_root' );
}
update_option( 'theme_switched', $old_theme->get_stylesheet() );
Simple solution: Two stylesheets.
Therefore I wouldn’t recommend doing so. Simply switch “themes” – read: loaded stylesheets – on a user/guest basis
$stylesheet = plugins_dir_url( __FILE__ ).'assets/';
$stylesheet .= is_user_logged_in()
? 'style-user.css'
: 'style-guest.css;
wp_enqueue_style(
'main-stylesheet',
$stylesheet
array( 'commons.css' )
1.0
);
As you can see, I add a dependency of commons.css
to the stylesheet. This would be another, previously registered/enqueued stylesheet that has all definitions that are shared between both.