Hello,
1. How can I make the redirect of this code to take priority over the redirect of buddypress profile completion plugin.
function buddydev_redirect_on_first_login( $redirect_to, $redirect_url_specified, $user ) { //check if we have a valid user? if ( is_wp_error( $user ) ) { return $redirect_to; } //check for user's last activity $last_activity = bp_get_user_last_activity( $user->ID ); if ( empty( $last_activity ) ) { //it is the first login //update redirect url //I am redirecting to user's profile here //you may change it to anything $redirect_to = bp_core_get_user_domain($user->ID ); } return $redirect_to; } add_filter( 'login_redirect', 'buddydev_redirect_on_first_login', 110, 3 );
2. I want the code to redirct to custom page (welcome) instead of user profile
Hello Tosin,
Thank you for posting. Please give it try to the following code.
/** * On first login * * @param string $user_login User login. * @param WP_User $user User object. * */ function buddydev_redirect_on_first_login( $user_login, $user ) { if ( ! function_exists( 'buddypress' ) ) { return; } // check for user's last activity. $last_activity = bp_get_user_last_activity( $user->ID ); if ( empty( $last_activity ) ) { // Redirect you custom page. bp_core_redirect( bp_loggedin_user_domain() ); } } add_action( 'wp_login', 'buddydev_redirect_on_first_login', -1, 2 );
Let me know if it works or not.
Regards
RaviHello Tosin,
Thank you for the acknowledgment. Please modify the following section.
if ( empty( $last_activity ) ) { // Redirect you custom page. bp_core_redirect( bp_loggedin_user_domain() ); }
with the following.
if ( empty( $last_activity ) ) { update_user_meta( $user->ID, '_buddydev_first_login', 1 ); // Redirect you custom page. bp_core_redirect( bp_loggedin_user_domain() ); } elseif ( get_user_meta( $user->ID, '_buddydev_first_login', true ) ) { delete_user_meta( $user->ID, '_buddydev_first_login' ); // Try second login here. bp_core_redirect( bp_loggedin_user_domain() ); }
Regards
Ravi
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic.
This topic is: resolved