User Switching - Version 1.2.0

Version Description

Download this release

Release Info

Developer johnbillion
Plugin Icon 128x128 User Switching
Version 1.2.0
Comparing to
See all releases

Code changes from version 1.1.0 to 1.2.0

Files changed (2) hide show
  1. readme.txt +1 -1
  2. user-switching.php +22 -11
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: johnbillion
4
  Tags: users, profiles, user switching, fast user switching, multisite, buddypress, bbpress, become, user management, developer
5
  Requires at least: 3.7
6
  Tested up to: 4.8
7
- Stable tag: 1.1.0
8
  License: GPL v2 or later
9
 
10
  Instant switching between user accounts in WordPress.
4
  Tags: users, profiles, user switching, fast user switching, multisite, buddypress, bbpress, become, user management, developer
5
  Requires at least: 3.7
6
  Tested up to: 4.8
7
+ Stable tag: 1.2.0
8
  License: GPL v2 or later
9
 
10
  Instant switching between user accounts in WordPress.
user-switching.php CHANGED
@@ -10,7 +10,7 @@
10
  *
11
  * Plugin Name: User Switching
12
  * Description: Instant switching between user accounts in WordPress
13
- * Version: 1.1.0
14
  * Plugin URI: https://johnblackbourn.com/wordpress-plugin-user-switching/
15
  * Author: John Blackbourn
16
  * Author URI: https://johnblackbourn.com/
@@ -182,7 +182,7 @@ class user_switching {
182
  } else {
183
  wp_safe_redirect( add_query_arg( $args, admin_url() ) );
184
  }
185
- die();
186
 
187
  } else {
188
  wp_die( esc_html__( 'Could not switch users.', 'user-switching' ) );
@@ -208,6 +208,12 @@ class user_switching {
208
  // Switch user:
209
  if ( switch_to_user( $old_user->ID, self::remember(), false ) ) {
210
 
 
 
 
 
 
 
211
  $redirect_to = self::get_redirect( $old_user, $current_user );
212
  $args = array(
213
  'user_switched' => 'true',
@@ -218,7 +224,7 @@ class user_switching {
218
  } else {
219
  wp_safe_redirect( add_query_arg( $args, admin_url( 'users.php' ) ) );
220
  }
221
- die();
222
  } else {
223
  wp_die( esc_html__( 'Could not switch users.', 'user-switching' ) );
224
  }
@@ -246,7 +252,7 @@ class user_switching {
246
  } else {
247
  wp_safe_redirect( add_query_arg( $args, home_url() ) );
248
  }
249
- die();
250
  } else {
251
  /* Translators: "switch off" means to temporarily log out */
252
  wp_die( esc_html__( 'Could not switch off.', 'user-switching' ) );
@@ -500,13 +506,9 @@ class user_switching {
500
  }
501
 
502
  /**
503
- * Adds a 'Switch back to {user}' link to the Meta sidebar widget if the admin toolbar isn't showing.
504
  */
505
  public function action_wp_meta() {
506
- if ( is_admin_bar_showing() ) {
507
- return;
508
- }
509
-
510
  $old_user = self::get_old_user();
511
 
512
  if ( $old_user instanceof WP_User ) {
@@ -566,12 +568,21 @@ class user_switching {
566
  $old_user->user_login
567
  );
568
  $url = self::switch_back_url( $old_user );
569
- if ( ! empty( $_REQUEST['redirect_to'] ) ) {
 
 
 
 
 
570
  $url = add_query_arg( array(
571
  'redirect_to' => urlencode( wp_unslash( $_REQUEST['redirect_to'] ) ), // WPCS: sanitization ok
572
  ), $url );
573
  }
574
- $message .= '<p class="message" id="user_switching_switch_on"><span class="dashicons dashicons-admin-users" style="color:#56c234"></span> <a href="' . esc_url( $url ) . '">' . esc_html( $link ) . '</a></p>';
 
 
 
 
575
  }
576
 
577
  return $message;
10
  *
11
  * Plugin Name: User Switching
12
  * Description: Instant switching between user accounts in WordPress
13
+ * Version: 1.2.0
14
  * Plugin URI: https://johnblackbourn.com/wordpress-plugin-user-switching/
15
  * Author: John Blackbourn
16
  * Author URI: https://johnblackbourn.com/
182
  } else {
183
  wp_safe_redirect( add_query_arg( $args, admin_url() ) );
184
  }
185
+ exit;
186
 
187
  } else {
188
  wp_die( esc_html__( 'Could not switch users.', 'user-switching' ) );
208
  // Switch user:
209
  if ( switch_to_user( $old_user->ID, self::remember(), false ) ) {
210
 
211
+ if ( ! empty( $_REQUEST['interim-login'] ) ) {
212
+ $GLOBALS['interim_login'] = 'success';
213
+ login_header( '', '' );
214
+ exit;
215
+ }
216
+
217
  $redirect_to = self::get_redirect( $old_user, $current_user );
218
  $args = array(
219
  'user_switched' => 'true',
224
  } else {
225
  wp_safe_redirect( add_query_arg( $args, admin_url( 'users.php' ) ) );
226
  }
227
+ exit;
228
  } else {
229
  wp_die( esc_html__( 'Could not switch users.', 'user-switching' ) );
230
  }
252
  } else {
253
  wp_safe_redirect( add_query_arg( $args, home_url() ) );
254
  }
255
+ exit;
256
  } else {
257
  /* Translators: "switch off" means to temporarily log out */
258
  wp_die( esc_html__( 'Could not switch off.', 'user-switching' ) );
506
  }
507
 
508
  /**
509
+ * Adds a 'Switch back to {user}' link to the Meta sidebar widget.
510
  */
511
  public function action_wp_meta() {
 
 
 
 
512
  $old_user = self::get_old_user();
513
 
514
  if ( $old_user instanceof WP_User ) {
568
  $old_user->user_login
569
  );
570
  $url = self::switch_back_url( $old_user );
571
+
572
+ if ( ! empty( $_REQUEST['interim-login'] ) ) {
573
+ $url = add_query_arg( array(
574
+ 'interim-login' => '1',
575
+ ), $url );
576
+ } elseif ( ! empty( $_REQUEST['redirect_to'] ) ) {
577
  $url = add_query_arg( array(
578
  'redirect_to' => urlencode( wp_unslash( $_REQUEST['redirect_to'] ) ), // WPCS: sanitization ok
579
  ), $url );
580
  }
581
+
582
+ $message .= '<p class="message" id="user_switching_switch_on">';
583
+ $message .= '<span class="dashicons dashicons-admin-users" style="color:#56c234"></span> ';
584
+ $message .= '<a href="' . esc_url( $url ) . '" onclick="window.location.href=\'' . esc_url( $url ) . '\';return false;">' . esc_html( $link ) . '</a>';
585
+ $message .= '</p>';
586
  }
587
 
588
  return $message;