redirects after logging in
-
I want to avoid users ever going to the wp-admin/profile.php page, which seems to be the WordPress default after login. I have a shortcode block that, for unlogged users, tracks their current URL (on pages with the shortcode) and redirects them back to that page after login. It works great:
function fp_logged_in() { if ( is_user_logged_in() ) { $current_user = wp_get_current_user(); $displayname = $current_user->display_name; $text = 'Logged in as <b>' . $displayname . '</b><br \><a href="' . home_url() . '/edit-profile/">Edit or Delete Profile</a><br \><a href="' . wp_logout_url() . ' ">Log Out</a>'; } else { global $wp; $current_url = home_url( add_query_arg( array(), $wp->request ) ); $URL = esc_url( wp_login_url( $current_url ) ); $text = '<p style="font-size:x-small;">Registration is needed only to post in the fora and blog.</p><a href="' . $URL . '">Login</a><br \><a href="' . wp_registration_url() . ' ">Register</a>'; } return $text; } add_shortcode( 'fp_user_stuff', 'fp_logged_in' );
The problem is new users. After going through the register/confirm/password/login process, since they didn’t go through the shortcode, they still get sent to the backend. I tried this to redirect Subscribers to the home page, but for some reason, it causes authentication failure when logging in
add_action('admin_init', 'fp_redirect'); function fp_redirect() { if( !current_user_can('edit_posts') ) wp_redirect(home_url()); }
How can I keep the page-specific redirect in the shortcode, but still direct new users to the home page after their registration/login process?
- The topic ‘redirects after logging in’ is closed to new replies.