',
esc_attr( $lang_attr )
);
} else {
echo '
';
}
?>
display_name,
$user->user_login
) );
}
$switch_back_url = add_query_arg( array(
'redirect_to' => urlencode( self::current_url() ),
), self::switch_back_url( $old_user ) );
$message .= sprintf(
' %s.',
esc_url( $switch_back_url ),
esc_html( sprintf(
/* Translators: 1: user display name; 2: username; */
__( 'Switch back to %1$s (%2$s)', 'user-switching' ),
$old_user->display_name,
$old_user->user_login
) )
);
/**
* Filters the contents of the message that's displayed to switched users in the admin area.
*
* @since 1.1.0
*
* @param string $message The message displayed to the switched user.
* @param WP_User $user The current user object.
* @param WP_User $old_user The old user object.
* @param string $switch_back_url The switch back URL.
* @param bool $just_switched Whether the user made the switch on this page request.
*/
$message = apply_filters( 'user_switching_switched_message', $message, $user, $old_user, $switch_back_url, $just_switched );
echo wp_kses( $message, array(
'a' => array(
'href' => array(),
),
) );
?>
display_name,
$user->user_login
) );
} else {
echo esc_html( sprintf(
/* Translators: 1: user display name; 2: username; */
__( 'Switched to %1$s (%2$s).', 'user-switching' ),
$user->display_name,
$user->user_login
) );
}
?>
ID === $old_user_id );
}
}
return false;
}
/**
* Adds a 'Switch back to {user}' link to the account menu, and a `Switch To` link to the user edit menu.
*
* @param WP_Admin_Bar $wp_admin_bar The admin bar object.
*/
public function action_admin_bar_menu( WP_Admin_Bar $wp_admin_bar ) {
if ( ! is_admin_bar_showing() ) {
return;
}
if ( method_exists( $wp_admin_bar, 'get_node' ) ) {
if ( $wp_admin_bar->get_node( 'user-actions' ) ) {
$parent = 'user-actions';
} else {
return;
}
} elseif ( get_option( 'show_avatars' ) ) {
$parent = 'my-account-with-avatar';
} else {
$parent = 'my-account';
}
$old_user = self::get_old_user();
if ( $old_user ) {
$wp_admin_bar->add_node( array(
'parent' => $parent,
'id' => 'switch-back',
'title' => esc_html( sprintf(
/* Translators: 1: user display name; 2: username; */
__( 'Switch back to %1$s (%2$s)', 'user-switching' ),
$old_user->display_name,
$old_user->user_login
) ),
'href' => add_query_arg( array(
'redirect_to' => urlencode( self::current_url() ),
), self::switch_back_url( $old_user ) ),
) );
}
if ( current_user_can( 'switch_off' ) ) {
$url = self::switch_off_url( wp_get_current_user() );
if ( ! is_admin() ) {
$url = add_query_arg( array(
'redirect_to' => urlencode( self::current_url() ),
), $url );
}
$wp_admin_bar->add_node( array(
'parent' => $parent,
'id' => 'switch-off',
/* Translators: "switch off" means to temporarily log out */
'title' => esc_html__( 'Switch Off', 'user-switching' ),
'href' => $url,
) );
}
if ( ! is_admin() && is_author() && ( get_queried_object() instanceof WP_User ) ) {
if ( $old_user ) {
$wp_admin_bar->add_node( array(
'parent' => 'edit',
'id' => 'author-switch-back',
'title' => esc_html( sprintf(
/* Translators: 1: user display name; 2: username; */
__( 'Switch back to %1$s (%2$s)', 'user-switching' ),
$old_user->display_name,
$old_user->user_login
) ),
'href' => add_query_arg( array(
'redirect_to' => urlencode( self::current_url() ),
), self::switch_back_url( $old_user ) ),
) );
} elseif ( current_user_can( 'switch_to_user', get_queried_object_id() ) ) {
$wp_admin_bar->add_node( array(
'parent' => 'edit',
'id' => 'author-switch-to',
'title' => esc_html__( 'Switch To', 'user-switching' ),
'href' => add_query_arg( array(
'redirect_to' => urlencode( self::current_url() ),
), self::switch_to_url( get_queried_object() ) ),
) );
}
}
}
/**
* Adds a 'Switch back to {user}' link to the Meta sidebar widget.
*/
public function action_wp_meta() {
$old_user = self::get_old_user();
if ( $old_user instanceof WP_User ) {
$link = sprintf(
/* Translators: 1: user display name; 2: username; */
__( 'Switch back to %1$s (%2$s)', 'user-switching' ),
$old_user->display_name,
$old_user->user_login
);
$url = add_query_arg( array(
'redirect_to' => urlencode( self::current_url() ),
), self::switch_back_url( $old_user ) );
printf(
'