The problems with just sending another email saying “you’re approved, don’t worry about activating” is that 1) we don’t actually know if that is a valid email [they could have a typo during reg, it could be a fake email made by a bot] 2) The user is not assigned the default role that wordpress settings give to new users [the problem i’m experiencing that initiated this thread] 3) The user is not ever removed from the “Pending” list of the user section.
Issue 2 seems like the biggest problem and I will try to clearly track the issue through the code:
In your admin.php file on line 274 you call:
bp_core_process_spammer_status( $user_id, 'ham' );
That function can be found https://github.com/buddypress/BuddyPress/blob/master/src/bp-members/bp-members-functions.php. On line 650 it uses ‘ham’ to set $is_spam:
$is_spam = ( 'spam' == $status );
So, it gets the value 0, then on line 680 updates the wp_users table:
$wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $user_id ) );
wp_users.user_status is now 0 and your user approval process finishes the rest of it’s code.
Then, the activation link in the email is used, eventually calling bp_core_activate_signup, which on line 1859 tries to update user_status to be 0:
if ( ! $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) ) ) {
Because user_status is already 0, no rows are updated and the query returns 0 and the function returns:
return new WP_Error( 'invalid_key', __( 'Invalid activation key.', 'buddypress' ) );
Therefore line 1981 is never called:
do_action( 'bp_core_activated_user', $user_id, $key, $user );
which has attached to it:
bp_members_add_role_after_activation
So the user is never given a site role.
That is where the activation process conflicts with your plugins approval process. I am not thoroughly acquainted with buddypress or your code, so I don’t know the best solution here without potentially breaking something else, but without investigating or testing it seems like there are a couple possible solutions:
1) You could attach your code to a hook at the end of the buddypress activation process so admins aren’t notified about a user needing moderation and the user won’t appear in the moderation list until they have activated their account. But this might allow users to use the site without being moderated yet.
2) Add a column on the approval UI that displays if the user is activated. I think this could be checked by seeing if their user id has the activation_key meta key set in wp_usermeta. I believe once a user activates this meta key is deleted. This doesn’t really solve the problem so much as allow a competent admin to not cause the problem.
3) You could call the buddypress activation functions when a user is moderated as approved before calling the bp_core_process_spammer_status function. This has the problem of approving well crafted spam users and users that entered the wrong email. Although, I have only ever encountered 1 spam user that was not obvious.
4) You could just not call bp_core_process_spammer_status( $user_id, ‘ham’ );. Unless there is somewhere else in your code that would specifically mark a user as spam until this is called I feel like removing this and letting the user be marked as ham when buddypress/wordpress normally would might be a very simple solution.
I hope this is helpful, and I don’t mind doing some more investigation or testing if you need additional information. This is an issue that is occurring for me very often, I assume because activation emails are going to spam or because much of my user base is older and doesn’t understand the importance of activation.
-
This reply was modified 5 years, 4 months ago by atmojones.
-
This reply was modified 5 years, 4 months ago by atmojones.
-
This reply was modified 5 years, 4 months ago by atmojones.