Changeset 1157185
- Timestamp:
- 05/10/2015 08:20:23 AM (11 years ago)
- Location:
- userswitcher
- Files:
-
- 4 edited
-
tags/1.1.2/readme.txt (modified) (1 diff)
-
tags/1.1.2/style.css (modified) (1 diff)
-
tags/1.1.2/userSwitcher.php (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
userswitcher/tags/1.1.2/readme.txt
r1098959 r1157185 1 1 === userSwitcher === 2 2 3 Contributors: irenem 4 3 5 Tags: guest, user, users, roles, capabilities, switcher 6 4 7 Requires at least: 3.4 5 Tested up to: 4.1 8 9 Tested up to: 4.2 10 6 11 Stable tag: 1.1.2 12 7 13 License: GPLv2 or later 14 15 8 16 9 17 Switch between user accounts to xperience what you're users can and cannot do without logging in and out. 10 18 19 20 11 21 == Description == 22 12 23 userSwitcher allows you to switch between user accounts without the hassle of logging in/out. It allows you to do, experience and know what you're users can and cannot do. 13 24 25 26 14 27 = Features = 28 15 29 * Switch between user role or account. 30 16 31 * Switch to "Guest" account without logging out. 32 17 33 * Inherit all capabilities to the selected account. 18 34 19 35 36 37 38 20 39 == Installation == 40 21 41 1. Upload `userSwitcher` to the `/wp-content/plugins/` directory 42 22 43 1. Activate the plugin through the 'Plugins' menu in WordPress 44 23 45 1. Click `userSwitcher` menu at the top to select user role or account. You will automatically switched to your selected role or account. 46 47 24 48 25 49 == Frequently Asked Questions == 26 50 27 51 52 53 54 28 55 = How to use userSwitcher? = 56 29 57 Click the `userSwitcher` menu at the top then select the type of role and account you wish to switch to. You will automatically switched to that account. 58 30 59 Select `Administrator` to change back to your account. 31 60 61 62 32 63 = Why am I redirected to the front page when selecting guest user? = 64 33 65 Dah. Obviously `GUEST` user do not have access to admin's panel. But no worries, you can still able to go back to admin's panel by selecting a different role or account then navigate back. 34 66 67 68 35 69 = Am I logged out when switching to GUEST user? = 70 36 71 No. Regardless of what type of role or user you switch yourself into, you are still logged in as you. 37 72 73 74 38 75 = Can I add post while switching? = 76 39 77 That depends on the type of user you switch yourself into. If you switch to say editor then you still able to add post. Take note though that if you choose an account and not a role, you will not be the author of the post but the selected user. 40 78 79 80 41 81 = I switch to guest user, why can I still read private posts? = 82 42 83 Private or password protected posts authored by you are still readable if you switch to `GUEST` or any other user `role`. 43 84 85 86 44 87 == Screenshots == 88 45 89 1. Switcher menu 46 90 91 92 47 93 == Changelog == 94 48 95 = 1.0 = 96 49 97 * First release. 50 98 99 100 51 101 = 1.1 = 102 52 103 * Fix switcher UI at admin bar. 104 53 105 * Added switcher UI if admin bar is disabled. 54 106 107 108 55 109 = 1.1.2 = 110 56 111 * Rename directory url not showing on Linux. 112 57 113 * Added "My Account" option for easy switching back to current account. -
userswitcher/tags/1.1.2/style.css
r1098954 r1157185 1 1 .switch-bg { 2 2 3 background: rgb(111,207,202); 4 3 5 background: -moz-linear-gradient(top, rgba(111,207,202,1) 0%, rgba(55,168,163,1) 100%); 6 4 7 background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(111,207,202,1)), color-stop(100%,rgba(55,168,163,1))); 8 5 9 background: -webkit-linear-gradient(top, rgba(111,207,202,1) 0%,rgba(55,168,163,1) 100%); 10 6 11 background: -o-linear-gradient(top, rgba(111,207,202,1) 0%,rgba(55,168,163,1) 100%); 12 7 13 background: -ms-linear-gradient(top, rgba(111,207,202,1) 0%,rgba(55,168,163,1) 100%); 14 8 15 background: linear-gradient(to bottom, rgba(111,207,202,1) 0%,rgba(55,168,163,1) 100%); 16 9 17 } 18 10 19 #switcher-form { 20 11 21 position: absolute; 22 12 23 border: 1px #ddd solid; 24 13 25 margin: 0; 26 14 27 z-index: 999; 28 15 29 left:0; 30 16 31 padding: 1px 0; 32 17 33 cursor: pointer; 34 18 35 height: 30px; 36 19 37 width: 120px; 38 20 39 text-indent: 0; 40 21 41 } 42 22 43 #switcher-form select, 44 23 45 #wpadminbar #switcher-form select { 46 24 47 position: relative; 48 25 49 font-size: 14px; 50 26 51 padding: 0; 52 27 53 -moz-border-radius: 0; 54 28 55 border-radius: 0; 56 29 57 display: table; 58 30 59 vertical-align: middle; 60 31 61 width: 0; 62 32 63 overflow: hidden; 64 33 65 -webkit-transition: width 0.4s ease; 66 34 67 -moz-transition: width 0.4s ease; 68 35 69 transition: width 0.4s ease; 70 36 71 -webkit-transform: translate3d(0,0,0); 72 37 73 -moz-transform: translate3d(0,0,0); 74 38 75 transform: translate3d(0,0,0); 76 39 77 margin: 0 0 0 110px; 78 40 79 cursor: pointer; 80 41 81 border:0; 82 42 83 outline: none; 84 43 85 } 86 44 87 #switcher-form option { 88 45 89 padding: 3px 15px; 90 46 91 border-bottom: 1px #ddd solid; 92 47 93 } 94 48 95 #switcher-form .switch-icon { 96 49 97 position: absolute; 98 50 99 left:0; 100 51 101 height: 100%; 102 52 103 padding-left: 30px; 104 53 105 padding-right:5px; 106 54 107 color: #333; 108 55 109 line-height: 28px; 110 56 111 background: url(arrow_switch_right.png) no-repeat left center; 112 57 113 } 114 58 115 #switcher-form.switch-fixed { 116 59 117 position: fixed; 118 60 119 left:0; 120 61 121 bottom:0; 122 62 123 } 124 63 125 #switcher-form.switch-fixed select { 126 64 127 margin-left: 115px; 128 65 129 } 130 66 131 #switcher-form.switch-admin { 132 67 133 border: 0; 134 68 135 } -
userswitcher/tags/1.1.2/userSwitcher.php
r1098955 r1157185 1 1 <?php 2 2 3 /** 4 3 5 * Plugin Name: userSwitcher 6 4 7 * Plugin URI: http://irenemitchell.com/userswitcher 8 5 9 * Description: Experience what you're user experienced and know what they can do to your site without logging in/out. 10 6 11 * Version: 1.1.2 12 7 13 * Author: Irene A. Mitchell 14 8 15 * Author URI: http://irenemitchell.com 16 9 17 * License: GPLv2 or later 18 10 19 **/ 11 20 21 22 12 23 if( ! class_exists( 'userSwitcher' ) ): 24 13 25 class userSwitcher { 26 14 27 var $current_switcher; 28 15 29 var $user_switcher; 30 16 31 var $is_switching = false; 32 17 33 var $user_data; 18 34 35 36 19 37 public function __construct(){ 38 20 39 add_action( 'init', array($this, 'validate_current_user'), 1); 40 21 41 add_action( 'admin_init', array($this, 'admin_init'), 1); 42 22 43 add_action( 'admin_bar_menu', array( $this, 'switcher_html' ), 1000 ); 44 23 45 add_action( ( is_admin() ? 'admin_footer' : 'wp_footer'), array( $this, 'footer'), 1 ); 24 } 25 46 47 } 48 49 50 26 51 public function admin_init(){ 52 27 53 register_setting( 'user_switcher', 'user_switcher', array( $this, 'redirect_switcher' ) ); 28 } 29 54 55 } 56 57 58 30 59 public function redirect_switcher($req){ 60 31 61 if( preg_match( '%wp-admin%', $_REQUEST['_wp_http_referer']) ){ 62 32 63 $_REQUEST['_wp_http_referer'] = in_array( 'guest', (array) $_REQUEST['user_switcher']) ? site_url() : admin_url(); 33 } 64 65 } 66 34 67 return $req; 35 } 36 68 69 } 70 71 72 37 73 public function validate_current_user(){ 74 38 75 global $pagenow, $current_user; 76 39 77 $this->current_switcher = get_current_user_id(); 78 40 79 $switchers = (array) get_option( 'user_switcher' ); 41 $this->user_switcher = $switchers[$this->current_switcher]; 80 81 $this->user_switcher = isset( $switchers[$this->current_switcher] ) ? $switchers[$this->current_switcher] : ''; 82 42 83 $this->is_switching = is_super_admin(); 43 84 85 86 44 87 if( !empty($this->user_switcher) && $this->current_switcher != $this->user_switcher ){ 88 45 89 add_filter( 'user_has_cap', array( $this, 'set_option_cap' ), 15, 3 ); 46 90 91 92 47 93 // Get the switcher's original userdata first 94 48 95 $this->user_data = get_userdata( (int) $this->current_switcher ); 49 96 97 98 50 99 if( intval( $this->user_switcher ) > 0 ){ 100 51 101 $user = get_userdata( (int) $this->user_switcher ); 102 52 103 $current_user = $user; 53 } 104 105 } 106 54 107 else { 108 55 109 $caps = get_role( (string) $this->user_switcher )->capabilities; 110 56 111 $current_user->allcaps = $caps; 112 57 113 $current_user->allcaps[ (string) $this->user_switcher ] = 1; 114 58 115 $current_user->roles = $current_user->caps = array( $this->user_switcher ); 59 } 60 116 117 } 118 119 120 61 121 if( $pagenow == 'options.php' && isset($_REQUEST['user_switcher']) ) { 122 62 123 $current_user = $this->user_data; 63 } 64 } 65 } 66 124 125 } 126 127 } 128 129 } 130 131 132 67 133 public function set_option_cap($caps, $cap, $a){ 134 68 135 global $pagenow, $current_user; 136 69 137 138 70 139 if( $pagenow == 'options.php' && $this->is_switching ){ 140 71 141 $caps['manage_options']= 1; 72 } 73 142 143 } 144 145 146 74 147 if( !is_admin() ){ 148 75 149 switch( $this->user_switcher ){ 150 76 151 case 'subscriber': 152 77 153 $caps = array('read' => 1); 154 78 155 break; 79 } 80 } 156 157 } 158 159 } 160 81 161 return $caps; 82 } 83 162 163 } 164 165 166 84 167 public function switcher_html(){ 168 85 169 $current = get_userdata( (int) $this->current_switcher ); 170 86 171 if( in_array( 'administrator', $current->roles ) ) { 172 87 173 174 88 175 global $wp_admin_bar; 89 176 177 178 90 179 $wp_admin_bar->add_menu( array( 180 91 181 'id' => 'user-switcher', 182 92 183 'title' => '<span class="switcher-icon">Switch To: </span>' 184 93 185 )); 94 } 95 } 96 186 187 } 188 189 } 190 191 192 97 193 public function footer(){ 194 98 195 global $wp_admin_bar, $current_user, $wp_roles; 196 99 197 198 100 199 if( $this->is_switching ){ 200 101 201 $switcher_url = WP_PLUGIN_URL . "/userswitcher"; 202 102 203 wp_enqueue_style( 'switch-css', $switcher_url . '/style.css' ); 204 103 205 wp_enqueue_script( 'switch-js', $switcher_url . '/switch.js' ); 206 104 207 $old_userdata = $current_user; 208 105 209 $current_user = $this->user_data; 210 106 211 ?> 212 107 213 <script type="text/template" id="switcher-template"> 214 108 215 <form method="post" action="<?php _e(admin_url()); ?>options.php" class="switch-bg" id="switcher-form"> 216 109 217 <input type="hidden" name="option_page" value="<?php _e( esc_attr( 'user_switcher' ) ); ?>" /> 218 110 219 <input type="hidden" name="action" value="update" /> 220 111 221 <?php wp_nonce_field("user_switcher-options");?> 222 112 223 <span class="switch-icon">userSwitcher</span> 224 113 225 <select tabindex="1" name="user_switcher[<?php _e($this->current_switcher); ?>]"> 226 114 227 <option value="<?php _e($this->current_switcher); ?>">My Account</option> 228 115 229 <option value="guest" <?php selected('guest', $this->user_switcher); ?>>Guest</option> 230 116 231 <?php 232 117 233 global $wp_roles; 234 118 235 $roles = array_map(create_function('$a', ' return $a["name"]; ' ), $wp_roles->roles ); 236 119 237 238 120 239 foreach( $roles as $role => $label ): ?> 240 121 241 <option value="<?php _e($role); ?>" <?php selected($this->user_switcher, $role); ?>><?php _e($label); ?></option> 242 122 243 <?php 244 123 245 $users = get_users( array( 'role' => $role, 'exclude' => $this->current_switcher ) ); 246 124 247 248 125 249 if( !is_wp_error( $users ) && count( $users ) > 0 ): 250 126 251 foreach( $users as $user ): ?> 252 127 253 <option value="<?php _e($user->ID); ?>" <?php selected($this->user_switcher, $user->ID); ?>>→ <?php _e($user->display_name); ?></option> 254 128 255 <?php endforeach; ?> 256 129 257 <?php endif; ?> 258 130 259 <?php endforeach; ?> 260 131 261 </select> 262 132 263 </form> 264 133 265 </script> 266 134 267 <?php 268 135 269 $current_user = $old_userdata; 136 } 137 } 270 271 } 272 273 } 274 138 275 } 276 139 277 new userSwitcher; 278 140 279 endif; -
userswitcher/trunk/readme.txt
r1098959 r1157185 3 3 Tags: guest, user, users, roles, capabilities, switcher 4 4 Requires at least: 3.4 5 Tested up to: 4. 15 Tested up to: 4.2 6 6 Stable tag: 1.1.2 7 7 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.