Plugin Directory

Changeset 1069862


Ignore:
Timestamp:
01/17/2015 05:27:14 AM (11 years ago)
Author:
irenem
Message:

Updated ui

Location:
userswitcher
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • userswitcher/style.css

    r1069673 r1069862  
    11#switcher-form {
    22    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;
    628    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);
    934    transform: translate3d(0,0,0);
    10     z-index: 9;
     35    cursor: pointer;
    1136}
    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;
    1452}
    1553#switcher-form.switch-admin {
    16     position: relative;
    17     margin:0;
    18     height: 30px;
     54    border: 0;
    1955}
    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  
    22    var is_admin = true, is_added = false,
    33    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 });
    117    };
    128   
     
    3127        }
    3228        form = $('#switcher-form').addClass(_class);
    33         is_added = true;
    3429    };
    3530   
  • userswitcher/userSwitcher.php

    r1069701 r1069862  
    1313                var $user_switcher;
    1414                var $is_switching = false;
     15                var $user_data;
    1516               
    1617                public function __construct(){
     
    1920                        add_action( 'admin_bar_menu', array( $this, 'switcher_html' ), 1000 );                       
    2021                        add_action( ( is_admin() ? 'admin_footer' : 'wp_footer'), array( $this, 'footer'), 1 );
    21                
    2222                }
    2323               
     
    3333                }
    3434               
    35                 public function validate_current_user(){
     35                public function validate_current_user(){ 
    3636                        global $pagenow, $current_user;
    3737                        $this->current_switcher = get_current_user_id();
     
    4242                                add_filter( 'user_has_cap', array( $this, 'set_option_cap' ), 15, 3 );
    4343                               
     44                                // Get the switcher's original userdata first
     45                                $this->user_data = get_userdata( (int) $this->current_switcher );
     46                               
    4447                                if( intval( $this->user_switcher ) > 0 ){                                       
    4548                                        $user = get_userdata( (int) $this->user_switcher );
    46                                         $current_user = $user;
     49                                        $current_user = $user;                                       
    4750                                }
    4851                                else {
    49                                         $caps = get_role( (string) $this->user_switcher )->capabilities;
     52                                        $caps = get_role( (string) $this->user_switcher )->capabilities;                                     
    5053                                        $current_user->allcaps = $caps;
     54                                        $current_user->allcaps[ (string) $this->user_switcher ] = 1;                                       
    5155                                        $current_user->roles = $current_user->caps = array( $this->user_switcher );
    5256                                }
    5357                                $this->is_switching = true;
     58                               
     59                                if( $pagenow == 'options.php' && isset($_REQUEST['user_switcher']) ) {
     60                                        $current_user = $this->user_data;
     61                                }
    5462                        }
    5563                }
    5664               
    5765                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 ){
    6069                                $caps['manage_options']= 1;
     70                        }
    6171                               
    6272                        if( !is_admin() ){
     
    8494               
    8595                public function footer(){                       
    86                         global $wp_admin_bar;
     96                        global $wp_admin_bar, $current_user, $wp_roles;
    8797                       
    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;
    93104                ?>
    94105                        <script type="text/template" id="switcher-template">
     
    96107                                <input type="hidden" name="option_page" value="<?php _e( esc_attr( 'user_switcher' ) ); ?>" />
    97108                                <input type="hidden" name="action" value="update" />
    98                                 <input type="hidden" name="_wp_http_referer" value="<?php _e(remove_query_arg('user_switcher')); ?>" />
    99109                                <?php wp_nonce_field("user_switcher-options");?>
    100110                                        <span class="switch-icon"></span>
     
    120130                        </script>
    121131                <?php
     132                                $current_user = $old_userdata;
    122133                        }
    123134                }
Note: See TracChangeset for help on using the changeset viewer.