• Resolved rtcunningham

    (@rtcunningham)


    I’m using one admin account for login only and then switching after login. It works perfectly, but it’s a few steps every time I log in that I’d love to bypass. And then I have to *remember* to switch or it’s another couple of steps to reassign the last post.

    It would be great if this could be done automatically somehow. Any ideas?

    https://wordpress.org/plugins/user-switching/

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

    (@johnbillion)

    WordPress Core Developer

    You’d have to write some code for it, but you could do something on the wp_login action to immediately switch user. Maybe something along the lines of this completely untested code, where 1 is your admin user ID and 2 is your editor user ID.

    add_action( 'wp_login', function( $user_login, WP_User $user ) {
        if ( 1 == $user->ID ) {
            switch_to_user( 2, true );
        }
    }, 10, 2 );
    Thread Starter rtcunningham

    (@rtcunningham)

    Thanks for trying, but your code doesn’t do anything at all (I just reversed 1 and 2). Oh well…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to do it automatically?’ is closed to new replies.