Version Description
Download this release
Release Info
Developer | johnbillion |
Plugin | User Switching |
Version | 1.4.1 |
Comparing to | |
See all releases |
Code changes from version 1.4.0 to 1.4.1
- composer.json +8 -10
- readme.txt +4 -2
- user-switching.php +37 -12
composer.json
CHANGED
@@ -22,17 +22,15 @@
|
|
22 |
"composer/installers": "^1"
|
23 |
},
|
24 |
"require-dev" : {
|
25 |
-
"behat/
|
26 |
-
"behat/mink-
|
27 |
-
"
|
|
|
28 |
"johnbillion/php-docs-standards": "^1.2",
|
29 |
-
"
|
30 |
-
"
|
31 |
"phpunit/phpunit": "^5",
|
32 |
-
"
|
33 |
-
"wp-coding-standards/wpcs": "
|
34 |
-
},
|
35 |
-
"extra": {
|
36 |
-
"wordpress-install-dir": "vendor/wordpress"
|
37 |
}
|
38 |
}
|
22 |
"composer/installers": "^1"
|
23 |
},
|
24 |
"require-dev" : {
|
25 |
+
"behat/mink-goutte-driver": "^1.2",
|
26 |
+
"behat/mink-selenium2-driver": "^1.3",
|
27 |
+
"dealerdirect/phpcodesniffer-composer-installer": "^0.5",
|
28 |
+
"genesis/behat-fail-aid": "^2.0",
|
29 |
"johnbillion/php-docs-standards": "^1.2",
|
30 |
+
"paulgibbs/behat-wordpress-extension": "^3.1",
|
31 |
+
"phpcompatibility/php-compatibility": "^9",
|
32 |
"phpunit/phpunit": "^5",
|
33 |
+
"wp-cli/wp-cli-bundle": "^2.1",
|
34 |
+
"wp-coding-standards/wpcs": "^2"
|
|
|
|
|
|
|
35 |
}
|
36 |
}
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@
|
|
3 |
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:
|
7 |
-
Stable tag: 1.4.
|
8 |
Requires PHP: 5.3
|
9 |
License: GPL v2 or later
|
10 |
|
@@ -131,6 +131,7 @@ When a user switches back to their originating account, the `switch_back_user` h
|
|
131 |
* or a token for a session that may or may not still be valid.
|
132 |
* @param string $old_token The token of the session of the user being switched from.
|
133 |
*/
|
|
|
134 |
|
135 |
When a user switches off, the `switch_off_user` hook is called:
|
136 |
|
@@ -143,6 +144,7 @@ When a user switches off, the `switch_off_user` hook is called:
|
|
143 |
* @param int $old_user_id The ID of the user switching off.
|
144 |
* @param string $old_token The token of the session of the user switching off.
|
145 |
*/
|
|
|
146 |
|
147 |
In addition, User Switching respects the following filters from WordPress core when appropriate:
|
148 |
|
3 |
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: 5.1
|
7 |
+
Stable tag: 1.4.1
|
8 |
Requires PHP: 5.3
|
9 |
License: GPL v2 or later
|
10 |
|
131 |
* or a token for a session that may or may not still be valid.
|
132 |
* @param string $old_token The token of the session of the user being switched from.
|
133 |
*/
|
134 |
+
do_action( 'switch_back_user', $user_id, $old_user_id, $new_token, $old_token );
|
135 |
|
136 |
When a user switches off, the `switch_off_user` hook is called:
|
137 |
|
144 |
* @param int $old_user_id The ID of the user switching off.
|
145 |
* @param string $old_token The token of the session of the user switching off.
|
146 |
*/
|
147 |
+
do_action( 'switch_off_user', $old_user_id, $old_token );
|
148 |
|
149 |
In addition, User Switching respects the following filters from WordPress core when appropriate:
|
150 |
|
user-switching.php
CHANGED
@@ -5,12 +5,12 @@
|
|
5 |
* @package user-switching
|
6 |
* @link https://github.com/johnbillion/user-switching
|
7 |
* @author John Blackbourn <john@johnblackbourn.com>
|
8 |
-
* @copyright 2009-
|
9 |
* @license GPL v2 or later
|
10 |
*
|
11 |
* Plugin Name: User Switching
|
12 |
* Description: Instant switching between user accounts in WordPress
|
13 |
-
* Version: 1.4.
|
14 |
* Plugin URI: https://johnblackbourn.com/wordpress-plugin-user-switching/
|
15 |
* Author: John Blackbourn & contributors
|
16 |
* Author URI: https://github.com/johnbillion/user-switching/graphs/contributors
|
@@ -263,8 +263,8 @@ class user_switching {
|
|
263 |
*/
|
264 |
protected static function get_redirect( WP_User $new_user = null, WP_User $old_user = null ) {
|
265 |
if ( ! empty( $_REQUEST['redirect_to'] ) ) {
|
266 |
-
$redirect_to = self::remove_query_args( wp_unslash( $_REQUEST['redirect_to'] ) );
|
267 |
-
$requested_redirect_to = wp_unslash( $_REQUEST['redirect_to'] );
|
268 |
} else {
|
269 |
$redirect_to = '';
|
270 |
$requested_redirect_to = '';
|
@@ -330,7 +330,8 @@ class user_switching {
|
|
330 |
* @param bool $just_switched Whether the user made the switch on this page request.
|
331 |
*/
|
332 |
$message = apply_filters( 'user_switching_switched_message', $message, $user, $old_user, $switch_back_url, $just_switched );
|
333 |
-
|
|
|
334 |
?>
|
335 |
</p>
|
336 |
</div>
|
@@ -404,14 +405,11 @@ class user_switching {
|
|
404 |
}
|
405 |
|
406 |
/**
|
407 |
-
* Adds a 'Switch back to {user}' link to the account menu
|
408 |
*
|
409 |
* @param WP_Admin_Bar $wp_admin_bar The admin bar object.
|
410 |
*/
|
411 |
public function action_admin_bar_menu( WP_Admin_Bar $wp_admin_bar ) {
|
412 |
-
if ( ! function_exists( 'is_admin_bar_showing' ) ) {
|
413 |
-
return;
|
414 |
-
}
|
415 |
if ( ! is_admin_bar_showing() ) {
|
416 |
return;
|
417 |
}
|
@@ -462,6 +460,33 @@ class user_switching {
|
|
462 |
'href' => $url,
|
463 |
) );
|
464 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
465 |
}
|
466 |
|
467 |
/**
|
@@ -532,7 +557,7 @@ class user_switching {
|
|
532 |
), $url );
|
533 |
} elseif ( ! empty( $_REQUEST['redirect_to'] ) ) {
|
534 |
$url = add_query_arg( array(
|
535 |
-
'redirect_to' => urlencode( wp_unslash( $_REQUEST['redirect_to'] ) ),
|
536 |
), $url );
|
537 |
}
|
538 |
|
@@ -965,7 +990,7 @@ if ( ! function_exists( 'user_switching_get_olduser_cookie' ) ) {
|
|
965 |
*/
|
966 |
function user_switching_get_olduser_cookie() {
|
967 |
if ( isset( $_COOKIE[ USER_SWITCHING_OLDUSER_COOKIE ] ) ) {
|
968 |
-
return wp_unslash( $_COOKIE[ USER_SWITCHING_OLDUSER_COOKIE ] );
|
969 |
} else {
|
970 |
return false;
|
971 |
}
|
@@ -986,7 +1011,7 @@ if ( ! function_exists( 'user_switching_get_auth_cookie' ) ) {
|
|
986 |
}
|
987 |
|
988 |
if ( isset( $_COOKIE[ $auth_cookie_name ] ) && is_string( $_COOKIE[ $auth_cookie_name ] ) ) {
|
989 |
-
$cookie = json_decode( wp_unslash( $_COOKIE[ $auth_cookie_name ] ) );
|
990 |
}
|
991 |
if ( ! isset( $cookie ) || ! is_array( $cookie ) ) {
|
992 |
$cookie = array();
|
5 |
* @package user-switching
|
6 |
* @link https://github.com/johnbillion/user-switching
|
7 |
* @author John Blackbourn <john@johnblackbourn.com>
|
8 |
+
* @copyright 2009-2019 John Blackbourn
|
9 |
* @license GPL v2 or later
|
10 |
*
|
11 |
* Plugin Name: User Switching
|
12 |
* Description: Instant switching between user accounts in WordPress
|
13 |
+
* Version: 1.4.1
|
14 |
* Plugin URI: https://johnblackbourn.com/wordpress-plugin-user-switching/
|
15 |
* Author: John Blackbourn & contributors
|
16 |
* Author URI: https://github.com/johnbillion/user-switching/graphs/contributors
|
263 |
*/
|
264 |
protected static function get_redirect( WP_User $new_user = null, WP_User $old_user = null ) {
|
265 |
if ( ! empty( $_REQUEST['redirect_to'] ) ) {
|
266 |
+
$redirect_to = self::remove_query_args( wp_unslash( $_REQUEST['redirect_to'] ) );
|
267 |
+
$requested_redirect_to = wp_unslash( $_REQUEST['redirect_to'] );
|
268 |
} else {
|
269 |
$redirect_to = '';
|
270 |
$requested_redirect_to = '';
|
330 |
* @param bool $just_switched Whether the user made the switch on this page request.
|
331 |
*/
|
332 |
$message = apply_filters( 'user_switching_switched_message', $message, $user, $old_user, $switch_back_url, $just_switched );
|
333 |
+
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
334 |
+
echo $message;
|
335 |
?>
|
336 |
</p>
|
337 |
</div>
|
405 |
}
|
406 |
|
407 |
/**
|
408 |
+
* Adds a 'Switch back to {user}' link to the account menu, and a `Switch To` link to the user edit menu.
|
409 |
*
|
410 |
* @param WP_Admin_Bar $wp_admin_bar The admin bar object.
|
411 |
*/
|
412 |
public function action_admin_bar_menu( WP_Admin_Bar $wp_admin_bar ) {
|
|
|
|
|
|
|
413 |
if ( ! is_admin_bar_showing() ) {
|
414 |
return;
|
415 |
}
|
460 |
'href' => $url,
|
461 |
) );
|
462 |
}
|
463 |
+
|
464 |
+
if ( is_author() ) {
|
465 |
+
if ( $old_user ) {
|
466 |
+
$wp_admin_bar->add_menu( array(
|
467 |
+
'parent' => 'edit',
|
468 |
+
'id' => 'author-switch-back',
|
469 |
+
'title' => esc_html( sprintf(
|
470 |
+
/* Translators: 1: user display name; 2: username; */
|
471 |
+
__( 'Switch back to %1$s (%2$s)', 'user-switching' ),
|
472 |
+
$old_user->display_name,
|
473 |
+
$old_user->user_login
|
474 |
+
) ),
|
475 |
+
'href' => add_query_arg( array(
|
476 |
+
'redirect_to' => urlencode( self::current_url() ),
|
477 |
+
), self::switch_back_url( $old_user ) ),
|
478 |
+
) );
|
479 |
+
} elseif ( current_user_can( 'switch_to_user', get_queried_object_id() ) ) {
|
480 |
+
$wp_admin_bar->add_menu( array(
|
481 |
+
'parent' => 'edit',
|
482 |
+
'id' => 'author-switch-to',
|
483 |
+
'title' => esc_html__( 'Switch To', 'user-switching' ),
|
484 |
+
'href' => add_query_arg( array(
|
485 |
+
'redirect_to' => urlencode( self::current_url() ),
|
486 |
+
), self::switch_to_url( get_queried_object() ) ),
|
487 |
+
) );
|
488 |
+
}
|
489 |
+
}
|
490 |
}
|
491 |
|
492 |
/**
|
557 |
), $url );
|
558 |
} elseif ( ! empty( $_REQUEST['redirect_to'] ) ) {
|
559 |
$url = add_query_arg( array(
|
560 |
+
'redirect_to' => urlencode( wp_unslash( $_REQUEST['redirect_to'] ) ),
|
561 |
), $url );
|
562 |
}
|
563 |
|
990 |
*/
|
991 |
function user_switching_get_olduser_cookie() {
|
992 |
if ( isset( $_COOKIE[ USER_SWITCHING_OLDUSER_COOKIE ] ) ) {
|
993 |
+
return wp_unslash( $_COOKIE[ USER_SWITCHING_OLDUSER_COOKIE ] );
|
994 |
} else {
|
995 |
return false;
|
996 |
}
|
1011 |
}
|
1012 |
|
1013 |
if ( isset( $_COOKIE[ $auth_cookie_name ] ) && is_string( $_COOKIE[ $auth_cookie_name ] ) ) {
|
1014 |
+
$cookie = json_decode( wp_unslash( $_COOKIE[ $auth_cookie_name ] ) );
|
1015 |
}
|
1016 |
if ( ! isset( $cookie ) || ! is_array( $cookie ) ) {
|
1017 |
$cookie = array();
|