• Resolved utentone

    (@utentone)


    Hi, im using this code from your faq to display a switch back to admin link on front end:

    if ( method_exists( 'user_switching', 'get_old_user' ) ) {
        $old_user = user_switching::get_old_user();
        if ( $old_user ) {
            printf(
                '<a href="%1$s">Switch back to %2$s</a>',
                esc_url( user_switching::switch_back_url( $old_user ) ),
                esc_html( $old_user->display_name )
            );
        }
    }

    But this redirect also to user page on backend is it possible istead to only reload the page? thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Yes you can do this by adding a redirect_to parameter which contains the URL you want to redirect to. User Switching includes a method for fetching the current URL that you can use. For example:

    if ( method_exists( 'user_switching', 'get_old_user' ) ) {
        $old_user = user_switching::get_old_user();
        if ( $old_user ) {
            $redirect_to = user_switching::current_url();
            $url = add_query_arg( 'redirect_to', rawurlencode( $redirect_to ), user_switching::switch_back_url( $old_user ) );
            printf(
                '<a href="%1$s">Switch back to %2$s</a>',
                esc_url( $url ),
                esc_html( $old_user->display_name )
            );
        }
    }
    Thread Starter utentone

    (@utentone)

    thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Switch back to admin reload page’ is closed to new replies.