WebDevStudios / BuddyPress-Registration-Options

Moderate new BuddyPress members, fight BuddyPress spam, set BuddyPress Groups or Blogs/Sites new members can join on the registration page.
28 stars 16 forks source link

Duplicate Users appearing in Approval Window #174

Open jmarks0981 opened 5 years ago

jmarks0981 commented 5 years ago

Currently running 4.3.5 on WP 5.0.3 and when new users request approval, if the approval isn't accepted within a few minutes, it duplicates

tw2113 commented 5 years ago

What other BuddyPress plugins do you have installed, if any? It feels like possibly something is triggering user registration again, since we only act when those hooks fire.

jmarks0981 commented 5 years ago

I have BP Local Avatars, BP Registration Options, BuddyPress, BuddyPress Registration Widget

Registration is handled by a ninja form, but that has been the case for awhile now. When I look at the SQL command to pull in the users, it seems straight forward. Could there be an issue in how its displaying the users? Maybe there is a double loop somewhere?

From: Michael Beckwith notifications@github.com Sent: Friday, January 11, 2019 10:58 PM To: WebDevStudios/BuddyPress-Registration-Options BuddyPress-Registration-Options@noreply.github.com Cc: Jim Marks jim@marksemails.com; Author author@noreply.github.com Subject: Re: [WebDevStudios/BuddyPress-Registration-Options] Duplicate Users appearing in Approval Window (#174)

What other BuddyPress plugins do you have installed, if any? It feels like possibly something is triggering user registration again, since we only act when those hooks fire.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/WebDevStudios/BuddyPress-Registration-Options/issues/174#issuecomment-453717232, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AsdF-BjDI9tHQLYVIXz9GbBW1h6kFeWFks5vCV1LgaJpZM4Z8ZBU.

jmarks0981 commented 5 years ago

So, I've noticed that the _bprwg_is_moderated flag is being set to true twice on some users. I'm unsure where this is being set during the reg process. Is anyone able to quickly identify for me where this is set in the usermeta table? This seems to be what is being keyed on when the DB is being searched for when counting users.

tw2113 commented 5 years ago

Hmm.

I do see that I managed to get two calls to setting moderated status inside the bp_registration_options_bp_core_register_account() function, which runs on the user_register action hook. We use bp_registration_set_moderation_status() to set the user status. However, in that function, we delete, or should be deleting, all user meta related to "_bprwg_is_moderated".

My biggest question is if with your Ninja Form setup, they're running their own user_register action hook, that may be managing to get multiple entries in the usermeta table.

jmarks0981 commented 5 years ago

I think Ninja is doing their own user_register, but they wouldn't have any clue about the Registration Options piece, so it shouldn't call it as well, right? I could test turning the actual registration piece off, but I don't think at that point, it would actually create the user once the form is submitted.

Any possibility I could clean up the meta_key with a different function? Maybe looking for duplicates during the call to list the users?

tw2113 commented 5 years ago

Depends on how their things are set up. If they're matching user_register exactly, then it would be running at least twice because WordPress core uses that same hook name as well.

I don't have any functions handy right now that would search for all user IDs that have multiple entries for this meta key, so anything you can do up on your own would be about as quick as I could manage to get over to you as well.

If you're fine with doing any sort of SQL in say phpmyadmin or so, a query like this would get an idea of how many entries are present:

SELECT * from wp_usermeta where meta_key = '_bprwg_is_moderated'

It'd return every db row that has that meta key. Not sure how large your site is right now, user-wise.

For what it's worth, this is the first time I have heard of any issues for this, if anything in a really long time, so it doesn't feel like a widespread bug at the moment. I'm willing to be wrong though.

jmarks0981 commented 5 years ago

So, I ended up adding a DISTINCT identifier in the SQL.

function bp_registration_get_pending_users( $start_from = 0 ) { global $wpdb;

$sql = "
    SELECT DISTINCT u.ID AS user_id
    FROM {$wpdb->users} AS u
    INNER JOIN {$wpdb->usermeta} AS um
    WHERE u.ID = um.user_id
    AND um.meta_key = %s
    AND meta_value = %s
    ORDER BY u.user_registered
    LIMIT %d, 20";

I now only see 1 entry per user, and the count is correct as well.

tw2113 commented 5 years ago

setting your sql to distinct would remove duplicate entries in the returned results, but doesn't mean that they were removed from the database as a whole.

jmarks0981 commented 5 years ago

I wouldn’t disagree, but everything I’ve seen shows that it does clean up both entries and sets only 1 to false. I feel like this is probably the best answer at the current time.

Thanks.

From: Michael Beckwith notifications@github.com Sent: Monday, January 14, 2019 5:19 PM To: WebDevStudios/BuddyPress-Registration-Options BuddyPress-Registration-Options@noreply.github.com Cc: Jim Marks jim@marksemails.com; Author author@noreply.github.com Subject: Re: [WebDevStudios/BuddyPress-Registration-Options] Duplicate Users appearing in Approval Window (#174)

setting your sql to distinct would remove duplicate entries in the returned results, but doesn't mean that they were removed from the database as a whole.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/WebDevStudios/BuddyPress-Registration-Options/issues/174#issuecomment-454183142, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AsdF-MR1OZexuW74UjLoKmt4Fb1bj3Iqks5vDQJCgaJpZM4Z8ZBU.