Version Description
- Azerbaijani, Danish, and Bosnian translations.
- Add back the 'User Switching' heading on the user profile screen, and correct the values passed to the
switch_back_user
hook when a user has been switched off.
=
Download this release
Release Info
Developer | johnbillion |
Plugin | User Switching |
Version | 1.0.7 |
Comparing to | |
See all releases |
Code changes from version 1.0.6 to 1.0.7
- languages/user-switching-az.mo +0 -0
- languages/user-switching-az.po +67 -0
- languages/user-switching-bs_BA.mo +0 -0
- languages/user-switching-bs_BA.po +67 -0
- languages/user-switching-da_DK.mo +0 -0
- languages/user-switching-da_DK.po +67 -0
- readme.txt +144 -123
- user-switching.php +87 -17
languages/user-switching-az.mo
ADDED
Binary file
|
languages/user-switching-az.po
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Translation of Development (trunk) in Azerbaijani
|
2 |
+
# This file is distributed under the same license as the Development (trunk) package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"PO-Revision-Date: 2015-02-07 02:30:39+0000\n"
|
6 |
+
"MIME-Version: 1.0\n"
|
7 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
8 |
+
"Content-Transfer-Encoding: 8bit\n"
|
9 |
+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
|
10 |
+
"X-Generator: GlotPress/1.0-alpha-1100\n"
|
11 |
+
"Project-Id-Version: Development (trunk)\n"
|
12 |
+
|
13 |
+
#. Author URI of the plugin/theme
|
14 |
+
msgid "https://johnblackbourn.com/"
|
15 |
+
msgstr "https://johnblackbourn.com/"
|
16 |
+
|
17 |
+
#. Author of the plugin/theme
|
18 |
+
msgid "John Blackbourn"
|
19 |
+
msgstr "John Blackbourn"
|
20 |
+
|
21 |
+
#. Description of the plugin/theme
|
22 |
+
msgid "Instant switching between user accounts in WordPress"
|
23 |
+
msgstr "WordPress istifadəçi hesabları arasında ani keçid"
|
24 |
+
|
25 |
+
#. Plugin Name of the plugin/theme
|
26 |
+
msgid "User Switching"
|
27 |
+
msgstr "İstifadəçi Keçidi"
|
28 |
+
|
29 |
+
#. Plugin URI of the plugin/theme
|
30 |
+
msgid "https://johnblackbourn.com/wordpress-plugin-user-switching/"
|
31 |
+
msgstr "https://johnblackbourn.com/wordpress-plugin-user-switching/"
|
32 |
+
|
33 |
+
#: user-switching.php:417
|
34 |
+
msgid "Switch Off"
|
35 |
+
msgstr "Keçid Bağlıdır"
|
36 |
+
|
37 |
+
#: user-switching.php:322
|
38 |
+
msgid "Switched back to %1$s (%2$s)."
|
39 |
+
msgstr "%1$s (%2$s) olaraq geri keçid edildi."
|
40 |
+
|
41 |
+
#: user-switching.php:311 user-switching.php:397 user-switching.php:431
|
42 |
+
#: user-switching.php:446 user-switching.php:464
|
43 |
+
msgid "Switch back to %1$s (%2$s)"
|
44 |
+
msgstr "%1$s (%2$s) olaraq geri keçid et."
|
45 |
+
|
46 |
+
#: user-switching.php:306 user-switching.php:324
|
47 |
+
msgid "Switched to %1$s (%2$s)."
|
48 |
+
msgstr "%1$s (%2$s) olaraq keçid edildi."
|
49 |
+
|
50 |
+
#: user-switching.php:219 user-switching.php:236
|
51 |
+
msgid "Could not switch off."
|
52 |
+
msgstr "Bağlamaq baş tutmadı."
|
53 |
+
|
54 |
+
#: user-switching.php:95 user-switching.php:491 user-switching.php:533
|
55 |
+
#: user-switching.php:557
|
56 |
+
msgid "Switch To"
|
57 |
+
msgstr " Keçid"
|
58 |
+
|
59 |
+
#: user-switching.php:154 user-switching.php:178 user-switching.php:187
|
60 |
+
#: user-switching.php:192 user-switching.php:210
|
61 |
+
msgid "Could not switch users."
|
62 |
+
msgstr "İstifadəçilər arasında geçid baş tutmadı."
|
63 |
+
|
64 |
+
#: user-switching.php:94
|
65 |
+
msgctxt "User Switching title on user profile screen"
|
66 |
+
msgid "User Switching"
|
67 |
+
msgstr "İstifadəçi Keçidi"
|
languages/user-switching-bs_BA.mo
ADDED
Binary file
|
languages/user-switching-bs_BA.po
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Translation of Development (trunk) in Bosnian
|
2 |
+
# This file is distributed under the same license as the Development (trunk) package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"PO-Revision-Date: 2015-03-28 14:20:48+0000\n"
|
6 |
+
"MIME-Version: 1.0\n"
|
7 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
8 |
+
"Content-Transfer-Encoding: 8bit\n"
|
9 |
+
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
|
10 |
+
"X-Generator: GlotPress/1.0-alpha-1100\n"
|
11 |
+
"Project-Id-Version: Development (trunk)\n"
|
12 |
+
|
13 |
+
#. Author URI of the plugin/theme
|
14 |
+
msgid "https://johnblackbourn.com/"
|
15 |
+
msgstr "https://johnblackbourn.com/"
|
16 |
+
|
17 |
+
#. Author of the plugin/theme
|
18 |
+
msgid "John Blackbourn"
|
19 |
+
msgstr "John Blackbourn"
|
20 |
+
|
21 |
+
#. Description of the plugin/theme
|
22 |
+
msgid "Instant switching between user accounts in WordPress"
|
23 |
+
msgstr "Trenutno prebacivanje između korisničkih računa u WordPressu"
|
24 |
+
|
25 |
+
#. Plugin Name of the plugin/theme
|
26 |
+
msgid "User Switching"
|
27 |
+
msgstr "Prebacivanje korisnika"
|
28 |
+
|
29 |
+
#. Plugin URI of the plugin/theme
|
30 |
+
msgid "https://johnblackbourn.com/wordpress-plugin-user-switching/"
|
31 |
+
msgstr "https://johnblackbourn.com/wordpress-plugin-user-switching/"
|
32 |
+
|
33 |
+
#: user-switching.php:417
|
34 |
+
msgid "Switch Off"
|
35 |
+
msgstr "Isključi"
|
36 |
+
|
37 |
+
#: user-switching.php:322
|
38 |
+
msgid "Switched back to %1$s (%2$s)."
|
39 |
+
msgstr "Prebačeno nazad na %1$s (%2$s)."
|
40 |
+
|
41 |
+
#: user-switching.php:311 user-switching.php:397 user-switching.php:431
|
42 |
+
#: user-switching.php:446 user-switching.php:464
|
43 |
+
msgid "Switch back to %1$s (%2$s)"
|
44 |
+
msgstr "Prebaci nazad na %1$s (%2$s)"
|
45 |
+
|
46 |
+
#: user-switching.php:306 user-switching.php:324
|
47 |
+
msgid "Switched to %1$s (%2$s)."
|
48 |
+
msgstr "Prebačeno na %1$s (%2$s)."
|
49 |
+
|
50 |
+
#: user-switching.php:219 user-switching.php:236
|
51 |
+
msgid "Could not switch off."
|
52 |
+
msgstr "Nije moguće isključiti."
|
53 |
+
|
54 |
+
#: user-switching.php:95 user-switching.php:491 user-switching.php:533
|
55 |
+
#: user-switching.php:557
|
56 |
+
msgid "Switch To"
|
57 |
+
msgstr "Prebaci na"
|
58 |
+
|
59 |
+
#: user-switching.php:154 user-switching.php:178 user-switching.php:187
|
60 |
+
#: user-switching.php:192 user-switching.php:210
|
61 |
+
msgid "Could not switch users."
|
62 |
+
msgstr "Nije moguće prebaciti korisnike."
|
63 |
+
|
64 |
+
#: user-switching.php:94
|
65 |
+
msgctxt "User Switching title on user profile screen"
|
66 |
+
msgid "User Switching"
|
67 |
+
msgstr "Prebacivanje korisnika"
|
languages/user-switching-da_DK.mo
ADDED
Binary file
|
languages/user-switching-da_DK.po
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Translation of Development (trunk) in Danish
|
2 |
+
# This file is distributed under the same license as the Development (trunk) package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"PO-Revision-Date: 2015-03-03 23:13:11+0000\n"
|
6 |
+
"MIME-Version: 1.0\n"
|
7 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
8 |
+
"Content-Transfer-Encoding: 8bit\n"
|
9 |
+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
|
10 |
+
"X-Generator: GlotPress/1.0-alpha-1100\n"
|
11 |
+
"Project-Id-Version: Development (trunk)\n"
|
12 |
+
|
13 |
+
#. Author URI of the plugin/theme
|
14 |
+
msgid "https://johnblackbourn.com/"
|
15 |
+
msgstr "https://johnblackbourn.com/"
|
16 |
+
|
17 |
+
#. Author of the plugin/theme
|
18 |
+
msgid "John Blackbourn"
|
19 |
+
msgstr "John Blackbourn"
|
20 |
+
|
21 |
+
#. Description of the plugin/theme
|
22 |
+
msgid "Instant switching between user accounts in WordPress"
|
23 |
+
msgstr "Skift hurtigt mellem brugerkonti i WordPress"
|
24 |
+
|
25 |
+
#. Plugin Name of the plugin/theme
|
26 |
+
msgid "User Switching"
|
27 |
+
msgstr "Brugerskift"
|
28 |
+
|
29 |
+
#. Plugin URI of the plugin/theme
|
30 |
+
msgid "https://johnblackbourn.com/wordpress-plugin-user-switching/"
|
31 |
+
msgstr "https://johnblackbourn.com/wordpress-plugin-user-switching/"
|
32 |
+
|
33 |
+
#: user-switching.php:417
|
34 |
+
msgid "Switch Off"
|
35 |
+
msgstr "Skift til egen bruger"
|
36 |
+
|
37 |
+
#: user-switching.php:322
|
38 |
+
msgid "Switched back to %1$s (%2$s)."
|
39 |
+
msgstr "Skiftede tilbage til %1$s (%2$s)."
|
40 |
+
|
41 |
+
#: user-switching.php:311 user-switching.php:397 user-switching.php:431
|
42 |
+
#: user-switching.php:446 user-switching.php:464
|
43 |
+
msgid "Switch back to %1$s (%2$s)"
|
44 |
+
msgstr "Skift tilbage til %1$s (%2$s)"
|
45 |
+
|
46 |
+
#: user-switching.php:306 user-switching.php:324
|
47 |
+
msgid "Switched to %1$s (%2$s)."
|
48 |
+
msgstr "Skiftede til %1$s (%2$s)."
|
49 |
+
|
50 |
+
#: user-switching.php:219 user-switching.php:236
|
51 |
+
msgid "Could not switch off."
|
52 |
+
msgstr "Kunne ikke skifte til egen bruger."
|
53 |
+
|
54 |
+
#: user-switching.php:95 user-switching.php:491 user-switching.php:533
|
55 |
+
#: user-switching.php:557
|
56 |
+
msgid "Switch To"
|
57 |
+
msgstr "Skift til"
|
58 |
+
|
59 |
+
#: user-switching.php:154 user-switching.php:178 user-switching.php:187
|
60 |
+
#: user-switching.php:192 user-switching.php:210
|
61 |
+
msgid "Could not switch users."
|
62 |
+
msgstr "Kunne ikke skifte bruger."
|
63 |
+
|
64 |
+
#: user-switching.php:94
|
65 |
+
msgctxt "User Switching title on user profile screen"
|
66 |
+
msgid "User Switching"
|
67 |
+
msgstr "Brugerskift"
|
readme.txt
CHANGED
@@ -1,132 +1,153 @@
|
|
1 |
-
=== User Switching ===
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
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.3
|
7 |
-
Stable tag: 1.0.6
|
8 |
-
License: GPL v2 or later
|
9 |
-
|
10 |
-
Instant switching between user accounts in WordPress.
|
11 |
-
|
12 |
-
== Description ==
|
13 |
-
|
14 |
-
This plugin allows you to quickly swap between user accounts in WordPress at the click of a button. You'll be instantly logged out and logged in as your desired user. This is handy for test environments where you regularly log out and in between different accounts, or for administrators who need to switch between multiple accounts.
|
15 |
-
|
16 |
-
= Features =
|
17 |
-
|
18 |
-
* Switch user: Instantly switch to any user account from the *Users* screen.
|
19 |
-
* Switch back: Instantly switch back to your originating account.
|
20 |
-
* Switch off: Log out of your account but retain the ability to instantly switch back in again.
|
21 |
-
* It's completely secure (see the *Security* section below).
|
22 |
-
* Compatible with WordPress, WordPress Multisite, BuddyPress and bbPress.
|
23 |
-
|
24 |
-
= Security =
|
25 |
-
|
26 |
-
* Only users with the ability to edit other users can switch user accounts. By default this is only Administrators on single site installs, and Super Admins on Multisite installs.
|
27 |
-
* Passwords are not (and cannot be) revealed.
|
28 |
-
* Uses the cookie authentication system in WordPress when remembering the account(s) you've switched from and when switching back.
|
29 |
-
* Implements the nonce security system in WordPress, meaning only those who intend to switch users can switch.
|
30 |
-
* Full support for administration over SSL (if applicable).
|
31 |
-
|
32 |
-
= Usage =
|
33 |
-
|
34 |
-
1. Visit the *Users* menu in WordPress and you'll see a *Switch To* link next to each user.
|
35 |
-
2. Click this and you will immediately switch into that user account.
|
36 |
-
3. You can switch back to your originating account via the *Switch back* link on each dashboard screen or in your profile menu in the WordPress toolbar.
|
37 |
-
|
38 |
-
See the [FAQ](https://wordpress.org/plugins/user-switching/faq/) for information about the *Switch Off* feature.
|
39 |
-
|
40 |
-
= Translations Included =
|
41 |
-
|
42 |
-
* العربية (Arabic)
|
43 |
-
* Български (Bulgarian)
|
44 |
-
* 中文 (Chinese Simplified)
|
45 |
-
* Hrvatski (Croatian)
|
46 |
-
* Nederlands (Dutch)
|
47 |
-
* Suomi (Finnish)
|
48 |
-
* Français (French)
|
49 |
-
* Deutsch (German)
|
50 |
-
* Ελληνικά (Greek)
|
51 |
-
* עִבְרִית (Hebrew)
|
52 |
-
* Bahasa Indonesia (Indonesian)
|
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)
|
60 |
-
* Română (Romanian)
|
61 |
-
* Русский (Russian)
|
62 |
-
* Slovenčina (Slovak)
|
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 |
-
|
70 |
-
1. ![The *Switch To* link on the Users screen](https://raw.github.com/johnbillion/user-switching/master/assets-wp-repo/screenshot-1.png)
|
71 |
-
2. ![The *Switch To* link on a user's profile](https://raw.github.com/johnbillion/user-switching/master/assets-wp-repo/screenshot-2.png)
|
72 |
-
|
73 |
-
== Installation ==
|
74 |
-
|
75 |
-
If you have the [WordPress Developer plugin](https://wordpress.org/plugins/developer/) installed then User Switching is a one-click install from the Tools -> Developer screen.
|
76 |
-
|
77 |
-
Alternatively, you can install this plugin directly from your WordPress dashboard:
|
78 |
-
|
79 |
-
1. Go to the *Plugins* menu and click *Add New*.
|
80 |
-
2. Search for *User Switching*.
|
81 |
-
3. Click *Install Now* next to the *User Switching* plugin.
|
82 |
-
4. Activate the plugin.
|
83 |
-
|
84 |
-
== Frequently Asked Questions ==
|
85 |
-
|
86 |
-
= What does "Switch off" mean? =
|
87 |
-
|
88 |
-
Switching off logs you out of your account but retains your user ID in an authentication cookie so you can switch straight back without having to log in again manually. It's akin to switching to no user, and being able to switch back.
|
89 |
-
|
90 |
-
The *Switch Off* link can be found in your profile menu in the WordPress toolbar. Once you've switched off you'll see a *Switch back* link in the footer of your site.
|
91 |
-
|
92 |
-
= Does this plugin work with WordPress Multisite? =
|
93 |
-
|
94 |
-
Yes, and you'll also be able to switch users from the Users screen in Network Admin.
|
95 |
-
|
96 |
-
= Does this plugin work with BuddyPress? =
|
97 |
-
|
98 |
-
Yes, and you'll also be able to switch users from member profile screens and the member listing screen.
|
99 |
-
|
100 |
-
= Does this plugin work with bbPress? =
|
101 |
-
|
102 |
-
Yes, and you'll also be able to switch users from member profile screens.
|
103 |
-
|
104 |
-
= Does this work as a mu-plugin? =
|
105 |
-
|
106 |
-
Yes, but you'll need to install `user-switching.php` into the root of your `mu-plugins` directory, not in the `user-switching` subdirectory. This is a restriction of WordPress.
|
107 |
-
|
108 |
-
= What capability does a user need in order to switch accounts? =
|
109 |
-
|
110 |
-
A user needs the `edit_users` capability in order to switch user accounts. By default only Administrators have this capability, and with Multisite enabled only Super Admins have this capability.
|
111 |
-
|
112 |
-
= Can regular admins on Multisite installs switch accounts? =
|
113 |
-
|
114 |
-
No. This can be enabled though by installing the [User Switching for Regular Admins](https://github.com/johnbillion/user-switching-for-regular-admins) plugin.
|
115 |
-
|
116 |
-
= Are any plugin hooks called when users switch accounts? =
|
117 |
-
|
118 |
-
Yes. When a user switches to another account, the `switch_to_user` hook is called with the new and old user IDs passed as parameters.
|
119 |
|
120 |
-
|
121 |
|
122 |
-
|
|
|
123 |
|
124 |
-
==
|
125 |
|
126 |
-
= 1.0.
|
127 |
-
* Correct the values passed to the `switch_back_user` action when a user switches back.
|
128 |
|
129 |
-
|
|
|
|
|
|
|
|
|
130 |
|
131 |
= 1.0.6 =
|
132 |
* Correct the values passed to the `switch_back_user` action when a user switches back.
|
1 |
+
=== User Switching ===
|
2 |
+
|
3 |
+
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.3
|
7 |
+
Stable tag: 1.0.7
|
8 |
+
License: GPL v2 or later
|
9 |
+
|
10 |
+
Instant switching between user accounts in WordPress.
|
11 |
+
|
12 |
+
== Description ==
|
13 |
+
|
14 |
+
This plugin allows you to quickly swap between user accounts in WordPress at the click of a button. You'll be instantly logged out and logged in as your desired user. This is handy for test environments where you regularly log out and in between different accounts, or for administrators who need to switch between multiple accounts.
|
15 |
+
|
16 |
+
= Features =
|
17 |
+
|
18 |
+
* Switch user: Instantly switch to any user account from the *Users* screen.
|
19 |
+
* Switch back: Instantly switch back to your originating account.
|
20 |
+
* Switch off: Log out of your account but retain the ability to instantly switch back in again.
|
21 |
+
* It's completely secure (see the *Security* section below).
|
22 |
+
* Compatible with WordPress, WordPress Multisite, BuddyPress and bbPress.
|
23 |
+
|
24 |
+
= Security =
|
25 |
+
|
26 |
+
* Only users with the ability to edit other users can switch user accounts. By default this is only Administrators on single site installs, and Super Admins on Multisite installs.
|
27 |
+
* Passwords are not (and cannot be) revealed.
|
28 |
+
* Uses the cookie authentication system in WordPress when remembering the account(s) you've switched from and when switching back.
|
29 |
+
* Implements the nonce security system in WordPress, meaning only those who intend to switch users can switch.
|
30 |
+
* Full support for administration over SSL (if applicable).
|
31 |
+
|
32 |
+
= Usage =
|
33 |
+
|
34 |
+
1. Visit the *Users* menu in WordPress and you'll see a *Switch To* link in the list of action links for each user.
|
35 |
+
2. Click this and you will immediately switch into that user account.
|
36 |
+
3. You can switch back to your originating account via the *Switch back* link on each dashboard screen or in your profile menu in the WordPress toolbar.
|
37 |
+
|
38 |
+
See the [FAQ](https://wordpress.org/plugins/user-switching/faq/) for information about the *Switch Off* feature.
|
39 |
+
|
40 |
+
= Translations Included =
|
41 |
+
|
42 |
+
* العربية (Arabic)
|
43 |
+
* Azərbaycan dili (Azerbaijani)
|
44 |
+
* Bosanski (Bosnian)
|
45 |
+
* Български (Bulgarian)
|
46 |
+
* 中文 (Chinese Simplified)
|
47 |
+
* Hrvatski (Croatian)
|
48 |
+
* Dansk (Danish)
|
49 |
+
* Nederlands (Dutch)
|
50 |
+
* Suomi (Finnish)
|
51 |
+
* Français (French)
|
52 |
+
* Deutsch (German)
|
53 |
+
* Ελληνικά (Greek)
|
54 |
+
* עִבְרִית (Hebrew)
|
55 |
+
* Bahasa Indonesia (Indonesian)
|
56 |
+
* Italiano (Italian)
|
57 |
+
* 日本語 (Japanese)
|
58 |
+
* Lietuvių kalba (Lithuanian)
|
59 |
+
* Norsk bokmål (Norwegian)
|
60 |
+
* فارسی (Persian)
|
61 |
+
* Polski (Polish)
|
62 |
+
* Português do Brasil (Brazilian Portuguese)
|
63 |
+
* Română (Romanian)
|
64 |
+
* Русский (Russian)
|
65 |
+
* Slovenčina (Slovak)
|
66 |
+
* Español (Spanish)
|
67 |
+
* Türkçe (Turkish)
|
68 |
+
|
69 |
+
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, Per Søderlind, Mushviq Abdulla, Kenan Dervisevic, and Joachim Jensen!
|
70 |
+
|
71 |
+
== Screenshots ==
|
72 |
+
|
73 |
+
1. ![The *Switch To* link on the Users screen](https://raw.github.com/johnbillion/user-switching/master/assets-wp-repo/screenshot-1.png)
|
74 |
+
2. ![The *Switch To* link on a user's profile](https://raw.github.com/johnbillion/user-switching/master/assets-wp-repo/screenshot-2.png)
|
75 |
+
|
76 |
+
== Installation ==
|
77 |
+
|
78 |
+
If you have the [WordPress Developer plugin](https://wordpress.org/plugins/developer/) installed then User Switching is a one-click install from the Tools -> Developer screen.
|
79 |
+
|
80 |
+
Alternatively, you can install this plugin directly from your WordPress dashboard:
|
81 |
+
|
82 |
+
1. Go to the *Plugins* menu and click *Add New*.
|
83 |
+
2. Search for *User Switching*.
|
84 |
+
3. Click *Install Now* next to the *User Switching* plugin.
|
85 |
+
4. Activate the plugin.
|
86 |
+
|
87 |
+
== Frequently Asked Questions ==
|
88 |
+
|
89 |
+
= What does "Switch off" mean? =
|
90 |
+
|
91 |
+
Switching off logs you out of your account but retains your user ID in an authentication cookie so you can switch straight back without having to log in again manually. It's akin to switching to no user, and being able to switch back.
|
92 |
+
|
93 |
+
The *Switch Off* link can be found in your profile menu in the WordPress toolbar. Once you've switched off you'll see a *Switch back* link in the footer of your site.
|
94 |
+
|
95 |
+
= Does this plugin work with WordPress Multisite? =
|
96 |
+
|
97 |
+
Yes, and you'll also be able to switch users from the Users screen in Network Admin.
|
98 |
+
|
99 |
+
= Does this plugin work with BuddyPress? =
|
100 |
+
|
101 |
+
Yes, and you'll also be able to switch users from member profile screens and the member listing screen.
|
102 |
+
|
103 |
+
= Does this plugin work with bbPress? =
|
104 |
+
|
105 |
+
Yes, and you'll also be able to switch users from member profile screens.
|
106 |
+
|
107 |
+
= Does this plugin work if my site is using a two-factor authentication plugin? =
|
108 |
+
|
109 |
+
Yes, mostly.
|
110 |
+
|
111 |
+
One exception I'm aware of is [Duo Security](https://wordpress.org/plugins/duo-wordpress/). If you're using this plugin, you should install the [User Switching for Duo Security](https://github.com/johnbillion/user-switching-duo-security) add-on plugin which will prevent the two-factor authentication prompt from appearing when you switch between users.
|
112 |
+
|
113 |
+
= Does this work as a mu-plugin? =
|
114 |
+
|
115 |
+
Yes, but you'll need to install `user-switching.php` into the root of your `mu-plugins` directory, not in the `user-switching` subdirectory. This is a limitation of WordPress.
|
116 |
+
|
117 |
+
= What capability does a user need in order to switch accounts? =
|
118 |
+
|
119 |
+
A user needs the `edit_users` capability in order to switch user accounts. By default only Administrators have this capability, and with Multisite enabled only Super Admins have this capability.
|
120 |
+
|
121 |
+
= Can regular admins on Multisite installs switch accounts? =
|
122 |
+
|
123 |
+
No. This can be enabled though by installing the [User Switching for Regular Admins](https://github.com/johnbillion/user-switching-for-regular-admins) plugin.
|
124 |
+
|
125 |
+
= Are any plugin actions called when a user switches account? =
|
126 |
+
|
127 |
+
Yes. When a user switches to another account, the `switch_to_user` hook is called with the new and old user IDs passed as parameters.
|
128 |
+
|
129 |
+
When a user switches back to their original account, the `switch_back_user` hook is called with the new (original) and old user IDs passed as parameters. Note that the old user ID can be boolean false if the user is switching back after they've been switched off.
|
130 |
+
|
131 |
+
When a user switches off, the `switch_off_user` hook is called with the old user ID as a parameter.
|
132 |
+
|
133 |
+
See the plugin source code for complete hook documentation.
|
134 |
|
135 |
+
== Upgrade Notice ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
+
= 1.0.7 =
|
138 |
|
139 |
+
* Azerbaijani, Danish, and Bosnian translations.
|
140 |
+
* Add back the 'User Switching' heading on the user profile screen, and correct the values passed to the `switch_back_user` hook when a user has been switched off.
|
141 |
|
142 |
+
== Changelog ==
|
143 |
|
144 |
+
= 1.0.7 =
|
|
|
145 |
|
146 |
+
* Azerbaijani, Danish, and Bosnian translations.
|
147 |
+
* Add back the 'User Switching' heading on the user profile screen.
|
148 |
+
* Correct the value passed to the `$old_user_id` parameter of the `switch_back_user` hook when a user has been switched off. This should be boolean `false` rather than `0`.
|
149 |
+
* Docblocks for actions and filters.
|
150 |
+
* More code standards tweaks.
|
151 |
|
152 |
= 1.0.6 =
|
153 |
* Correct the values passed to the `switch_back_user` action when a user switches back.
|
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/
|
@@ -91,7 +91,7 @@ class user_switching {
|
|
91 |
|
92 |
?>
|
93 |
<tr>
|
94 |
-
<th scope="row"><?php esc_html_x( 'User Switching', 'User Switching title on user profile screen', 'user-switching' ); ?></th>
|
95 |
<td><a href="<?php echo esc_url( $link ); ?>"><?php esc_html_e( 'Switch To', 'user-switching' ); ?></a></td>
|
96 |
</tr>
|
97 |
<?php
|
@@ -106,8 +106,19 @@ class user_switching {
|
|
106 |
*/
|
107 |
public static function remember() {
|
108 |
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
$cookie_life = apply_filters( 'auth_cookie_expiration', 172800, get_current_user_id(), false );
|
|
|
111 |
|
112 |
# Here we calculate the expiration length of the current auth cookie and compare it to the default expiration.
|
113 |
# If it's greater than this, then we know the user checked 'Remember Me' when they logged in.
|
@@ -132,7 +143,11 @@ class user_switching {
|
|
132 |
|
133 |
# We're attempting to switch to another user:
|
134 |
case 'switch_to_user':
|
135 |
-
|
|
|
|
|
|
|
|
|
136 |
|
137 |
# Check authentication:
|
138 |
if ( ! current_user_can( 'switch_to_user', $user_id ) ) {
|
@@ -229,13 +244,13 @@ class user_switching {
|
|
229 |
/**
|
230 |
* Fetch the URL to redirect to for a given user (used after switching).
|
231 |
*
|
232 |
-
* @param WP_User $new_user The new user's WP_User object
|
233 |
-
* @param WP_User $old_user The old user's WP_User object
|
234 |
* @return string The URL to redirect to.
|
235 |
*/
|
236 |
protected static function get_redirect( WP_User $new_user = null, WP_User $old_user = null ) {
|
237 |
|
238 |
-
if (
|
239 |
$redirect_to = self::remove_query_args( $_REQUEST['redirect_to'] );
|
240 |
$requested_redirect_to = $_REQUEST['redirect_to'];
|
241 |
} else {
|
@@ -244,8 +259,30 @@ class user_switching {
|
|
244 |
}
|
245 |
|
246 |
if ( ! $new_user ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
$redirect_to = apply_filters( 'logout_redirect', $redirect_to, $requested_redirect_to, $old_user );
|
248 |
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
$redirect_to = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $new_user );
|
250 |
}
|
251 |
|
@@ -360,7 +397,7 @@ class user_switching {
|
|
360 |
'title' => esc_html( sprintf( __( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login ) ),
|
361 |
'href' => add_query_arg( array(
|
362 |
'redirect_to' => urlencode( self::current_url() ),
|
363 |
-
), self::switch_back_url( $old_user ) )
|
364 |
) );
|
365 |
|
366 |
}
|
@@ -393,7 +430,7 @@ class user_switching {
|
|
393 |
if ( ! is_admin_bar_showing() && $old_user = self::get_old_user() ) {
|
394 |
$link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login );
|
395 |
$url = add_query_arg( array(
|
396 |
-
'redirect_to' => urlencode( self::current_url() )
|
397 |
), self::switch_back_url( $old_user ) );
|
398 |
echo '<li id="user_switching_switch_on"><a href="' . esc_url( $url ) . '">' . esc_html( $link ) . '</a></li>';
|
399 |
}
|
@@ -408,7 +445,7 @@ class user_switching {
|
|
408 |
if ( ! did_action( 'wp_meta' ) && ! is_admin_bar_showing() && $old_user = self::get_old_user() ) {
|
409 |
$link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login );
|
410 |
$url = add_query_arg( array(
|
411 |
-
'redirect_to' => urlencode( self::current_url() )
|
412 |
), self::switch_back_url( $old_user ) );
|
413 |
echo '<p id="user_switching_switch_on"><a href="' . esc_url( $url ) . '">' . esc_html( $link ) . '</a></p>';
|
414 |
}
|
@@ -426,9 +463,9 @@ class user_switching {
|
|
426 |
if ( $old_user = self::get_old_user() ) {
|
427 |
$link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login );
|
428 |
$url = self::switch_back_url( $old_user );
|
429 |
-
if (
|
430 |
$url = add_query_arg( array(
|
431 |
-
'redirect_to' => urlencode( $_REQUEST['redirect_to'] )
|
432 |
), $url );
|
433 |
}
|
434 |
$message .= '<p class="message"><span class="dashicons dashicons-admin-users" style="color:#56c234"></span> <a href="' . esc_url( $url ) . '">' . esc_html( $link ) . '</a></p>';
|
@@ -610,6 +647,15 @@ class user_switching {
|
|
610 |
* @return string The URL with the listed query args removed.
|
611 |
*/
|
612 |
public static function remove_query_args( $url ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
613 |
$args = apply_filters( 'removable_query_args', array(
|
614 |
'message', 'update', 'updated', 'settings-updated', 'saved',
|
615 |
'activated', 'activate', 'deactivate', 'enabled', 'disabled',
|
@@ -710,7 +756,7 @@ if ( ! function_exists( 'user_switching_set_olduser_cookie' ) ) {
|
|
710 |
* Sets authorisation cookies containing the originating user information.
|
711 |
*
|
712 |
* @param int $old_user_id The ID of the originating user, usually the current logged in user.
|
713 |
-
* @param bool $pop Pop the latest user off the auth cookie, instead of appending the new one. Default false.
|
714 |
*/
|
715 |
function user_switching_set_olduser_cookie( $old_user_id, $pop = false ) {
|
716 |
$secure_auth_cookie = user_switching::secure_auth_cookie();
|
@@ -742,7 +788,7 @@ if ( ! function_exists( 'user_switching_clear_olduser_cookie' ) ) {
|
|
742 |
/**
|
743 |
* Clears the cookies containing the originating user, or pops the latest item off the end if there's more than one.
|
744 |
*
|
745 |
-
* @param bool $clear_all Whether to clear the cookies
|
746 |
*/
|
747 |
function user_switching_clear_olduser_cookie( $clear_all = true ) {
|
748 |
$auth_cookie = user_switching_get_auth_cookie();
|
@@ -812,8 +858,8 @@ if ( ! function_exists( 'switch_to_user' ) ) {
|
|
812 |
* Switches the current logged in user to the specified user.
|
813 |
*
|
814 |
* @param int $user_id The ID of the user to switch to.
|
815 |
-
* @param bool $remember Whether to 'remember' the user in the form of a persistent browser cookie.
|
816 |
-
* @param bool $set_old_user Whether to set the old user cookie.
|
817 |
* @return bool|WP_User WP_User object on success, false on failure.
|
818 |
*/
|
819 |
function switch_to_user( $user_id, $remember = false, $set_old_user = true ) {
|
@@ -821,7 +867,7 @@ function switch_to_user( $user_id, $remember = false, $set_old_user = true ) {
|
|
821 |
return false;
|
822 |
}
|
823 |
|
824 |
-
$old_user_id = get_current_user_id();
|
825 |
|
826 |
if ( $set_old_user && $old_user_id ) {
|
827 |
user_switching_set_olduser_cookie( $old_user_id );
|
@@ -834,8 +880,25 @@ function switch_to_user( $user_id, $remember = false, $set_old_user = true ) {
|
|
834 |
wp_set_current_user( $user_id );
|
835 |
|
836 |
if ( $set_old_user ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
837 |
do_action( 'switch_to_user', $user_id, $old_user_id );
|
838 |
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
839 |
do_action( 'switch_back_user', $user_id, $old_user_id );
|
840 |
}
|
841 |
|
@@ -859,6 +922,13 @@ function switch_off_user() {
|
|
859 |
wp_clear_auth_cookie();
|
860 |
wp_set_current_user( 0 );
|
861 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
862 |
do_action( 'switch_off_user', $old_user_id );
|
863 |
|
864 |
return true;
|
2 |
/*
|
3 |
Plugin Name: User Switching
|
4 |
Description: Instant switching between user accounts in WordPress
|
5 |
+
Version: 1.0.7
|
6 |
Plugin URI: https://johnblackbourn.com/wordpress-plugin-user-switching/
|
7 |
Author: John Blackbourn
|
8 |
Author URI: https://johnblackbourn.com/
|
91 |
|
92 |
?>
|
93 |
<tr>
|
94 |
+
<th scope="row"><?php echo esc_html_x( 'User Switching', 'User Switching title on user profile screen', 'user-switching' ); ?></th>
|
95 |
<td><a href="<?php echo esc_url( $link ); ?>"><?php esc_html_e( 'Switch To', 'user-switching' ); ?></a></td>
|
96 |
</tr>
|
97 |
<?php
|
106 |
*/
|
107 |
public static function remember() {
|
108 |
|
109 |
+
/**
|
110 |
+
* Filter the duration of the authentication cookie expiration period.
|
111 |
+
*
|
112 |
+
* This matches the WordPress core filter in `wp_set_auth_cookie()`.
|
113 |
+
*
|
114 |
+
* @since 0.2.2
|
115 |
+
*
|
116 |
+
* @param int $length Duration of the expiration period in seconds.
|
117 |
+
* @param int $user_id User ID.
|
118 |
+
* @param bool $remember Whether to remember the user login. Default false.
|
119 |
+
*/
|
120 |
$cookie_life = apply_filters( 'auth_cookie_expiration', 172800, get_current_user_id(), false );
|
121 |
+
$current = wp_parse_auth_cookie( '', 'logged_in' );
|
122 |
|
123 |
# Here we calculate the expiration length of the current auth cookie and compare it to the default expiration.
|
124 |
# If it's greater than this, then we know the user checked 'Remember Me' when they logged in.
|
143 |
|
144 |
# We're attempting to switch to another user:
|
145 |
case 'switch_to_user':
|
146 |
+
if ( isset( $_REQUEST['user_id'] ) ) {
|
147 |
+
$user_id = absint( $_REQUEST['user_id'] );
|
148 |
+
} else {
|
149 |
+
$user_id = 0;
|
150 |
+
}
|
151 |
|
152 |
# Check authentication:
|
153 |
if ( ! current_user_can( 'switch_to_user', $user_id ) ) {
|
244 |
/**
|
245 |
* Fetch the URL to redirect to for a given user (used after switching).
|
246 |
*
|
247 |
+
* @param WP_User $new_user Optional. The new user's WP_User object.
|
248 |
+
* @param WP_User $old_user Optional. The old user's WP_User object.
|
249 |
* @return string The URL to redirect to.
|
250 |
*/
|
251 |
protected static function get_redirect( WP_User $new_user = null, WP_User $old_user = null ) {
|
252 |
|
253 |
+
if ( ! empty( $_REQUEST['redirect_to'] ) ) {
|
254 |
$redirect_to = self::remove_query_args( $_REQUEST['redirect_to'] );
|
255 |
$requested_redirect_to = $_REQUEST['redirect_to'];
|
256 |
} else {
|
259 |
}
|
260 |
|
261 |
if ( ! $new_user ) {
|
262 |
+
/**
|
263 |
+
* Filter the redirect URL when a user switches off.
|
264 |
+
*
|
265 |
+
* This matches the WordPress core filter in wp-login.php.
|
266 |
+
*
|
267 |
+
* @since 1.0.4
|
268 |
+
*
|
269 |
+
* @param string $redirect_to The redirect destination URL.
|
270 |
+
* @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
|
271 |
+
* @param WP_User $old_user The WP_User object for the user that's switching off.
|
272 |
+
*/
|
273 |
$redirect_to = apply_filters( 'logout_redirect', $redirect_to, $requested_redirect_to, $old_user );
|
274 |
} else {
|
275 |
+
/**
|
276 |
+
* Filter the redirect URL when a user switches to another user or switches back.
|
277 |
+
*
|
278 |
+
* This matches the WordPress core filter in wp-login.php.
|
279 |
+
*
|
280 |
+
* @since 0.8.7
|
281 |
+
*
|
282 |
+
* @param string $redirect_to The redirect destination URL.
|
283 |
+
* @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
|
284 |
+
* @param WP_User $new_user The WP_User object for the user that's being switched to.
|
285 |
+
*/
|
286 |
$redirect_to = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $new_user );
|
287 |
}
|
288 |
|
397 |
'title' => esc_html( sprintf( __( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login ) ),
|
398 |
'href' => add_query_arg( array(
|
399 |
'redirect_to' => urlencode( self::current_url() ),
|
400 |
+
), self::switch_back_url( $old_user ) ),
|
401 |
) );
|
402 |
|
403 |
}
|
430 |
if ( ! is_admin_bar_showing() && $old_user = self::get_old_user() ) {
|
431 |
$link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login );
|
432 |
$url = add_query_arg( array(
|
433 |
+
'redirect_to' => urlencode( self::current_url() ),
|
434 |
), self::switch_back_url( $old_user ) );
|
435 |
echo '<li id="user_switching_switch_on"><a href="' . esc_url( $url ) . '">' . esc_html( $link ) . '</a></li>';
|
436 |
}
|
445 |
if ( ! did_action( 'wp_meta' ) && ! is_admin_bar_showing() && $old_user = self::get_old_user() ) {
|
446 |
$link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login );
|
447 |
$url = add_query_arg( array(
|
448 |
+
'redirect_to' => urlencode( self::current_url() ),
|
449 |
), self::switch_back_url( $old_user ) );
|
450 |
echo '<p id="user_switching_switch_on"><a href="' . esc_url( $url ) . '">' . esc_html( $link ) . '</a></p>';
|
451 |
}
|
463 |
if ( $old_user = self::get_old_user() ) {
|
464 |
$link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user-switching' ), $old_user->display_name, $old_user->user_login );
|
465 |
$url = self::switch_back_url( $old_user );
|
466 |
+
if ( ! empty( $_REQUEST['redirect_to'] ) ) {
|
467 |
$url = add_query_arg( array(
|
468 |
+
'redirect_to' => urlencode( $_REQUEST['redirect_to'] ),
|
469 |
), $url );
|
470 |
}
|
471 |
$message .= '<p class="message"><span class="dashicons dashicons-admin-users" style="color:#56c234"></span> <a href="' . esc_url( $url ) . '">' . esc_html( $link ) . '</a></p>';
|
647 |
* @return string The URL with the listed query args removed.
|
648 |
*/
|
649 |
public static function remove_query_args( $url ) {
|
650 |
+
/**
|
651 |
+
* Filter the list of URL parameters to remove from the URL when redirecting after a user switches.
|
652 |
+
*
|
653 |
+
* This matches the WordPress core filter in `wp_admin_canonical_url()`.
|
654 |
+
*
|
655 |
+
* @since 1.0.4
|
656 |
+
*
|
657 |
+
* @param array $removable_query_args An array of parameters to remove from the URL.
|
658 |
+
*/
|
659 |
$args = apply_filters( 'removable_query_args', array(
|
660 |
'message', 'update', 'updated', 'settings-updated', 'saved',
|
661 |
'activated', 'activate', 'deactivate', 'enabled', 'disabled',
|
756 |
* Sets authorisation cookies containing the originating user information.
|
757 |
*
|
758 |
* @param int $old_user_id The ID of the originating user, usually the current logged in user.
|
759 |
+
* @param bool $pop Optional. Pop the latest user off the auth cookie, instead of appending the new one. Default false.
|
760 |
*/
|
761 |
function user_switching_set_olduser_cookie( $old_user_id, $pop = false ) {
|
762 |
$secure_auth_cookie = user_switching::secure_auth_cookie();
|
788 |
/**
|
789 |
* Clears the cookies containing the originating user, or pops the latest item off the end if there's more than one.
|
790 |
*
|
791 |
+
* @param bool $clear_all Optional. Whether to clear the cookies (as opposed to just popping the last user off the end). Default true.
|
792 |
*/
|
793 |
function user_switching_clear_olduser_cookie( $clear_all = true ) {
|
794 |
$auth_cookie = user_switching_get_auth_cookie();
|
858 |
* Switches the current logged in user to the specified user.
|
859 |
*
|
860 |
* @param int $user_id The ID of the user to switch to.
|
861 |
+
* @param bool $remember Optional. Whether to 'remember' the user in the form of a persistent browser cookie. Default false.
|
862 |
+
* @param bool $set_old_user Optional. Whether to set the old user cookie. Default true.
|
863 |
* @return bool|WP_User WP_User object on success, false on failure.
|
864 |
*/
|
865 |
function switch_to_user( $user_id, $remember = false, $set_old_user = true ) {
|
867 |
return false;
|
868 |
}
|
869 |
|
870 |
+
$old_user_id = ( is_user_logged_in() ) ? get_current_user_id() : false;
|
871 |
|
872 |
if ( $set_old_user && $old_user_id ) {
|
873 |
user_switching_set_olduser_cookie( $old_user_id );
|
880 |
wp_set_current_user( $user_id );
|
881 |
|
882 |
if ( $set_old_user ) {
|
883 |
+
/**
|
884 |
+
* Fires when a user switches to another user account.
|
885 |
+
*
|
886 |
+
* @since 0.6.0
|
887 |
+
*
|
888 |
+
* @param int $user_id The ID of the user being switched to.
|
889 |
+
* @param int $old_user_id The ID of the user being switched from.
|
890 |
+
*/
|
891 |
do_action( 'switch_to_user', $user_id, $old_user_id );
|
892 |
} else {
|
893 |
+
/**
|
894 |
+
* Fires when a user switches back to their originating account.
|
895 |
+
*
|
896 |
+
* @since 0.6.0
|
897 |
+
*
|
898 |
+
* @param int $user_id The ID of the user being switched back to.
|
899 |
+
* @param int|false $old_user_id The ID of the user being switched from, or false if the user is switching back
|
900 |
+
* after having been switched off.
|
901 |
+
*/
|
902 |
do_action( 'switch_back_user', $user_id, $old_user_id );
|
903 |
}
|
904 |
|
922 |
wp_clear_auth_cookie();
|
923 |
wp_set_current_user( 0 );
|
924 |
|
925 |
+
/**
|
926 |
+
* Fires when a user switches off.
|
927 |
+
*
|
928 |
+
* @since 0.6.0
|
929 |
+
*
|
930 |
+
* @param int $old_user_id The ID of the user switching off.
|
931 |
+
*/
|
932 |
do_action( 'switch_off_user', $old_user_id );
|
933 |
|
934 |
return true;
|