Version Description
- Norwegian translation by Per Sderlind.
=
Download this release
Release Info
Developer | johnbillion |
Plugin | User Switching |
Version | 1.0.5 |
Comparing to | |
See all releases |
Code changes from version 1.0.4 to 1.0.5
- composer.json +7 -2
- languages/user-switching-nb_NO.mo +0 -0
- languages/user-switching-nb_NO.po +57 -0
- readme.txt +10 -5
- user-switching.php +76 -76
composer.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
{
|
2 |
"name" : "johnbillion/user-switching",
|
3 |
"description": "WordPress plugin that provides instant switching between user accounts.",
|
4 |
-
"homepage" : "https://github.com/johnbillion/user-switching
|
5 |
"type" : "wordpress-plugin",
|
6 |
"license" : "GPL-2.0+",
|
7 |
"authors" : [
|
@@ -10,10 +10,15 @@
|
|
10 |
"homepage": "https://johnblackbourn.com/"
|
11 |
}
|
12 |
],
|
|
|
|
|
|
|
|
|
|
|
13 |
"require": {
|
14 |
"composer/installers": "~1.0"
|
15 |
},
|
16 |
"require-dev": {
|
17 |
"phpunit/phpunit": ">=3.7"
|
18 |
-
|
19 |
}
|
1 |
{
|
2 |
"name" : "johnbillion/user-switching",
|
3 |
"description": "WordPress plugin that provides instant switching between user accounts.",
|
4 |
+
"homepage" : "https://github.com/johnbillion/user-switching",
|
5 |
"type" : "wordpress-plugin",
|
6 |
"license" : "GPL-2.0+",
|
7 |
"authors" : [
|
10 |
"homepage": "https://johnblackbourn.com/"
|
11 |
}
|
12 |
],
|
13 |
+
"support": {
|
14 |
+
"issues": "https://github.com/johnbillion/user-switching/issues",
|
15 |
+
"forum": "https://wordpress.org/support/plugin/user-switching",
|
16 |
+
"source": "https://github.com/johnbillion/user-switching"
|
17 |
+
},
|
18 |
"require": {
|
19 |
"composer/installers": "~1.0"
|
20 |
},
|
21 |
"require-dev": {
|
22 |
"phpunit/phpunit": ">=3.7"
|
23 |
+
}
|
24 |
}
|
languages/user-switching-nb_NO.mo
ADDED
Binary file
|
languages/user-switching-nb_NO.po
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2013 John Blackbourn
|
2 |
+
# This file is distributed under the same license as the User Switching package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"Project-Id-Version: User Switching 0.8.3\n"
|
6 |
+
"Report-Msgid-Bugs-To: http://wordpress.org/tag/user-switching\n"
|
7 |
+
"POT-Creation-Date: 2013-10-28 23:22:09+00:00\n"
|
8 |
+
"MIME-Version: 1.0\n"
|
9 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
+
"Content-Transfer-Encoding: 8bit\n"
|
11 |
+
"PO-Revision-Date: 2015-03-30 23:13+0100\n"
|
12 |
+
"Last-Translator: Per Søderlind <per@soderlind.no>\n"
|
13 |
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
+
"Language: nb_NO\n"
|
15 |
+
"X-Generator: Poedit 1.6.5\n"
|
16 |
+
|
17 |
+
#: user-switching.php:80
|
18 |
+
msgctxt "User Switching title on user profile screen"
|
19 |
+
msgid "User Switching"
|
20 |
+
msgstr "Endre bruker"
|
21 |
+
|
22 |
+
#: user-switching.php:81 user-switching.php:355 user-switching.php:409
|
23 |
+
msgid "Switch To"
|
24 |
+
msgstr "Bytt til"
|
25 |
+
|
26 |
+
#: user-switching.php:151 user-switching.php:162 user-switching.php:172
|
27 |
+
msgid "Could not switch users."
|
28 |
+
msgstr "Kunne ikke bytte brukere"
|
29 |
+
|
30 |
+
#: user-switching.php:189
|
31 |
+
msgid "Could not switch off."
|
32 |
+
msgstr "Kunne ikke koble i fra"
|
33 |
+
|
34 |
+
#: user-switching.php:211 user-switching.php:228
|
35 |
+
msgid "Switched to %1$s (%2$s)."
|
36 |
+
msgstr "Byttet til %1$s (%2$s)."
|
37 |
+
|
38 |
+
#: user-switching.php:215 user-switching.php:275 user-switching.php:311
|
39 |
+
#: user-switching.php:329 user-switching.php:370
|
40 |
+
msgid "Switch back to %1$s (%2$s)"
|
41 |
+
msgstr "Bytt tilbake til %1$s (%2$s)"
|
42 |
+
|
43 |
+
#: user-switching.php:226
|
44 |
+
msgid "Switched back to %1$s (%2$s)."
|
45 |
+
msgstr "Byttet tilbake til %1$s (%2$s)."
|
46 |
+
|
47 |
+
#: user-switching.php:295
|
48 |
+
msgid "Switch Off"
|
49 |
+
msgstr "Koble i fra"
|
50 |
+
|
51 |
+
#. Plugin Name of the plugin/theme
|
52 |
+
msgid "User Switching"
|
53 |
+
msgstr "Endring av bruker"
|
54 |
+
|
55 |
+
#. Description of the plugin/theme
|
56 |
+
msgid "Instant switching between user accounts in WordPress"
|
57 |
+
msgstr "Bytt mellom brukerkontoer i WordPress"
|
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.1
|
6 |
Tested up to: 4.1.1
|
7 |
-
Stable tag: 1.0.
|
8 |
License: GPL v2 or later
|
9 |
|
10 |
Instant switching between user accounts in WordPress.
|
@@ -53,6 +53,7 @@ See the [FAQ](https://wordpress.org/plugins/user-switching/faq/) for information
|
|
53 |
* Italiano (Italian)
|
54 |
* 日本語 (Japanese)
|
55 |
* Lietuvių kalba (Lithuanian)
|
|
|
56 |
* فارسی (Persian)
|
57 |
* Polski (Polish)
|
58 |
* Português do Brasil (Brazilian Portuguese)
|
@@ -62,7 +63,7 @@ See the [FAQ](https://wordpress.org/plugins/user-switching/faq/) for information
|
|
62 |
* Español (Spanish)
|
63 |
* Türkçe (Turkish)
|
64 |
|
65 |
-
Thanks to translations by Hassan Hisham, Tunghsiao Liu, Francois-Xavier Bénard, Ralph Stenzel, Rami Y, Yusuke Hayasaki, Tommixoft, Amin Ab, Bartosz Arendt, Raphael Mendonça, R J, Max Samael, Eko Ikhyar, Marcelo Pedra, Abdullah Pazarbasi, ArianServ, SilverXp, Evi Giannakou, Petya Raykovska, Martin Sauter, Yaser Tallo, Enrique Errando, Sami Keijonen, Kalina Michocka, Alessandro Curci, Alessandro Tesoro, and
|
66 |
|
67 |
== Screenshots ==
|
68 |
|
@@ -122,16 +123,20 @@ When a user switches off, the `switch_off_user` hook is called with the old user
|
|
122 |
|
123 |
== Upgrade Notice ==
|
124 |
|
125 |
-
= 1.0.
|
126 |
-
*
|
127 |
|
128 |
== Changelog ==
|
129 |
|
|
|
|
|
|
|
|
|
130 |
= 1.0.4 =
|
131 |
* Support for the new `logout_redirect` and `removable_query_args` filters in WordPress 4.2.
|
132 |
|
133 |
= 1.0.3 =
|
134 |
-
* Croation translation.
|
135 |
* Avoid PHP notices caused by other plugins which erroneously use boolean `true` as a capability.
|
136 |
|
137 |
= 1.0.2 =
|
4 |
Tags: users, profiles, user switching, fast user switching, multisite, buddypress, bbpress, become, user management, developer
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 4.1.1
|
7 |
+
Stable tag: 1.0.5
|
8 |
License: GPL v2 or later
|
9 |
|
10 |
Instant switching between user accounts in WordPress.
|
53 |
* Italiano (Italian)
|
54 |
* 日本語 (Japanese)
|
55 |
* Lietuvių kalba (Lithuanian)
|
56 |
+
* Norsk bokmål (Norwegian)
|
57 |
* فارسی (Persian)
|
58 |
* Polski (Polish)
|
59 |
* Português do Brasil (Brazilian Portuguese)
|
63 |
* Español (Spanish)
|
64 |
* Türkçe (Turkish)
|
65 |
|
66 |
+
Thanks to translations by Hassan Hisham, Tunghsiao Liu, Francois-Xavier Bénard, Ralph Stenzel, Rami Y, Yusuke Hayasaki, Tommixoft, Amin Ab, Bartosz Arendt, Raphael Mendonça, R J, Max Samael, Eko Ikhyar, Marcelo Pedra, Abdullah Pazarbasi, ArianServ, SilverXp, Evi Giannakou, Petya Raykovska, Martin Sauter, Yaser Tallo, Enrique Errando, Sami Keijonen, Kalina Michocka, Alessandro Curci, Alessandro Tesoro, Ante Sepic, and Per Søderlind!
|
67 |
|
68 |
== Screenshots ==
|
69 |
|
123 |
|
124 |
== Upgrade Notice ==
|
125 |
|
126 |
+
= 1.0.5 =
|
127 |
+
* Norwegian translation by Per Søderlind.
|
128 |
|
129 |
== Changelog ==
|
130 |
|
131 |
+
= 1.0.5 =
|
132 |
+
* Norwegian translation by Per Søderlind.
|
133 |
+
* Code standards tweaks.
|
134 |
+
|
135 |
= 1.0.4 =
|
136 |
* Support for the new `logout_redirect` and `removable_query_args` filters in WordPress 4.2.
|
137 |
|
138 |
= 1.0.3 =
|
139 |
+
* Croation translation by Ante Sepic.
|
140 |
* Avoid PHP notices caused by other plugins which erroneously use boolean `true` as a capability.
|
141 |
|
142 |
= 1.0.2 =
|
user-switching.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/*
|
3 |
Plugin Name: User Switching
|
4 |
Description: Instant switching between user accounts in WordPress
|
5 |
-
Version: 1.0.
|
6 |
Plugin URI: https://johnblackbourn.com/wordpress-plugin-user-switching/
|
7 |
Author: John Blackbourn
|
8 |
Author URI: https://johnblackbourn.com/
|
@@ -62,17 +62,17 @@ class user_switching {
|
|
62 |
public function action_plugins_loaded() {
|
63 |
|
64 |
// User Switching's auth_cookie
|
65 |
-
if ( !defined( 'USER_SWITCHING_COOKIE' ) ) {
|
66 |
define( 'USER_SWITCHING_COOKIE', 'wordpress_user_sw_' . COOKIEHASH );
|
67 |
}
|
68 |
|
69 |
// User Switching's secure_auth_cookie
|
70 |
-
if ( !defined( 'USER_SWITCHING_SECURE_COOKIE' ) ) {
|
71 |
define( 'USER_SWITCHING_SECURE_COOKIE', 'wordpress_user_sw_secure_' . COOKIEHASH );
|
72 |
}
|
73 |
|
74 |
// User Switching's logged_in_cookie
|
75 |
-
if ( !defined( 'USER_SWITCHING_OLDUSER_COOKIE' ) ) {
|
76 |
if ( defined( 'OLDUSER_COOKIE' ) ) {
|
77 |
trigger_error( sprintf(
|
78 |
'The OLDUSER_COOKIE constant is deprecated. See <code>%s()</code>.',
|
@@ -99,8 +99,8 @@ class user_switching {
|
|
99 |
|
100 |
?>
|
101 |
<tr>
|
102 |
-
<th scope="row"><?php
|
103 |
-
<td><a href="<?php echo $link; ?>"><?php
|
104 |
</tr>
|
105 |
<?php
|
106 |
}
|
@@ -130,7 +130,7 @@ class user_switching {
|
|
130 |
|
131 |
load_plugin_textdomain( 'user-switching', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
|
132 |
|
133 |
-
if ( !isset( $_REQUEST['action'] ) ) {
|
134 |
return;
|
135 |
}
|
136 |
|
@@ -143,8 +143,8 @@ class user_switching {
|
|
143 |
$user_id = absint( $_REQUEST['user_id'] );
|
144 |
|
145 |
# Check authentication:
|
146 |
-
if ( !current_user_can( 'switch_to_user', $user_id ) ) {
|
147 |
-
wp_die(
|
148 |
}
|
149 |
|
150 |
# Check intent:
|
@@ -160,7 +160,7 @@ class user_switching {
|
|
160 |
$args = array( 'user_switched' => 'true' );
|
161 |
if ( $redirect_to ) {
|
162 |
wp_safe_redirect( add_query_arg( $args, $redirect_to ) );
|
163 |
-
} else if ( !current_user_can( 'read' ) ) {
|
164 |
wp_redirect( add_query_arg( $args, home_url() ) );
|
165 |
} else {
|
166 |
wp_redirect( add_query_arg( $args, admin_url() ) );
|
@@ -168,7 +168,7 @@ class user_switching {
|
|
168 |
die();
|
169 |
|
170 |
} else {
|
171 |
-
wp_die(
|
172 |
}
|
173 |
break;
|
174 |
|
@@ -176,13 +176,13 @@ class user_switching {
|
|
176 |
case 'switch_to_olduser':
|
177 |
|
178 |
# Fetch the originating user data:
|
179 |
-
if (
|
180 |
-
wp_die(
|
181 |
}
|
182 |
|
183 |
# Check authentication:
|
184 |
-
if ( !self::authenticate_old_user( $old_user ) ) {
|
185 |
-
wp_die(
|
186 |
}
|
187 |
|
188 |
# Check intent:
|
@@ -200,7 +200,7 @@ class user_switching {
|
|
200 |
}
|
201 |
die();
|
202 |
} else {
|
203 |
-
wp_die(
|
204 |
}
|
205 |
break;
|
206 |
|
@@ -208,8 +208,8 @@ class user_switching {
|
|
208 |
case 'switch_off':
|
209 |
|
210 |
# Check authentication:
|
211 |
-
if ( !current_user_can( 'switch_off' ) ) {
|
212 |
-
wp_die(
|
213 |
}
|
214 |
|
215 |
# Check intent:
|
@@ -226,7 +226,7 @@ class user_switching {
|
|
226 |
}
|
227 |
die();
|
228 |
} else {
|
229 |
-
wp_die(
|
230 |
}
|
231 |
break;
|
232 |
|
@@ -243,7 +243,7 @@ class user_switching {
|
|
243 |
*/
|
244 |
protected static function get_redirect( WP_User $new_user = null, WP_User $old_user = null ) {
|
245 |
|
246 |
-
if ( isset( $_REQUEST['redirect_to'] ) and !empty( $_REQUEST['redirect_to'] ) ) {
|
247 |
$redirect_to = self::remove_query_args( $_REQUEST['redirect_to'] );
|
248 |
$requested_redirect_to = $_REQUEST['redirect_to'];
|
249 |
} else {
|
@@ -274,12 +274,12 @@ class user_switching {
|
|
274 |
<p><span class="dashicons dashicons-admin-users" style="color:#56c234"></span>
|
275 |
<?php
|
276 |
if ( isset( $_GET['user_switched'] ) ) {
|
277 |
-
printf(
|
278 |
}
|
279 |
$url = add_query_arg( array(
|
280 |
-
'redirect_to' => urlencode( self::current_url() )
|
281 |
), self::switch_back_url( $old_user ) );
|
282 |
-
printf( ' <a href="%s">%s</a>.', $url, sprintf(
|
283 |
?></p>
|
284 |
</div>
|
285 |
<?php
|
@@ -290,9 +290,9 @@ class user_switching {
|
|
290 |
<div id="user_switching" class="updated">
|
291 |
<p><?php
|
292 |
if ( isset( $_GET['switched_back'] ) ) {
|
293 |
-
printf(
|
294 |
} else {
|
295 |
-
printf(
|
296 |
}
|
297 |
?></p>
|
298 |
</div>
|
@@ -308,7 +308,7 @@ class user_switching {
|
|
308 |
*/
|
309 |
public static function get_old_user() {
|
310 |
$cookie = user_switching_get_olduser_cookie();
|
311 |
-
if ( !empty( $cookie ) ) {
|
312 |
if ( $old_user_id = wp_validate_auth_cookie( $cookie, 'logged_in' ) ) {
|
313 |
return get_userdata( $old_user_id );
|
314 |
}
|
@@ -318,13 +318,13 @@ class user_switching {
|
|
318 |
|
319 |
/**
|
320 |
* Authenticate an old user by verifying the latest entry in the auth cookie.
|
321 |
-
*
|
322 |
* @param WP_User $user A WP_User object (usually from the logged_in cookie).
|
323 |
* @return bool Whether verification with the auth cookie passed.
|
324 |
*/
|
325 |
public static function authenticate_old_user( WP_User $user ) {
|
326 |
$cookie = user_switching_get_auth_cookie();
|
327 |
-
if ( !empty( $cookie ) ) {
|
328 |
|
329 |
if ( user_switching::secure_auth_cookie() ) {
|
330 |
$scheme = 'secure_auth';
|
@@ -345,10 +345,10 @@ class user_switching {
|
|
345 |
*/
|
346 |
public function action_admin_bar_menu( WP_Admin_Bar $wp_admin_bar ) {
|
347 |
|
348 |
-
if ( !function_exists( 'is_admin_bar_showing' ) ) {
|
349 |
return;
|
350 |
}
|
351 |
-
if ( !is_admin_bar_showing() ) {
|
352 |
return;
|
353 |
}
|
354 |
|
@@ -365,9 +365,9 @@ class user_switching {
|
|
365 |
$wp_admin_bar->add_menu( array(
|
366 |
'parent' => $parent,
|
367 |
'id' => 'switch-back',
|
368 |
-
'title' => sprintf(
|
369 |
'href' => add_query_arg( array(
|
370 |
-
'redirect_to' => urlencode( self::current_url() )
|
371 |
), self::switch_back_url( $old_user ) )
|
372 |
) );
|
373 |
|
@@ -376,17 +376,17 @@ class user_switching {
|
|
376 |
if ( current_user_can( 'switch_off' ) ) {
|
377 |
|
378 |
$url = self::switch_off_url( wp_get_current_user() );
|
379 |
-
if ( !is_admin() ) {
|
380 |
$url = add_query_arg( array(
|
381 |
-
'redirect_to' => urlencode( self::current_url() )
|
382 |
), $url );
|
383 |
}
|
384 |
|
385 |
$wp_admin_bar->add_menu( array(
|
386 |
'parent' => $parent,
|
387 |
'id' => 'switch-off',
|
388 |
-
'title' =>
|
389 |
-
'href' => $url
|
390 |
) );
|
391 |
|
392 |
}
|
@@ -398,12 +398,12 @@ class user_switching {
|
|
398 |
*/
|
399 |
public function action_wp_meta() {
|
400 |
|
401 |
-
if ( !is_admin_bar_showing() and $old_user = self::get_old_user() ) {
|
402 |
$link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login );
|
403 |
$url = add_query_arg( array(
|
404 |
'redirect_to' => urlencode( self::current_url() )
|
405 |
), self::switch_back_url( $old_user ) );
|
406 |
-
echo '<li id="user_switching_switch_on"><a href="' . $url . '">' . $link . '</a></li>';
|
407 |
}
|
408 |
|
409 |
}
|
@@ -413,12 +413,12 @@ class user_switching {
|
|
413 |
*/
|
414 |
public function action_wp_footer() {
|
415 |
|
416 |
-
if ( !did_action( 'wp_meta' ) and !is_admin_bar_showing() and $old_user = self::get_old_user() ) {
|
417 |
$link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login );
|
418 |
$url = add_query_arg( array(
|
419 |
'redirect_to' => urlencode( self::current_url() )
|
420 |
), self::switch_back_url( $old_user ) );
|
421 |
-
echo '<p id="user_switching_switch_on"><a href="' . $url . '">' . $link . '</a></p>';
|
422 |
}
|
423 |
|
424 |
}
|
@@ -434,12 +434,12 @@ class user_switching {
|
|
434 |
if ( $old_user = self::get_old_user() ) {
|
435 |
$link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login );
|
436 |
$url = self::switch_back_url( $old_user );
|
437 |
-
if ( isset( $_REQUEST['redirect_to'] ) and !empty( $_REQUEST['redirect_to'] ) ) {
|
438 |
$url = add_query_arg( array(
|
439 |
'redirect_to' => urlencode( $_REQUEST['redirect_to'] )
|
440 |
), $url );
|
441 |
}
|
442 |
-
$message .= '<p class="message"><span class="dashicons dashicons-admin-users" style="color:#56c234"></span> <a href="' . $url . '">' . $link . '</a></p>';
|
443 |
}
|
444 |
|
445 |
return $message;
|
@@ -459,7 +459,7 @@ class user_switching {
|
|
459 |
return $actions;
|
460 |
}
|
461 |
|
462 |
-
$actions['switch_to_user'] = '<a href="' . $link . '">' .
|
463 |
|
464 |
return $actions;
|
465 |
}
|
@@ -471,7 +471,7 @@ class user_switching {
|
|
471 |
|
472 |
global $bp, $members_template;
|
473 |
|
474 |
-
if ( !empty( $members_template ) and empty( $bp->displayed_user->id ) ) {
|
475 |
$user = get_userdata( $members_template->member->id );
|
476 |
} else {
|
477 |
$user = get_userdata( $bp->displayed_user->id );
|
@@ -485,12 +485,12 @@ class user_switching {
|
|
485 |
}
|
486 |
|
487 |
$link = add_query_arg( array(
|
488 |
-
'redirect_to' => urlencode( bp_core_get_user_domain( $user->ID ) )
|
489 |
), $link );
|
490 |
|
491 |
# Workaround for https://buddypress.trac.wordpress.org/ticket/4212
|
492 |
$components = array_keys( $bp->active_components );
|
493 |
-
if ( !empty( $components ) ) {
|
494 |
$component = reset( $components );
|
495 |
} else {
|
496 |
$component = 'core';
|
@@ -499,8 +499,8 @@ class user_switching {
|
|
499 |
echo bp_get_button( array(
|
500 |
'id' => 'user_switching',
|
501 |
'component' => $component,
|
502 |
-
'link_href' => $link,
|
503 |
-
'link_text' =>
|
504 |
) );
|
505 |
|
506 |
}
|
@@ -518,12 +518,12 @@ class user_switching {
|
|
518 |
}
|
519 |
|
520 |
$link = add_query_arg( array(
|
521 |
-
'redirect_to' => urlencode( bbp_get_user_profile_url( $user->ID ) )
|
522 |
), $link );
|
523 |
|
524 |
?>
|
525 |
<ul>
|
526 |
-
<li><a href="<?php echo $link; ?>"><?php
|
527 |
</ul>
|
528 |
<?php
|
529 |
|
@@ -531,7 +531,7 @@ class user_switching {
|
|
531 |
|
532 |
/**
|
533 |
* Filter the list of query arguments which get removed from admin area URLs in WordPress.
|
534 |
-
*
|
535 |
* @link https://core.trac.wordpress.org/ticket/23367
|
536 |
*
|
537 |
* @param array $args List of removable query arguments.
|
@@ -555,7 +555,7 @@ class user_switching {
|
|
555 |
|
556 |
if ( $old_user and ( $old_user->ID == $user->ID ) ) {
|
557 |
return self::switch_back_url( $old_user );
|
558 |
-
} else if ( current_user_can( 'switch_to_user', $user->ID ) ) {
|
559 |
return self::switch_to_url( $user );
|
560 |
} else {
|
561 |
return false;
|
@@ -572,7 +572,7 @@ class user_switching {
|
|
572 |
public static function switch_to_url( WP_User $user ) {
|
573 |
return wp_nonce_url( add_query_arg( array(
|
574 |
'action' => 'switch_to_user',
|
575 |
-
'user_id' => $user->ID
|
576 |
), wp_login_url() ), "switch_to_user_{$user->ID}" );
|
577 |
}
|
578 |
|
@@ -584,7 +584,7 @@ class user_switching {
|
|
584 |
*/
|
585 |
public static function switch_back_url( WP_User $user ) {
|
586 |
return wp_nonce_url( add_query_arg( array(
|
587 |
-
'action' => 'switch_to_olduser'
|
588 |
), wp_login_url() ), "switch_to_olduser_{$user->ID}" );
|
589 |
}
|
590 |
|
@@ -596,7 +596,7 @@ class user_switching {
|
|
596 |
*/
|
597 |
public static function switch_off_url( WP_User $user ) {
|
598 |
return wp_nonce_url( add_query_arg( array(
|
599 |
-
'action' => 'switch_off'
|
600 |
), wp_login_url() ), "switch_off_{$user->ID}" );
|
601 |
}
|
602 |
|
@@ -619,7 +619,8 @@ class user_switching {
|
|
619 |
$args = apply_filters( 'removable_query_args', array(
|
620 |
'message', 'update', 'updated', 'settings-updated', 'saved',
|
621 |
'activated', 'activate', 'deactivate', 'enabled', 'disabled',
|
622 |
-
'locked', 'skipped', 'deleted', 'trashed', 'untrashed'
|
|
|
623 |
) );
|
624 |
return remove_query_arg( $args, $url );
|
625 |
}
|
@@ -628,7 +629,7 @@ class user_switching {
|
|
628 |
* Helper function. Should User Switching's equivalent of the 'logged_in' cookie be secure?
|
629 |
*
|
630 |
* This is used to set the 'secure' flag on the old user cookie, for enhanced security.
|
631 |
-
*
|
632 |
* @link https://core.trac.wordpress.org/ticket/15330
|
633 |
*
|
634 |
* @return bool Should the old user cookie be secure?
|
@@ -639,7 +640,7 @@ class user_switching {
|
|
639 |
|
640 |
/**
|
641 |
* Helper function. Should User Switching's equivalent of the 'auth' cookie be secure?
|
642 |
-
*
|
643 |
* This is used to determine whether to set a secure auth cookie or not.
|
644 |
*
|
645 |
* @return bool Should the auth cookie be secure?
|
@@ -710,7 +711,7 @@ class user_switching {
|
|
710 |
|
711 |
}
|
712 |
|
713 |
-
if ( !function_exists( 'user_switching_set_olduser_cookie' ) ) {
|
714 |
/**
|
715 |
* Sets authorisation cookies containing the originating user information.
|
716 |
*
|
@@ -743,15 +744,15 @@ function user_switching_set_olduser_cookie( $old_user_id, $pop = false ) {
|
|
743 |
}
|
744 |
}
|
745 |
|
746 |
-
if ( !function_exists( 'user_switching_clear_olduser_cookie' ) ) {
|
747 |
/**
|
748 |
* Clears the cookies containing the originating user, or pops the latest item off the end if there's more than one.
|
749 |
-
*
|
750 |
* @param bool $clear_all Whether to clear the cookies or just pop the last user information off the end.
|
751 |
*/
|
752 |
function user_switching_clear_olduser_cookie( $clear_all = true ) {
|
753 |
$auth_cookie = user_switching_get_auth_cookie();
|
754 |
-
if ( !empty( $auth_cookie ) ) {
|
755 |
array_pop( $auth_cookie );
|
756 |
}
|
757 |
if ( $clear_all or empty( $auth_cookie ) ) {
|
@@ -770,27 +771,26 @@ function user_switching_clear_olduser_cookie( $clear_all = true ) {
|
|
770 |
if ( $old_user_id = wp_validate_auth_cookie( end( $auth_cookie ), $scheme ) ) {
|
771 |
user_switching_set_olduser_cookie( $old_user_id, true );
|
772 |
}
|
773 |
-
|
774 |
}
|
775 |
}
|
776 |
}
|
777 |
|
778 |
-
if ( !function_exists( 'user_switching_get_olduser_cookie' ) ) {
|
779 |
/**
|
780 |
* Gets the value of the cookie containing the originating user.
|
781 |
*
|
782 |
* @return string|bool The old user cookie, or boolean false if there isn't one.
|
783 |
*/
|
784 |
function user_switching_get_olduser_cookie() {
|
785 |
-
if ( isset( $_COOKIE[USER_SWITCHING_OLDUSER_COOKIE] ) ) {
|
786 |
-
return stripslashes( $_COOKIE[USER_SWITCHING_OLDUSER_COOKIE] );
|
787 |
} else {
|
788 |
return false;
|
789 |
}
|
790 |
}
|
791 |
}
|
792 |
|
793 |
-
if ( !function_exists( 'user_switching_get_auth_cookie' ) ) {
|
794 |
/**
|
795 |
* Gets the value of the auth cookie containing the list of originating users.
|
796 |
*
|
@@ -803,17 +803,17 @@ function user_switching_get_auth_cookie() {
|
|
803 |
$auth_cookie_name = USER_SWITCHING_COOKIE;
|
804 |
}
|
805 |
|
806 |
-
if ( isset( $_COOKIE[$auth_cookie_name] ) ) {
|
807 |
-
$cookie = json_decode( stripslashes( $_COOKIE[$auth_cookie_name] ) );
|
808 |
}
|
809 |
-
if ( !isset( $cookie ) or !is_array( $cookie ) ) {
|
810 |
$cookie = array();
|
811 |
}
|
812 |
return $cookie;
|
813 |
}
|
814 |
}
|
815 |
|
816 |
-
if ( !function_exists( 'switch_to_user' ) ) {
|
817 |
/**
|
818 |
* Switches the current logged in user to the specified user.
|
819 |
*
|
@@ -823,7 +823,7 @@ if ( !function_exists( 'switch_to_user' ) ) {
|
|
823 |
* @return bool|WP_User WP_User object on success, false on failure.
|
824 |
*/
|
825 |
function switch_to_user( $user_id, $remember = false, $set_old_user = true ) {
|
826 |
-
if (
|
827 |
return false;
|
828 |
}
|
829 |
|
@@ -849,7 +849,7 @@ function switch_to_user( $user_id, $remember = false, $set_old_user = true ) {
|
|
849 |
}
|
850 |
}
|
851 |
|
852 |
-
if ( !function_exists( 'switch_off_user' ) ) {
|
853 |
/**
|
854 |
* Switches off the current logged in user. This logs the current user out while retaining a cookie allowing them to log
|
855 |
* straight back in using the 'Switch back to {user}' system.
|
@@ -857,7 +857,7 @@ if ( !function_exists( 'switch_off_user' ) ) {
|
|
857 |
* @return bool True on success, false on failure.
|
858 |
*/
|
859 |
function switch_off_user() {
|
860 |
-
if (
|
861 |
return false;
|
862 |
}
|
863 |
|
@@ -870,7 +870,7 @@ function switch_off_user() {
|
|
870 |
}
|
871 |
}
|
872 |
|
873 |
-
if ( !function_exists( 'current_user_switched' ) ) {
|
874 |
/**
|
875 |
* Helper function. Did the current user switch into their account?
|
876 |
*
|
@@ -878,7 +878,7 @@ if ( !function_exists( 'current_user_switched' ) ) {
|
|
878 |
* true) if the user switched into the current user account.
|
879 |
*/
|
880 |
function current_user_switched() {
|
881 |
-
if ( !is_user_logged_in() ) {
|
882 |
return false;
|
883 |
}
|
884 |
|
2 |
/*
|
3 |
Plugin Name: User Switching
|
4 |
Description: Instant switching between user accounts in WordPress
|
5 |
+
Version: 1.0.5
|
6 |
Plugin URI: https://johnblackbourn.com/wordpress-plugin-user-switching/
|
7 |
Author: John Blackbourn
|
8 |
Author URI: https://johnblackbourn.com/
|
62 |
public function action_plugins_loaded() {
|
63 |
|
64 |
// User Switching's auth_cookie
|
65 |
+
if ( ! defined( 'USER_SWITCHING_COOKIE' ) ) {
|
66 |
define( 'USER_SWITCHING_COOKIE', 'wordpress_user_sw_' . COOKIEHASH );
|
67 |
}
|
68 |
|
69 |
// User Switching's secure_auth_cookie
|
70 |
+
if ( ! defined( 'USER_SWITCHING_SECURE_COOKIE' ) ) {
|
71 |
define( 'USER_SWITCHING_SECURE_COOKIE', 'wordpress_user_sw_secure_' . COOKIEHASH );
|
72 |
}
|
73 |
|
74 |
// User Switching's logged_in_cookie
|
75 |
+
if ( ! defined( 'USER_SWITCHING_OLDUSER_COOKIE' ) ) {
|
76 |
if ( defined( 'OLDUSER_COOKIE' ) ) {
|
77 |
trigger_error( sprintf(
|
78 |
'The OLDUSER_COOKIE constant is deprecated. See <code>%s()</code>.',
|
99 |
|
100 |
?>
|
101 |
<tr>
|
102 |
+
<th scope="row"><?php esc_html_x( 'User Switching', 'User Switching title on user profile screen', 'user-switching' ); ?></th>
|
103 |
+
<td><a href="<?php echo esc_url( $link ); ?>"><?php esc_html_e( 'Switch To', 'user-switching' ); ?></a></td>
|
104 |
</tr>
|
105 |
<?php
|
106 |
}
|
130 |
|
131 |
load_plugin_textdomain( 'user-switching', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
|
132 |
|
133 |
+
if ( ! isset( $_REQUEST['action'] ) ) {
|
134 |
return;
|
135 |
}
|
136 |
|
143 |
$user_id = absint( $_REQUEST['user_id'] );
|
144 |
|
145 |
# Check authentication:
|
146 |
+
if ( ! current_user_can( 'switch_to_user', $user_id ) ) {
|
147 |
+
wp_die( esc_html__( 'Could not switch users.', 'user-switching' ) );
|
148 |
}
|
149 |
|
150 |
# Check intent:
|
160 |
$args = array( 'user_switched' => 'true' );
|
161 |
if ( $redirect_to ) {
|
162 |
wp_safe_redirect( add_query_arg( $args, $redirect_to ) );
|
163 |
+
} else if ( ! current_user_can( 'read' ) ) {
|
164 |
wp_redirect( add_query_arg( $args, home_url() ) );
|
165 |
} else {
|
166 |
wp_redirect( add_query_arg( $args, admin_url() ) );
|
168 |
die();
|
169 |
|
170 |
} else {
|
171 |
+
wp_die( esc_html__( 'Could not switch users.', 'user-switching' ) );
|
172 |
}
|
173 |
break;
|
174 |
|
176 |
case 'switch_to_olduser':
|
177 |
|
178 |
# Fetch the originating user data:
|
179 |
+
if ( ! $old_user = self::get_old_user() ) {
|
180 |
+
wp_die( esc_html__( 'Could not switch users.', 'user-switching' ) );
|
181 |
}
|
182 |
|
183 |
# Check authentication:
|
184 |
+
if ( ! self::authenticate_old_user( $old_user ) ) {
|
185 |
+
wp_die( esc_html__( 'Could not switch users.', 'user-switching' ) );
|
186 |
}
|
187 |
|
188 |
# Check intent:
|
200 |
}
|
201 |
die();
|
202 |
} else {
|
203 |
+
wp_die( esc_html__( 'Could not switch users.', 'user-switching' ) );
|
204 |
}
|
205 |
break;
|
206 |
|
208 |
case 'switch_off':
|
209 |
|
210 |
# Check authentication:
|
211 |
+
if ( ! current_user_can( 'switch_off' ) ) {
|
212 |
+
wp_die( esc_html__( 'Could not switch off.', 'user-switching' ) );
|
213 |
}
|
214 |
|
215 |
# Check intent:
|
226 |
}
|
227 |
die();
|
228 |
} else {
|
229 |
+
wp_die( esc_html__( 'Could not switch off.', 'user-switching' ) );
|
230 |
}
|
231 |
break;
|
232 |
|
243 |
*/
|
244 |
protected static function get_redirect( WP_User $new_user = null, WP_User $old_user = null ) {
|
245 |
|
246 |
+
if ( isset( $_REQUEST['redirect_to'] ) and ! empty( $_REQUEST['redirect_to'] ) ) {
|
247 |
$redirect_to = self::remove_query_args( $_REQUEST['redirect_to'] );
|
248 |
$requested_redirect_to = $_REQUEST['redirect_to'];
|
249 |
} else {
|
274 |
<p><span class="dashicons dashicons-admin-users" style="color:#56c234"></span>
|
275 |
<?php
|
276 |
if ( isset( $_GET['user_switched'] ) ) {
|
277 |
+
printf( esc_html__( 'Switched to %1$s (%2$s).', 'user-switching' ), $user->display_name, $user->user_login );
|
278 |
}
|
279 |
$url = add_query_arg( array(
|
280 |
+
'redirect_to' => urlencode( self::current_url() ),
|
281 |
), self::switch_back_url( $old_user ) );
|
282 |
+
printf( ' <a href="%s">%s</a>.', esc_url( $url ), sprintf( esc_html__( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login ) );
|
283 |
?></p>
|
284 |
</div>
|
285 |
<?php
|
290 |
<div id="user_switching" class="updated">
|
291 |
<p><?php
|
292 |
if ( isset( $_GET['switched_back'] ) ) {
|
293 |
+
printf( esc_html__( 'Switched back to %1$s (%2$s).', 'user-switching' ), $user->display_name, $user->user_login );
|
294 |
} else {
|
295 |
+
printf( esc_html__( 'Switched to %1$s (%2$s).', 'user-switching' ), $user->display_name, $user->user_login );
|
296 |
}
|
297 |
?></p>
|
298 |
</div>
|
308 |
*/
|
309 |
public static function get_old_user() {
|
310 |
$cookie = user_switching_get_olduser_cookie();
|
311 |
+
if ( ! empty( $cookie ) ) {
|
312 |
if ( $old_user_id = wp_validate_auth_cookie( $cookie, 'logged_in' ) ) {
|
313 |
return get_userdata( $old_user_id );
|
314 |
}
|
318 |
|
319 |
/**
|
320 |
* Authenticate an old user by verifying the latest entry in the auth cookie.
|
321 |
+
*
|
322 |
* @param WP_User $user A WP_User object (usually from the logged_in cookie).
|
323 |
* @return bool Whether verification with the auth cookie passed.
|
324 |
*/
|
325 |
public static function authenticate_old_user( WP_User $user ) {
|
326 |
$cookie = user_switching_get_auth_cookie();
|
327 |
+
if ( ! empty( $cookie ) ) {
|
328 |
|
329 |
if ( user_switching::secure_auth_cookie() ) {
|
330 |
$scheme = 'secure_auth';
|
345 |
*/
|
346 |
public function action_admin_bar_menu( WP_Admin_Bar $wp_admin_bar ) {
|
347 |
|
348 |
+
if ( ! function_exists( 'is_admin_bar_showing' ) ) {
|
349 |
return;
|
350 |
}
|
351 |
+
if ( ! is_admin_bar_showing() ) {
|
352 |
return;
|
353 |
}
|
354 |
|
365 |
$wp_admin_bar->add_menu( array(
|
366 |
'parent' => $parent,
|
367 |
'id' => 'switch-back',
|
368 |
+
'title' => sprintf( esc_html__( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login ),
|
369 |
'href' => add_query_arg( array(
|
370 |
+
'redirect_to' => urlencode( self::current_url() ),
|
371 |
), self::switch_back_url( $old_user ) )
|
372 |
) );
|
373 |
|
376 |
if ( current_user_can( 'switch_off' ) ) {
|
377 |
|
378 |
$url = self::switch_off_url( wp_get_current_user() );
|
379 |
+
if ( ! is_admin() ) {
|
380 |
$url = add_query_arg( array(
|
381 |
+
'redirect_to' => urlencode( self::current_url() ),
|
382 |
), $url );
|
383 |
}
|
384 |
|
385 |
$wp_admin_bar->add_menu( array(
|
386 |
'parent' => $parent,
|
387 |
'id' => 'switch-off',
|
388 |
+
'title' => esc_html__( 'Switch Off', 'user-switching' ),
|
389 |
+
'href' => $url,
|
390 |
) );
|
391 |
|
392 |
}
|
398 |
*/
|
399 |
public function action_wp_meta() {
|
400 |
|
401 |
+
if ( ! is_admin_bar_showing() and $old_user = self::get_old_user() ) {
|
402 |
$link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login );
|
403 |
$url = add_query_arg( array(
|
404 |
'redirect_to' => urlencode( self::current_url() )
|
405 |
), self::switch_back_url( $old_user ) );
|
406 |
+
echo '<li id="user_switching_switch_on"><a href="' . esc_url( $url ) . '">' . esc_html( $link ) . '</a></li>';
|
407 |
}
|
408 |
|
409 |
}
|
413 |
*/
|
414 |
public function action_wp_footer() {
|
415 |
|
416 |
+
if ( ! did_action( 'wp_meta' ) and ! is_admin_bar_showing() and $old_user = self::get_old_user() ) {
|
417 |
$link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login );
|
418 |
$url = add_query_arg( array(
|
419 |
'redirect_to' => urlencode( self::current_url() )
|
420 |
), self::switch_back_url( $old_user ) );
|
421 |
+
echo '<p id="user_switching_switch_on"><a href="' . esc_url( $url ) . '">' . esc_html( $link ) . '</a></p>';
|
422 |
}
|
423 |
|
424 |
}
|
434 |
if ( $old_user = self::get_old_user() ) {
|
435 |
$link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login );
|
436 |
$url = self::switch_back_url( $old_user );
|
437 |
+
if ( isset( $_REQUEST['redirect_to'] ) and ! empty( $_REQUEST['redirect_to'] ) ) {
|
438 |
$url = add_query_arg( array(
|
439 |
'redirect_to' => urlencode( $_REQUEST['redirect_to'] )
|
440 |
), $url );
|
441 |
}
|
442 |
+
$message .= '<p class="message"><span class="dashicons dashicons-admin-users" style="color:#56c234"></span> <a href="' . esc_url( $url ) . '">' . esc_html( $link ) . '</a></p>';
|
443 |
}
|
444 |
|
445 |
return $message;
|
459 |
return $actions;
|
460 |
}
|
461 |
|
462 |
+
$actions['switch_to_user'] = '<a href="' . esc_url( $link ) . '">' . esc_html__( 'Switch To', 'user-switching' ) . '</a>';
|
463 |
|
464 |
return $actions;
|
465 |
}
|
471 |
|
472 |
global $bp, $members_template;
|
473 |
|
474 |
+
if ( ! empty( $members_template ) and empty( $bp->displayed_user->id ) ) {
|
475 |
$user = get_userdata( $members_template->member->id );
|
476 |
} else {
|
477 |
$user = get_userdata( $bp->displayed_user->id );
|
485 |
}
|
486 |
|
487 |
$link = add_query_arg( array(
|
488 |
+
'redirect_to' => urlencode( bp_core_get_user_domain( $user->ID ) ),
|
489 |
), $link );
|
490 |
|
491 |
# Workaround for https://buddypress.trac.wordpress.org/ticket/4212
|
492 |
$components = array_keys( $bp->active_components );
|
493 |
+
if ( ! empty( $components ) ) {
|
494 |
$component = reset( $components );
|
495 |
} else {
|
496 |
$component = 'core';
|
499 |
echo bp_get_button( array(
|
500 |
'id' => 'user_switching',
|
501 |
'component' => $component,
|
502 |
+
'link_href' => esc_url( $link ),
|
503 |
+
'link_text' => esc_html__( 'Switch To', 'user-switching' ),
|
504 |
) );
|
505 |
|
506 |
}
|
518 |
}
|
519 |
|
520 |
$link = add_query_arg( array(
|
521 |
+
'redirect_to' => urlencode( bbp_get_user_profile_url( $user->ID ) ),
|
522 |
), $link );
|
523 |
|
524 |
?>
|
525 |
<ul>
|
526 |
+
<li><a href="<?php echo esc_url( $link ); ?>"><?php esc_html_e( 'Switch To', 'user-switching' ); ?></a></li>
|
527 |
</ul>
|
528 |
<?php
|
529 |
|
531 |
|
532 |
/**
|
533 |
* Filter the list of query arguments which get removed from admin area URLs in WordPress.
|
534 |
+
*
|
535 |
* @link https://core.trac.wordpress.org/ticket/23367
|
536 |
*
|
537 |
* @param array $args List of removable query arguments.
|
555 |
|
556 |
if ( $old_user and ( $old_user->ID == $user->ID ) ) {
|
557 |
return self::switch_back_url( $old_user );
|
558 |
+
} else if ( current_user_can( 'switch_to_user', $user->ID ) ) {
|
559 |
return self::switch_to_url( $user );
|
560 |
} else {
|
561 |
return false;
|
572 |
public static function switch_to_url( WP_User $user ) {
|
573 |
return wp_nonce_url( add_query_arg( array(
|
574 |
'action' => 'switch_to_user',
|
575 |
+
'user_id' => $user->ID,
|
576 |
), wp_login_url() ), "switch_to_user_{$user->ID}" );
|
577 |
}
|
578 |
|
584 |
*/
|
585 |
public static function switch_back_url( WP_User $user ) {
|
586 |
return wp_nonce_url( add_query_arg( array(
|
587 |
+
'action' => 'switch_to_olduser',
|
588 |
), wp_login_url() ), "switch_to_olduser_{$user->ID}" );
|
589 |
}
|
590 |
|
596 |
*/
|
597 |
public static function switch_off_url( WP_User $user ) {
|
598 |
return wp_nonce_url( add_query_arg( array(
|
599 |
+
'action' => 'switch_off',
|
600 |
), wp_login_url() ), "switch_off_{$user->ID}" );
|
601 |
}
|
602 |
|
619 |
$args = apply_filters( 'removable_query_args', array(
|
620 |
'message', 'update', 'updated', 'settings-updated', 'saved',
|
621 |
'activated', 'activate', 'deactivate', 'enabled', 'disabled',
|
622 |
+
'locked', 'skipped', 'deleted', 'trashed', 'untrashed',
|
623 |
+
'spammed', 'unspammed',
|
624 |
) );
|
625 |
return remove_query_arg( $args, $url );
|
626 |
}
|
629 |
* Helper function. Should User Switching's equivalent of the 'logged_in' cookie be secure?
|
630 |
*
|
631 |
* This is used to set the 'secure' flag on the old user cookie, for enhanced security.
|
632 |
+
*
|
633 |
* @link https://core.trac.wordpress.org/ticket/15330
|
634 |
*
|
635 |
* @return bool Should the old user cookie be secure?
|
640 |
|
641 |
/**
|
642 |
* Helper function. Should User Switching's equivalent of the 'auth' cookie be secure?
|
643 |
+
*
|
644 |
* This is used to determine whether to set a secure auth cookie or not.
|
645 |
*
|
646 |
* @return bool Should the auth cookie be secure?
|
711 |
|
712 |
}
|
713 |
|
714 |
+
if ( ! function_exists( 'user_switching_set_olduser_cookie' ) ) {
|
715 |
/**
|
716 |
* Sets authorisation cookies containing the originating user information.
|
717 |
*
|
744 |
}
|
745 |
}
|
746 |
|
747 |
+
if ( ! function_exists( 'user_switching_clear_olduser_cookie' ) ) {
|
748 |
/**
|
749 |
* Clears the cookies containing the originating user, or pops the latest item off the end if there's more than one.
|
750 |
+
*
|
751 |
* @param bool $clear_all Whether to clear the cookies or just pop the last user information off the end.
|
752 |
*/
|
753 |
function user_switching_clear_olduser_cookie( $clear_all = true ) {
|
754 |
$auth_cookie = user_switching_get_auth_cookie();
|
755 |
+
if ( ! empty( $auth_cookie ) ) {
|
756 |
array_pop( $auth_cookie );
|
757 |
}
|
758 |
if ( $clear_all or empty( $auth_cookie ) ) {
|
771 |
if ( $old_user_id = wp_validate_auth_cookie( end( $auth_cookie ), $scheme ) ) {
|
772 |
user_switching_set_olduser_cookie( $old_user_id, true );
|
773 |
}
|
|
|
774 |
}
|
775 |
}
|
776 |
}
|
777 |
|
778 |
+
if ( ! function_exists( 'user_switching_get_olduser_cookie' ) ) {
|
779 |
/**
|
780 |
* Gets the value of the cookie containing the originating user.
|
781 |
*
|
782 |
* @return string|bool The old user cookie, or boolean false if there isn't one.
|
783 |
*/
|
784 |
function user_switching_get_olduser_cookie() {
|
785 |
+
if ( isset( $_COOKIE[ USER_SWITCHING_OLDUSER_COOKIE ] ) ) {
|
786 |
+
return stripslashes( $_COOKIE[ USER_SWITCHING_OLDUSER_COOKIE ] );
|
787 |
} else {
|
788 |
return false;
|
789 |
}
|
790 |
}
|
791 |
}
|
792 |
|
793 |
+
if ( ! function_exists( 'user_switching_get_auth_cookie' ) ) {
|
794 |
/**
|
795 |
* Gets the value of the auth cookie containing the list of originating users.
|
796 |
*
|
803 |
$auth_cookie_name = USER_SWITCHING_COOKIE;
|
804 |
}
|
805 |
|
806 |
+
if ( isset( $_COOKIE[ $auth_cookie_name ] ) ) {
|
807 |
+
$cookie = json_decode( stripslashes( $_COOKIE[ $auth_cookie_name ] ) );
|
808 |
}
|
809 |
+
if ( ! isset( $cookie ) or ! is_array( $cookie ) ) {
|
810 |
$cookie = array();
|
811 |
}
|
812 |
return $cookie;
|
813 |
}
|
814 |
}
|
815 |
|
816 |
+
if ( ! function_exists( 'switch_to_user' ) ) {
|
817 |
/**
|
818 |
* Switches the current logged in user to the specified user.
|
819 |
*
|
823 |
* @return bool|WP_User WP_User object on success, false on failure.
|
824 |
*/
|
825 |
function switch_to_user( $user_id, $remember = false, $set_old_user = true ) {
|
826 |
+
if ( ! $user = get_userdata( $user_id ) ) {
|
827 |
return false;
|
828 |
}
|
829 |
|
849 |
}
|
850 |
}
|
851 |
|
852 |
+
if ( ! function_exists( 'switch_off_user' ) ) {
|
853 |
/**
|
854 |
* Switches off the current logged in user. This logs the current user out while retaining a cookie allowing them to log
|
855 |
* straight back in using the 'Switch back to {user}' system.
|
857 |
* @return bool True on success, false on failure.
|
858 |
*/
|
859 |
function switch_off_user() {
|
860 |
+
if ( ! $old_user_id = get_current_user_id() ) {
|
861 |
return false;
|
862 |
}
|
863 |
|
870 |
}
|
871 |
}
|
872 |
|
873 |
+
if ( ! function_exists( 'current_user_switched' ) ) {
|
874 |
/**
|
875 |
* Helper function. Did the current user switch into their account?
|
876 |
*
|
878 |
* true) if the user switched into the current user account.
|
879 |
*/
|
880 |
function current_user_switched() {
|
881 |
+
if ( ! is_user_logged_in() ) {
|
882 |
return false;
|
883 |
}
|
884 |
|