• Resolved kazuyk

    (@kazuyk)


    I added the redirect_to parameter to the switch URL as described in the FAQ, but it doesn’t work.
    Whether I include the parameter or not, it redirects to home_url() or admin_url(). Are there any other required parameters or settings?

    if ( method_exists( 'user_switching', 'maybe_switch_url' ) ) {
    $url = user_switching::maybe_switch_url( $target_user );
    $my_page = 'slug_of_target_page';
    if ( $url ) {
    // Redirect to the home page after switching:
    $redirect_to = home_url( '/' ) . $my_page;
    printf(
    '<a href="%1$s">Switch to %2$s</a>',
    esc_url( add_query_arg(
    'redirect_to',
    rawurlencode( $redirect_to ),
    $url
    ) ),
    esc_html( $target_user->display_name )
    );
    }
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter kazuyk

    (@kazuyk)

    Ah, I figured out the cause.
    It was due to the callback I wrote for the login_redirect hook.
    Is there a way to distinguish whether it’s a pure login or a user switching?

    Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Cool.

    I think the best way is to check the value of $_REQUEST['action'], which will be switch_to_user when a user is switching, and switch_to_olduser when they’re switching back.

    Thread Starter kazuyk

    (@kazuyk)

    It works fine!
    Thank you!!

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.