From c7e59cd6c1c94edeee44a5468bb9b77a3c5e74b6 Mon Sep 17 00:00:00 2001 From: Justin de Vesine Date: Thu, 19 Jul 2012 15:13:57 -0600 Subject: [PATCH] add 0.5.2 from http://plugins.svn.wordpress.org/user-switching/trunk/ @r574859 --- languages/readme.txt | 10 + languages/user_switching-de_DE.mo | Bin 0 -> 1220 bytes languages/user_switching-fa_IR.mo | Bin 0 -> 1205 bytes languages/user_switching-zh_CN.mo | Bin 0 -> 1247 bytes readme.txt | 158 +++++++++ screenshot-1.png | Bin 0 -> 4219 bytes screenshot-2.png | Bin 0 -> 4974 bytes user-switching.php | 510 ++++++++++++++++++++++++++++++ 8 files changed, 678 insertions(+) create mode 100644 languages/readme.txt create mode 100644 languages/user_switching-de_DE.mo create mode 100644 languages/user_switching-fa_IR.mo create mode 100644 languages/user_switching-zh_CN.mo create mode 100644 readme.txt create mode 100644 screenshot-1.png create mode 100644 screenshot-2.png create mode 100644 user-switching.php diff --git a/languages/readme.txt b/languages/readme.txt new file mode 100644 index 0000000..e665450 --- /dev/null +++ b/languages/readme.txt @@ -0,0 +1,10 @@ +== For Translators == + +Note: this folder contains MO files only. If you are looking for the POT or PO files, you can download them here: + +http://plugins.svn.wordpress.org/user-switching/assets/ + +If you have created your own translation, or have an update of an existing one, please send it to so I can bundle it into the next release of the plugin. + +Thank you. +John. diff --git a/languages/user_switching-de_DE.mo b/languages/user_switching-de_DE.mo new file mode 100644 index 0000000000000000000000000000000000000000..a61268dc12dca81faf45752705c1daae91c022e9 GIT binary patch literal 1220 zcmb7@&2G~`5XTqMQx1R-2!uc^Qj3bpI(7=BxPWLwTU8Jm<%0q@#~vpp&Th23ZfKr? zD+lg80>^UVz!`BxyZ~>&iNBkK5IzoA8vSNHvpfG8d%vEZd(H3^U>9L&zQA)h!V%BH ze-Aqc`wY7Q`v%MR@MDZ!0GGfM;1+lZY=Y-O1Nz`A@C)oC>^jzOk2AIiegap(@8B8G zn`7)UxCNd9WAF+%0P{L;z?0xRkd;-IMqDb(%^Rh(dLLJi4tv$?FQ)e8!(*onjwG@B^t z^Vt;cIyW89@d`ESD{V!^w3A3|WNjlF%I6(x`+l)FK;!+qaYyNP(FW~eJ{vI_FGLlp zyA4s+6j+oH4+2X*FS%YxxXYrn3fFf%-@CQs!f}x-YP6r^a(>Uf&D|A$d3nk8koPDs zRy1@VO&VCGeO?RFeuvjB$swiuj?S0&yD2471TE-^;W-iA!%o@Gf;Nc;1-<{+SJ|m- zPABC#ZlSCs%0b3KA3a%mX^Z_dNaPw1JApQ2?=~A-Vs)CA%Z;IBQ-&(SXnelfN^Ie& zs49vQD<;x>zD>Fp$Y}(>t+e_8fz4WF{qeJDq^>d@Qh8L+=b4RBkv&ur+ISaD2SGw3lz`+PV^ z;KTWO1H|Nr?$LnQwCF?$NwzmSp7=1+9}aOphS|*hn8ZgnWSFt%qr5hah1uVBIBfgh Kp^2jLUiJggtZ#Jy literal 0 HcmV?d00001 diff --git a/languages/user_switching-fa_IR.mo b/languages/user_switching-fa_IR.mo new file mode 100644 index 0000000000000000000000000000000000000000..4294beefe9142179f359b02c211b34b7f1ab6f94 GIT binary patch literal 1205 zcmb7?Pfrs;7{*sc(Iy%-F)C`D0~iVJcH07}3lb_Kl9WHeqVb~HZl}viyVLAWMLEkK zlU_V{@&mLIv}tPML1X+Fvo!HD=-G?U(2`Q{;v~=f`tJMAJI_1m&+}dH6s!<*70N-U zp>L2}zn}}yZ|EY_eMC_P!Rw$rlLC9dXW$ud6}$$%0WX1N&;Wmc%g`UFAF+L`$+zHB z#9zU4U{9B#Tmf%^XTb*`0iU$E3SLJ19z-hz$9C5#?9xv+bR0SgorL5<>Fzoq_X$?a zWr)i-@mCyfEfJQ@YKOlTed_s|GVS`@boXi<*CuJoS15IfEFh+3v7*a;;<)57^D^@u z^?l`Gv+-OuyZ19~TFZnp(iiFV$<4lKuixKF-Eh->VI;*`Ah7R!&J+_j6QP1O`N^9D&KW~UYtQL2RXPpF_VjHTGU|m#2S=2=Je=6IJM5R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NI@64dGJmi4ChUxJv)O9!`-?0Qi5v*gq8#3Zx_&Pm!JjruPIB z@`c#SI}a0|A0YHLqp*8C+i6jh9pMlTPM5s{`^-4qD6G9HPQ5-wB4bau9{X7MT6cRD z=G=zD>NoC4@2S?Bt|U^?0uanNss^3Jxdw>z*9$o8Mn^!qDlfSTXkCUL98 zSE^F$sAp#G3kkNeDul=mCpJMX?m4Y2^rGW-V6?0IqYXsPD7G0T`wOkrE@65v;o39_ zyfoOQV|0#;z-Q;lbpiUFsKWt}92N=u361Bz1OH9&)&4)O7ep~VPY#OYwo4>1A3?eq z)h$e#iQ0iVUyR|bpz#dLZhp4%=NQTccYNQq9&s;WQT4;!yu24eK(ycg0EV}SxKP1p z*`{(w;82(j7ga3P|6AV?!%)HOHy*4_lL-Yy59}a@1y&iFXfQ-LVCC(pq`%5a7#=zk zKx?}sR^GiA%74S7%~%Tsv3H0+M%WV={C)7j(=4X{DOdK%<(&s_$nx?<_jOR$j}z}H zNpP`$Ol$jL`xpOFYXMRzY48S1UGW5#?z}M-4ahJSE?-rWzI1H4-PJL|vTZ)}o7a#8 zaB|%G}GHAG`lNC!5v&Z=yd|%on{Uxk7HSj?o z^Vjd9RQ<-K7w?-NVTveTuh#_#M>NeHELuJUCPDa6DRE7%k1XA6&qE=F8TkZ@qHIgu zKFkMI_FxTs&?9~Q6;mTDY@@^euc+yMvBfVDR_o8Ze->{&dE%He^!^y!7ZFsVT&ar? zqFQlt)T=I_uKXYuxE&*)472Jc8UjwhpZmob40~nNoz?S|21By5{=szINOgVNQ?KJ$ Y!e6tUYsih^{!QSqIA>#8YJ!RWFLGHWu>b%7 literal 0 HcmV?d00001 diff --git a/screenshot-2.png b/screenshot-2.png new file mode 100644 index 0000000000000000000000000000000000000000..a18ec7cd503fc010442eefc0c3d44cb58916ad7b GIT binary patch literal 4974 zcmb7Ic{J2*`zJ+Fgd#j4${Io$$&iGyjU~o9Wto&^#8@&&wuCZ8jCJfLd$PqCB0Jdz zV;ww}nXye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^weK6MHHW1tJ3B)A zeCNGA!y^6JPjw5_*g5h!Ruv31VF;7?j zZp;3AP5+~ZbBQFI^sBj_lGN|N_Um-w&wRAlNmm7F@C-(n4K)s>L^Y@`GOD8Oev!iI z#yi2Z6F-?Uc$e0`qSl3m@?Gr5womWXtJI2MROFEvTp)s<+e_H?=XW6s!-GT#@5P5) zjkl(E@)N>U+A7>37g+T@?m@A>g7?7i#^_B|?X|?vv#~k;?8i0$hSlstP=S4i$zur& z;n%@&4=1HZV9@^O_i;P(>|mYcj?H5WkjimrQ($=5d&l^u*?t#o#*2luT8PuqgNHR` z`zr@TY|iv;33lG`V){P(O=Od6@JWIea&ORJZth%2gL)b;f4+};Oj2K}l2ZA{@GH)n zTJ&Sp<_%aLl=m&k#c?81*!0y&nE7E>#qi`&xf!kAe_7s#L`-HjB?YhXx!m2@oewzk zMnsVsy$wQS3Zfk6az2}-btZ;@ll^8eeJlJ$)>U0Mo$sNu_?2o!6q+ViaWfBl_BU=W z_E+ja_C~farNt!OfhP~^r&4a;=4f=a7Z?(!Mt)!G5Z4O-@}r^a#h=mf)D4V~5|VQu zcl)jRhnr~YW?iw49DL9;{_08}bT~()-<%fUr)4R3z_`07U1SqyI$8G!UBX}Ni~9MJ#( literal 0 HcmV?d00001 diff --git a/user-switching.php b/user-switching.php new file mode 100644 index 0000000..8f85d10 --- /dev/null +++ b/user-switching.php @@ -0,0 +1,510 @@ +ID ) ) + return; + ?> + + + + + ID, false ); + + return ( ( $current['expiration'] - time() ) > $cookie_life ); + + } + + /** + * Load localisation files and route actions depending on the 'action' query var. Actions are secured + * with WordPress' nonce system. + * + * @return null + */ + function init() { + + load_plugin_textdomain( 'user_switching', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); + + if ( !isset( $_REQUEST['action'] ) ) + return; + + switch ( $_REQUEST['action'] ) { + + # We're attempting to switch to another user: + case 'switch_to_user': + $user_id = intval( $_REQUEST['user_id'] ); + + check_admin_referer( "switch_to_user_{$user_id}" ); + + # Switch user: + if ( switch_to_user( $user_id, $this->remember() ) ) { + + # Redirect to the dashboard or the home URL depending on capabilities: + if ( !current_user_can( 'read' ) ) + wp_redirect( add_query_arg( array( 'user_switched' => 'true' ), home_url() ) ); + else + wp_redirect( add_query_arg( array( 'user_switched' => 'true' ), admin_url() ) ); + die(); + + } else { + wp_die( __( 'Could not switch users.', 'user_switching' ) ); + } + break; + + # We're attempting to switch back to the originating user: + case 'switch_to_olduser': + + check_admin_referer( 'switch_to_olduser' ); + + # Fetch the originating user data: + if ( !$old_user = $this->get_old_user() ) + wp_die( __( 'Could not switch users.', 'user_switching' ) ); + + # Switch user: + if ( switch_to_user( $old_user->ID, $this->remember(), false ) ) { + wp_redirect( add_query_arg( array( 'user_switched' => 'true', 'back' => 'true' ), admin_url('users.php') ) ); + die(); + } else { + wp_die( __( 'Could not switch users.', 'user_switching' ) ); + } + break; + + # We're attempting to switch off the current user: + case 'switch_off': + + check_admin_referer( 'switch_off' ); + + # Switch off: + if ( switch_off_user() ) { + wp_redirect( add_query_arg( array( 'switched_off' => 'true' ), home_url() ) ); + die(); + } else { + wp_die( __( 'Could not switch off.', 'user_switching' ) ); + } + break; + + } + + } + + /** + * Display the 'Switched to {user}' and 'Switch back to {user}' messages in the admin area. + * + * @return null + */ + function admin_notice() { + global $user_identity, $user_login; + + if ( $old_user = $this->get_old_user() ) { + + ?> +
+

%s.', $this->switch_back_url(), sprintf( __( 'Switch back to %1$s (%2$s)', 'user_switching' ), $old_user->display_name, $old_user->user_login ) ); + ?>

+
+ +
+

+
+ get_node( 'user-actions' ) ) + $parent = 'user-actions'; + else if ( get_option( 'show_avatars' ) ) + $parent = 'my-account-with-avatar'; + else + $parent = 'my-account'; + + if ( $old_user = $this->get_old_user() ) { + + $wp_admin_bar->add_menu( array( + 'parent' => $parent, + 'id' => 'wp-admin-bar-switch-back', + 'title' => sprintf( __( 'Switch back to %1$s (%2$s)', 'user_switching' ), $old_user->display_name, $old_user->user_login ), + 'href' => $this->switch_back_url() + ) ); + + } + + if ( current_user_can( 'switch_off' ) ) { + + $wp_admin_bar->add_menu( array( + 'parent' => $parent, + 'id' => 'wp-admin-bar-switch-off', + 'title' => __( 'Switch Off', 'user_switching' ), + 'href' => $this->switch_off_url() + ) ); + + } + + } + + /** + * Adds a 'Switch back to {user}' link to the WordPress footer if a user is switched off. + * + * @return null + */ + function switch_on() { + + if ( !is_user_logged_in() and $old_user = $this->get_old_user() ) { + $link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user_switching' ), $old_user->display_name, $old_user->user_login ); + echo '

' . $link . '

'; + } + + } + + /** + * Adds a 'Switch back to {user}' link to the WordPress login screen if a user is switched off. + * + * @return null + */ + function login_message( $message ) { + + if ( !is_user_logged_in() and $old_user = $this->get_old_user() ) { + $link = sprintf( __( 'Switch back to %1$s (%2$s)', 'user_switching' ), $old_user->display_name, $old_user->user_login ); + $message .= '

' . $link . '

'; + } + + return $message; + + } + + /** + * Adds a 'Switch To' link to each list of user actions on the Users screen. + * + * @return null + */ + function user_row( $actions, $user ) { + if ( current_user_can( 'switch_to_user', $user->ID ) ) + $actions[] = '' . __( 'Switch To', 'user_switching' ) . ''; + return $actions; + } + + /** + * Adds a 'Switch back to {user}' link to the BuddyPress admin bar. + * + * @return null + */ + function bp_menu() { + + if ( !is_admin() and $old_user = $this->get_old_user() ) { + + echo '
  • '; + printf( __( 'Switch back to %1$s (%2$s)', 'user_switching' ), $old_user->display_name, $old_user->user_login ); + echo '
  • '; + + } + + } + + /** + * Adds a 'Switch To' link to each member's profile page in BuddyPress. + * + * @return null + */ + function bp_button() { + + global $bp, $members_template; + + if ( !empty( $members_template ) ) + $id = intval( $members_template->member->id ); + else + $id = intval( $bp->displayed_user->id ); + + if ( current_user_can( 'switch_to_user', $id ) ) { + echo bp_get_button( array( + 'id' => 'user_switching', + 'component' => 'members', # https://buddypress.trac.wordpress.org/ticket/4212 + 'link_href' => $this->switch_to_url( $id ), + 'link_text' => __( 'Switch To', 'user_switching' ) + ) ); + } + + } + + /** + * Returns the nonce-secured URL needed to switch to a given user ID. + * + * @param int $user_id The user ID to be switched to. + * @return string The required URL + */ + function switch_to_url( $user_id ) { + return wp_nonce_url( add_query_arg( array( + 'action' => 'switch_to_user', + 'user_id' => $user_id + ), site_url( 'wp-login.php', 'login' ) ), "switch_to_user_{$user_id}" ); + } + + /** + * Returns the nonce-secured URL needed to switch back to the originating user. + * + * @return string The required URL + */ + function switch_back_url() { + return wp_nonce_url( add_query_arg( array( + 'action' => 'switch_to_olduser' + ), site_url( 'wp-login.php', 'login' ) ), 'switch_to_olduser' ); + } + + /** + * Returns the nonce-secured URL needed to "switch off" the current user. + * + * @return string The required URL + */ + function switch_off_url() { + return wp_nonce_url( add_query_arg( array( + 'action' => 'switch_off' + ), site_url( 'wp-login.php', 'login' ) ), 'switch_off' ); + } + + /** + * Filter the user's capabilities so they can be added/removed on the fly. + * + * This is used to grant the 'switch_to_user' capability to a user if they have the ability to edit the user + * they're trying to switch to (and that user is not themselves), and to grant the 'switch_off' capability to + * a user if they can edit users. + * + * Important: This does not get called for Super Admins. See map_meta_cap() below. + * + * @param array $user_caps User's capabilities + * @param array $required_caps Actual required capabilities for the requested capability + * @param array $args Arguments that accompany the requested capability check: + * [0] => Requested capability from current_user_can() + * [1] => Current user ID + * [2] => Optional second parameter from current_user_can() + * @return array User's capabilities + */ + function user_cap_filter( $user_caps, $required_caps, $args ) { + if ( 'switch_to_user' == $args[0] ) + $user_caps['switch_to_user'] = ( current_user_can( 'edit_user', $args[2] ) and ( $args[2] != $args[1] ) ); + else if ( 'switch_off' == $args[0] ) + $user_caps['switch_off'] = ( current_user_can( 'edit_users' ) and !$this->get_old_user() ); + return $user_caps; + } + + /** + * Filters the actual required capabilities for a given capability or meta capability. + * + * This is used to add the 'do_not_allow' capability to the list of required capabilities when a super admin + * is trying to switch to themselves. It affects nothing else as super admins can do everything by default. + * + * @param array $required_caps Actual required capabilities for the requested action + * @param string $cap Capability or meta capability being checked + * @param string $user_id Current user ID + * @param array $args Arguments that accompany this capability check + * @return array Required capabilities for the requested action + */ + function map_meta_cap( $required_caps, $cap, $user_id, $args ) { + if ( ( 'switch_to_user' == $cap ) and ( $args[0] == $user_id ) ) + $required_caps[] = 'do_not_allow'; + else if ( ( 'switch_off' == $cap ) and ( $this->get_old_user() ) ) + $required_caps[] = 'do_not_allow'; + return $required_caps; + } + +} + +/** + * Sets an authorisation cookie containing the user ID of the originating user. + * + * @param int $old_user_id The ID of the originating user, usually the current logged in user. + * @return null + */ +if ( !function_exists( 'wp_set_olduser_cookie' ) ) { +function wp_set_olduser_cookie( $old_user_id ) { + $expiration = time() + 172800; # 48 hours + $cookie = wp_generate_auth_cookie( $old_user_id, $expiration, 'old_user' ); + setcookie( OLDUSER_COOKIE, $cookie, $expiration, COOKIEPATH, COOKIE_DOMAIN, false ); +} +} + +/** + * Clears the cookie containing the originating user ID. + * + * @return null + */ +if ( !function_exists( 'wp_clear_olduser_cookie' ) ) { +function wp_clear_olduser_cookie() { + setcookie( OLDUSER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN ); +} +} + +/** + * Switches the current logged in user to the specified user. + * + * @param int $user_id The ID of the user to switch to. + * @param bool $remember Whether to 'remember' the user in the form of a persistent browser cookie. Optional. + * @param int|bool $old_user_id The ID of the originating user, or false to not set the old user cookie. Defaults to the current user. + * @return bool True on success, false on failure. + */ +if ( !function_exists( 'switch_to_user' ) ) { +function switch_to_user( $user_id, $remember = false, $old_user_id = 0 ) { + if ( !function_exists( 'wp_set_auth_cookie' ) ) + return false; + if ( !$user_id ) + return false; + if ( !$user = get_userdata( $user_id ) ) + return false; + + if ( 0 === $old_user_id ) { + if ( $current_user = wp_get_current_user() ) + $old_user_id = $current_user->ID; + } + + if ( $old_user_id ) + wp_set_olduser_cookie( $old_user_id ); + else + wp_clear_olduser_cookie(); + + wp_clear_auth_cookie(); + wp_set_auth_cookie( $user_id, $remember ); + wp_set_current_user( $user_id ); + + return true; +} +} + +/** + * Switches off the current logged in user. This logs the current user out while retaining a cookie allowing them to log straight + * back in using the 'Switch back to {user}' system. + * + * @return bool True on success, false on failure. + */ +if ( !function_exists( 'switch_off_user' ) ) { +function switch_off_user() { + if ( $current_user = wp_get_current_user() ) + $old_user_id = $current_user->ID; + else + return false; + + wp_set_olduser_cookie( $old_user_id ); + wp_clear_auth_cookie(); + + return true; +} +} + +$user_switching = new user_switching; + +?> \ No newline at end of file