From 2e93b5e16de16e201497cba727d2a8ef129ce800 Mon Sep 17 00:00:00 2001 From: Aubrey Portwood Date: Sat, 27 Jun 2015 19:03:16 -0700 Subject: [PATCH 1/2] Allow designers to hide/show wp admin bar using parameter w/out logging out. --- inc/extras.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/inc/extras.php b/inc/extras.php index 94a041cb9..da3624ff9 100644 --- a/inc/extras.php +++ b/inc/extras.php @@ -64,4 +64,19 @@ function _s_render_title() { } add_action( 'wp_head', '_s_render_title' ); -endif; \ No newline at end of file +endif; + +/** + * Allows designers to hide/show the Admin Bar w/out logging out. + * + * @return void + */ +function _s_show_admin_bar() { + if ( ! is_user_logged_in() || ! isset ( $_GET['show_admin_bar'] ) ) { + return; + } + + show_admin_bar( 'true' == $_GET['show_admin_bar'] ? true : false ); +} + +add_action( 'init', '_s_show_admin_bar' ); From ba0356a4fc0a7c8050eb0dcf6b4128088fc36279 Mon Sep 17 00:00:00 2001 From: Aubrey Portwood Date: Sat, 27 Jun 2015 19:18:20 -0700 Subject: [PATCH 2/2] Use a different method that's more useful. To emulate logged out you can use `?wp_set_current_user=false`, or you can set the user (when logged in as an admin) using `?wp_set_current_user=1`. --- inc/extras.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/inc/extras.php b/inc/extras.php index da3624ff9..6a4adc55e 100644 --- a/inc/extras.php +++ b/inc/extras.php @@ -67,16 +67,18 @@ function _s_render_title() { endif; /** - * Allows designers to hide/show the Admin Bar w/out logging out. + * Allows an administrator to set the logged in user. + * + * Setting to false will emulate a logged out user. * * @return void */ -function _s_show_admin_bar() { - if ( ! is_user_logged_in() || ! isset ( $_GET['show_admin_bar'] ) ) { +function _s_wp_set_current_user() { + if ( ! is_user_logged_in() || ! isset ( $_GET['wp_set_current_user'] ) || ! current_user_can( 'create_users' ) ) { return; } - show_admin_bar( 'true' == $_GET['show_admin_bar'] ? true : false ); + wp_set_current_user( is_numeric( $_GET['wp_set_current_user'] ) ? absint( $_GET['wp_set_current_user'] ) : ( 'true' == $_GET['wp_set_current_user'] ? true : false ) ); } -add_action( 'init', '_s_show_admin_bar' ); +add_action( 'init', '_s_wp_set_current_user' );