• Resolved Graham

    (@sandgroper)


    I see this topic has been raised before, but the fixes are a bit technical for me to understand.

    I have BuddyPress installed and custom capabilities setup. But I don’t think that is what is causing my concern.

    When I switch to a user that does not have the ability to list users (subscriber), I get the cheating message and am sent to:

    /wp-admin/users.php?user_switched=true

    Backspacing to /wp-admin/ shows me the switch did work.

    If the user is given listing capability, everything works fine, but of course you don’t want that.

    So my question is, is there a filter I can use in my child functions.php file to change the page the admin gets sent to, to /wp-admin/ or /wp-admin/index.php or “admin(URL)” instead?

    This seems the most logical thing to do.

    Thanks in advance.

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

    (@johnbillion)

    WordPress Core Developer

    I’ll take a look at see why that incorrect redirect is happening in the first place.

    You can use the filters here to control the redirect location: https://github.com/johnbillion/user-switching/blob/28b8034c5a30c30188404966632c13d582bcd9b1/user-switching.php#L263-L289 but bear in mind that these are the same filters used by WordPress core when any user logs in or logs out, not just when a user switches to another account.

    John

    Thread Starter Graham

    (@sandgroper)

    Yes, I did see that before, but I’m not smart enough to understand it. I’m a monkey-see-monkey-do level code destroyer.

    That’s why I was hoping for a pre-packaged filter for dummies, that I can simply add to my functions file.

    One bracket or semi-colon wrong and I can bring my site to a crashing halt in one foul swoop.

    Thread Starter Graham

    (@sandgroper)

    I see around line 166 you have this:

    # Redirect to the dashboard or the home URL depending on capabilities:
    					$args = array( 'user_switched' => 'true' );
    					if ( $redirect_to ) {
    						wp_safe_redirect( add_query_arg( $args, $redirect_to ) );
    					} else if ( ! current_user_can( 'read' ) ) {
    						wp_redirect( add_query_arg( $args, home_url() ) );
    					} else {
    						wp_redirect( add_query_arg( $args, admin_url() ) );
    					}

    Why does it need to ask if the user can read? Is that the question that causes the wrong redirect?

    Just guessing.

    Thread Starter Graham

    (@sandgroper)

    Disregard my last suggestion. I installed your plugin and capability manager on one of my standard WordPress sites and the problem didn’t occur. All users have the “Read” box ticked by default.

    It seems BuddyPress is probably introducing the error. Maybe the extended profile fields or it is hijacking something else.

    All I do know for sure is, giving the user the ability to list users, fixes the error. Hope that helps you narrow it down.

    Thread Starter Graham

    (@sandgroper)

    @johnbillion

    Thought I’d just update you on what I’ve found.

    I had been going to the All Users page and clicking on Switch-To. I have since found that while in the user’s actual profile, switching works fine.

    It also works correctly when used in the BuddyPress pages themselves.

    So it is only in the first case that I get the invalid redirect. That doesn’t happen until I install BuddyPress. A normal WP installation works.

    So there is no real problem to worry about.

    Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Thanks for the updates! I’ll take a look and see what I can find.

    Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Okay this looks like a side effect or bug caused by BuddyPress being active on the site. BuddyPress overrides the redirect destination when you log in and sends you back to the page you were on. If you’re on a page which the user you’re switching to cannot access, then you’ll get the Cheatin’ uh? error.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Redirect to Admin URL’ is closed to new replies.