Shape the future of Social networking with WordPress: Join Project Midnight Sun! The next generation platform for community building with WordPress!

BuddyDev

Search

Replies

  • Participant
    Level: Guru
    Posts: 922
    Tosin on in reply to: [Resolved] Auto delete users by role and time #39414

    Reminder: Any update on this sir

    Thanks

  • Participant
    Level: Guru
    Posts: 922
    Tosin on in reply to: [Resolved] Auto delete users by role and time #39380

    Gentle reminder sir

    Thanks

  • Participant
    Level: Guru
    Posts: 922
    Tosin on in reply to: [Resolved] Auto delete users by role and time #39313

    Can you please help provide a safe solution to this. I would feel much safer with your own code.

    Thank you

  • Participant
    Level: Guru
    Posts: 922

    This worked perfectly

    Thank you very much Brajesh, thanks to you my site is now 90% complete im really grateful

  • Participant
    Level: Guru
    Posts: 922

    Hello Brajesh,

    I just found out why the code is not working, its conflicting with the other redirect code on first login. when I removed the redirect code it worked perfectly see code causing conflict.

     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 ) ) {
    		update_user_meta( $user->ID, '_buddydev_first_login', 1 );
    		// Redirect you custom page.
    		bp_core_redirect( bp_get_root_domain() . '/welcome/' );
    	} 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_get_root_domain() . '/publish/' );
    	}
    }
    
    add_action( 'wp_login', 'buddydev_redirect_on_first_login', -1, 2 ); 

    How can this conflict be prevented.

    Thanks

  • Participant
    Level: Guru
    Posts: 922

    Thank you Brajesh, I will be expecting your feedback.

  • Participant
    Level: Guru
    Posts: 922

    (active_member) is the new custom role I created using this plugin https://wordpress.org/plugins/members/

  • Participant
    Level: Guru
    Posts: 922

    I tried the code but it did not change newly registered role on first login to active_member, I also tried using the code below but it also did not work

    
     if ( empty( $last_activity ) ) {
    		$active_role = 'active_member';
    		$non_active_role = 'non_active_member';
    		$user->remove_role( $non_active_role );
    		$user->add_role( $active_role );
    	} 
    

    I don’t know if this has any relevance

    wp_update_user

  • Participant
    Level: Guru
    Posts: 922

    Gentle reminder

    Thanks

  • Participant
    Level: Guru
    Posts: 922

    Thank you brajesh

    Please can you check the rough code

    Also the code should not affect administrators (Admins should be excluded)

     /**
     * Change user role on first login
     *
     */
    function buddydev_change_user_role_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 ) ) {
    		
    		get_user_by('id', $user_id)->set_role('active member');
    		
    	} 
    }
    add_action( 'wp_login', 'buddydev_change_user_role_on_first_login', -1, 2 ); 

    Thanks