• Kyle

    (@kylebravotangoca)


    Users are no longer being assigned a role. I’m not sure the exact date this started happening but it appears to be happening for the last 2 months.

    Once a user is approved the role says:
    – No role for this site –

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • I ended up writing custom code to get around this. Tweak as needed:

    add_action( 'bp_core_activated_user', 'auto_add_user_to_bp_and_bbpress_roles' );
    function auto_add_user_to_bp_and_bbpress_roles( $user_id ) {
        $user = new WP_User( $user_id );
        // Check if the user has one of the roles to ignore
        $roles_to_ignore = array('administrator', 'buddypress_admin', 'system_admin', 'buddypress_moderator');
        if (array_intersect($roles_to_ignore, $user->roles)) {
            // Do not update the fields for users with one of the roles to ignore
            return;
        }
    	$user->set_role( 'bbp_participant' );
    	$user->add_role('subscriber');
        $member_type = 'members';
        bp_set_member_type( $user_id, $member_type );
    }
    add_action('wp_login', 'my_first_login_function', 10, 2);
    function my_first_login_function($user_login, $user) {
        // Check if it is the user's first login
        $first_login = get_user_meta($user->ID, 'my_first_login', true);
        if (!$first_login) {
            // Run your code here
            auto_add_user_to_bp_and_bbpress_roles($user->ID);
          // Update the user meta to indicate that the user has logged in for the first time
            update_user_meta($user->ID, 'my_first_login', true);
        }
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Roles are not being assigned to approved users’ is closed to new replies.