Changeset 1069862
- Timestamp:
- 01/17/2015 05:27:14 AM (11 years ago)
- Location:
- userswitcher
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
userswitcher/style.css
r1069673 r1069862 1 1 #switcher-form { 2 2 position: absolute; 3 padding: 1px 0; 4 background: rgba(0, 0, 0, 0.5); 5 width: 40px; 3 border: 1px #ddd solid; 4 background: #000; 5 margin: 0; 6 z-index: 999; 7 background: #000 url(arrow_switch_right.png) no-repeat left center; 8 padding: 4px 5px 4px 35px; 9 vertical-align: middle; 10 cursor: pointer; 11 height: 30px; 12 width: auto; 13 } 14 #switcher-form select, 15 #wpadminbar #switcher-form select { 16 position: relative; 17 margin:0; 18 display: table; 19 vertical-align: middle; 20 top:0; 21 padding-left:0; 22 padding-right:0; 23 -moz-border-radius: 0; 24 border-radius: 0; 25 font-size: 14px; 26 border: 1px #ddd solid; 27 width: 0; 6 28 overflow: hidden; 7 height: 40px; 8 transition: width 0.4s ease-in-out, height 0.4s ease-in; 29 -webkit-transition: width 0.4s ease; 30 -moz-transition: width 0.4s ease; 31 transition: width 0.4s ease; 32 -webkit-transform: translate3d(0,0,0); 33 -moz-transform: translate3d(0,0,0); 9 34 transform: translate3d(0,0,0); 10 z-index: 9;35 cursor: pointer; 11 36 } 12 .switch-fixed { 13 margin: 5px 15px; 37 #switcher-form option { 38 padding: 3px 15px; 39 border-bottom: 1px #ddd solid; 40 } 41 #switcher-form .switch-icon { 42 position: absolute; 43 top:0; 44 left: 0; 45 width: 30px; 46 height: 100%; 47 } 48 #switcher-form.switch-fixed { 49 position: fixed; 50 right:0; 51 bottom:0; 14 52 } 15 53 #switcher-form.switch-admin { 16 position: relative; 17 margin:0; 18 height: 30px; 54 border: 0; 19 55 } 20 #switcher-form option {21 padding: 2px 15px;22 border-bottom: 1px #ddd solid;23 color: #333;24 }25 #switcher-form .switch-icon {26 position: relative;27 float: left;28 width: 40px;29 background: url(arrow_switch_right.png) no-repeat left center;30 height: 40px;31 cursor: pointer;32 }33 #switcher-form.switch-admin .switch-icon {34 height: 30px;35 }36 #switcher-form select {37 position: relative;38 z-index: 1;39 cursor: pointer;40 color: #333;41 border: 1px #ddd solid;42 } -
userswitcher/switch.js
r1069673 r1069862 2 2 var is_admin = true, is_added = false, 3 3 toggleSwitcher = function(){ 4 var target = $(this), form = target.parents('form').first(), 5 is_open = form.width() > 40; 6 form.css({ 7 width: is_open ? 40 : 200, 8 height: is_admin ? 30 : 40 9 }) 10 //form.css('width', is_open ? 40 : 200); 4 var target = $(this), form = target.parents('form').first(), box = form.find('select'); 5 is_open = box.width() > 40; 6 box.css({width: is_open ? 0 : 200 }); 11 7 }; 12 8 … … 31 27 } 32 28 form = $('#switcher-form').addClass(_class); 33 is_added = true;34 29 }; 35 30 -
userswitcher/userSwitcher.php
r1069701 r1069862 13 13 var $user_switcher; 14 14 var $is_switching = false; 15 var $user_data; 15 16 16 17 public function __construct(){ … … 19 20 add_action( 'admin_bar_menu', array( $this, 'switcher_html' ), 1000 ); 20 21 add_action( ( is_admin() ? 'admin_footer' : 'wp_footer'), array( $this, 'footer'), 1 ); 21 22 22 } 23 23 … … 33 33 } 34 34 35 public function validate_current_user(){ 35 public function validate_current_user(){ 36 36 global $pagenow, $current_user; 37 37 $this->current_switcher = get_current_user_id(); … … 42 42 add_filter( 'user_has_cap', array( $this, 'set_option_cap' ), 15, 3 ); 43 43 44 // Get the switcher's original userdata first 45 $this->user_data = get_userdata( (int) $this->current_switcher ); 46 44 47 if( intval( $this->user_switcher ) > 0 ){ 45 48 $user = get_userdata( (int) $this->user_switcher ); 46 $current_user = $user; 49 $current_user = $user; 47 50 } 48 51 else { 49 $caps = get_role( (string) $this->user_switcher )->capabilities; 52 $caps = get_role( (string) $this->user_switcher )->capabilities; 50 53 $current_user->allcaps = $caps; 54 $current_user->allcaps[ (string) $this->user_switcher ] = 1; 51 55 $current_user->roles = $current_user->caps = array( $this->user_switcher ); 52 56 } 53 57 $this->is_switching = true; 58 59 if( $pagenow == 'options.php' && isset($_REQUEST['user_switcher']) ) { 60 $current_user = $this->user_data; 61 } 54 62 } 55 63 } 56 64 57 65 public function set_option_cap($caps, $cap, $a){ 58 global $pagenow; 59 if( $pagenow == 'options.php' && $this->current_switcher != $this->user_switcher ) 66 global $pagenow, $current_user; 67 68 if( $pagenow == 'options.php' && $this->is_switching ){ 60 69 $caps['manage_options']= 1; 70 } 61 71 62 72 if( !is_admin() ){ … … 84 94 85 95 public function footer(){ 86 global $wp_admin_bar ;96 global $wp_admin_bar, $current_user, $wp_roles; 87 97 88 if( $this->is_switching ){ 89 90 $switcher_url = WP_PLUGIN_URL . "/userSwitcher"; 91 wp_enqueue_style( 'switch-css', $switcher_url . '/style.css' ); 92 wp_enqueue_script( 'switch-js', $switcher_url . '/switch.js' ); 98 if( $this->is_switching ){ 99 $switcher_url = WP_PLUGIN_URL . "/userSwitcher"; 100 wp_enqueue_style( 'switch-css', $switcher_url . '/style.css' ); 101 wp_enqueue_script( 'switch-js', $switcher_url . '/switch.js' ); 102 $old_userdata = $current_user; 103 $current_user = $this->user_data; 93 104 ?> 94 105 <script type="text/template" id="switcher-template"> … … 96 107 <input type="hidden" name="option_page" value="<?php _e( esc_attr( 'user_switcher' ) ); ?>" /> 97 108 <input type="hidden" name="action" value="update" /> 98 <input type="hidden" name="_wp_http_referer" value="<?php _e(remove_query_arg('user_switcher')); ?>" />99 109 <?php wp_nonce_field("user_switcher-options");?> 100 110 <span class="switch-icon"></span> … … 120 130 </script> 121 131 <?php 132 $current_user = $old_userdata; 122 133 } 123 134 }
Note: See TracChangeset
for help on using the changeset viewer.