From 99e229c48bc4b39851f3255b0112455b76d8e751 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 18 Oct 2012 05:54:52 +0000 Subject: [PATCH] Always show a 'Switch back' link in the footer when the admin toolbar isn't showing. More intuitive redirecting after switching. git-svn-id: http://plugins.svn.wordpress.org/user-switching/trunk@613948 b8457f37-d9ea-0310-8a92-e5e31aec5664 --- readme.txt | 16 ++++++++-------- user-switching.php | 34 ++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/readme.txt b/readme.txt index 724628f..c4d7b9b 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: johnbillion Donate link: http://lud.icro.us/donations/ Tags: user, users, profiles, switching, wpmu, multisite, buddypress, become, user control, user management, user access, developer -Requires at least: 2.7 -Tested up to: 3.4.2 +Requires at least: 3.1 +Tested up to: 3.5 Stable tag: trunk Instant switching between user accounts in WordPress. @@ -34,7 +34,6 @@ This plugin allows you to quickly swap between user accounts in WordPress at the * Farsi (Persian) by Amin Ab * Slovak by Max Samael * Polish by Bartosz Arendt - * Lithuanian by Tommixoft == Installation == @@ -96,14 +95,15 @@ When a user switches off, the `switch_off_user` hook is called with the old user == Upgrade Notice == -= 0.6.3 = -* Lithuanian, Polish and Slovak translations. - -= 0.6 = -* More intuitive redirecting after switching, a BuddyPress bugfix and some hooks added. += 0.7 = +* More intuitive redirecting after switching. Always show a 'Switch back' link in the footer when the admin toolbar isn't showing. == Changelog == += 0.7 = +* Always show a 'Switch back' link in the footer when the admin toolbar isn't showing. +* More intuitive redirecting after switching. + = 0.6.3 = * Lithuanian translation by Tommixoft. diff --git a/user-switching.php b/user-switching.php index dc067ef..a82e9e1 100644 --- a/user-switching.php +++ b/user-switching.php @@ -2,7 +2,7 @@ /* Plugin Name: User Switching Description: Instant switching between user accounts in WordPress -Version: 0.6.3 +Version: 0.7 Plugin URI: http://lud.icro.us/wordpress-plugin-user-switching/ Author: John Blackbourn Author URI: http://johnblackbourn.com/ @@ -114,7 +114,7 @@ function init() { return; if ( isset( $_REQUEST['redirect_to'] ) and !empty( $_REQUEST['redirect_to'] ) ) - $redirect_to = remove_query_arg( array( 'user_switched', 'switched_off', 'switched_back' ), $_REQUEST['redirect_to'] ); + $redirect_to = remove_query_arg( array( 'user_switched', 'switched_off', 'switched_back', 'message', 'updated', 'settings-updated' ), $_REQUEST['redirect_to'] ); else $redirect_to = false; @@ -200,7 +200,10 @@ function admin_notice() {

%s.', $this->switch_back_url(), sprintf( __( 'Switch back to %1$s (%2$s)', 'user_switching' ), $old_user->display_name, $old_user->user_login ) ); + $url = add_query_arg( array( + 'redirect_to' => urlencode( $this->current_url() ) + ), $this->switch_back_url() ); + printf( ' %s.', $url, sprintf( __( 'Switch back to %1$s (%2$s)', 'user_switching' ), $old_user->display_name, $old_user->user_login ) ); ?>

$parent, 'id' => 'wp-admin-bar-switch-back', 'title' => sprintf( __( 'Switch back to %1$s (%2$s)', 'user_switching' ), $old_user->display_name, $old_user->user_login ), - 'href' => $this->switch_back_url() + 'href' => add_query_arg( array( + 'redirect_to' => urlencode( $this->current_url() ) + ), $this->switch_back_url() ) ) ); } @@ -269,7 +274,7 @@ function admin_bar_menu( $wp_admin_bar ) { $url = $this->switch_off_url(); if ( !is_admin() ) { $url = add_query_arg( array( - 'redirect_to' => $_SERVER['REQUEST_URI'] + 'redirect_to' => urlencode( $this->current_url() ) ), $url ); } @@ -285,16 +290,16 @@ function admin_bar_menu( $wp_admin_bar ) { } /** - * Adds a 'Switch back to {user}' link to the WordPress footer if a user is switched off. + * Adds a 'Switch back to {user}' link to the WordPress footer if the admin toolbar isn't showing. * * @return null */ function switch_on() { - if ( !is_user_logged_in() and $old_user = $this->get_old_user() ) { + if ( !is_admin_bar_showing() and $old_user = $this->get_old_user() ) { $link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user_switching' ), $old_user->display_name, $old_user->user_login ); $url = add_query_arg( array( - 'redirect_to' => $_SERVER['REQUEST_URI'] + 'redirect_to' => urlencode( $this->current_url() ) ), $this->switch_back_url() ); echo '

' . $link . '

'; } @@ -302,13 +307,13 @@ function switch_on() { } /** - * Adds a 'Switch back to {user}' link to the WordPress login screen if a user is switched off. + * Adds a 'Switch back to {user}' link to the WordPress login screen. * * @return null */ function login_message( $message ) { - if ( !is_user_logged_in() and $old_user = $this->get_old_user() ) { + if ( $old_user = $this->get_old_user() ) { $link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user_switching' ), $old_user->display_name, $old_user->user_login ); $url = $this->switch_back_url(); if ( isset( $_REQUEST['redirect_to'] ) and !empty( $_REQUEST['redirect_to'] ) ) { @@ -419,6 +424,15 @@ function switch_off_url() { ), site_url( 'wp-login.php', 'login' ) ), 'switch_off' ); } + /** + * Returns the current URL. + * + * @return string The current URL + */ + function current_url() { + return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + } + /** * Filter the user's capabilities so they can be added/removed on the fly. *