• Resolved AWOL

    (@awol)


    Hi,
    I was just looking through the database in my site because of an error concerning email addresses in a php function (unrelated to Simple Membership), and noticed that after a certain member_id, the user_id has stopped matching, with the member_id being mostly 1 different from the user_id, with one user having a difference of 2. Is this normal or should they be the same always? I am concerned because (a) there might be a problem in my site, and (b) if I need to do anything that involves user_ids in my theme functions I won’t be able to use the Simple Membership methods for retrieving member_id and then using that as user_id. My setup includes Buddypress and I do need to use functions to retrieve user_id a lot, sometimes not for logged in users. The site is still being tested so there are only 13 users, but do you have any suggestions what is causing this, and how to fix it? I can obviously manually alter the database now, but once we go live that is not practical.

    P.S. I have just looked through the support forum on your site and there are a couple concerning this issue, but as they are from 7 years ago I wasn’t sure if they are still applicable. If they are, I guess I will have to write a function to add the member_id to the user_meta table when users register, and a temporary one to do the same for current users. Then I can reference the member_id in the user meta for any other functions that require it. However some other fix would be preferable!

    • This topic was modified 2 years, 5 months ago by AWOL.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support mbrsolution

    (@mbrsolution)

    Hi, the following explains how our plugin integrate with BuddyPress and WP User account.

    First go to WP Membership -> Settings -> Advanced Settings -> Create Member Account for New WP Users. This allows you to enable the following feature Enable Auto Create Member Accounts. This will allow the users signing up to WordPress / BuddyPress accounts to be added automatically to the members area in Simple Membership plugin.

    Also when a person registers as a Member in simple membership plugins area, they are also added as a WP User. Our plugin does not use the same ID as you mentioned above. The following forum post shares more light about this.

    https://www.ads-software.com/support/topic/function-to-create-membership-from-user-id/#post-15098685

    Let me know if the above helps you in any way.

    Thank you.

    Thread Starter AWOL

    (@awol)

    Hi @mbrsolution,
    Thanks for the reply – I already had that setting enabled but that clearly doesn’t always allocate matching ids, which I think might be caused by any users who are deleted, which has occurred on my site as we are in a testing phase, but would occur in live sites.

    I looked at the linked forum post and the API but that doesn’t seem to cover matching user_id and member_id, unless I am missing something? I am sure there are good reasons why your plugin doesn’t match the ids in some way, but it would be interesting to know why, as if it were possible I think most users of your plugin would expect this behaviour, rather than what actually happens – it certainly tripped me up when writing functions! If the behaviour can be changed in a future update I’m sure others would appreciate it, but without knowing exactly why it is hard to understand.

    I have now created a function, as I described above, that adds ‘member_id’ as a user meta which can then be referenced if need be – I already had two other functions that were using incorrect ids to do things on my site that couldn’t use ‘SwpmMemberUtils::get_logged_in_members_id()’ because it was for things outside of just the currently logged in user that required membership levels, so if I looped through users using the user_id it would give the wrong level in some cases.

    Plugin Support mbrsolution

    (@mbrsolution)

    Hi, I am glad you created a function for your needs. I was wondering if you would like to share the function here for others to use if they run into the same situation as yourself.

    Kind regards.

    Thread Starter AWOL

    (@awol)

    Hi @mbrsolution ,
    Sure, no problem. I actually created two functions; the first was to update all existing users with a new meta field, with the function only to be run once and then deleted (in the theme functions file, while the second is an ongoing function to add this meta field when users register. I should add that the second one has not been tested yet because my site is not open to the public yet, but the first one 100% works.
    FUNCTION 1

    //Temporary function to add member_id to user meta
    add_action ('init', 'add_member_id');
    function add_member_id(){
        $users = get_users();
        foreach ( $users as $user ) {
            $email = $user->user_email;
            $member = SwpmMemberUtils::get_user_by_email($email);
            $member_id = $member->member_id;
            update_user_meta( $user->ID, 'member_id', $member_id );
            }
    }

    FUNCTION 2

    //Put Simple Membership member_id in user meta table
    function set_member_id($member_info){
        $member_id = SwpmMemberUtils::get_logged_in_members_id();
        $field_name = 'email';
        $email = SwpmMemberUtils::get_member_field_by_id($member_id, $field_name);
        $user = get_user_by( 'email', $email );
        if ( metadata_exists( 'user', $user->ID, 'member_id' )){
        return;
        }
        else
            update_user_meta( $user->ID, 'member_id', $member_id );
    }
    add_action('swpm_front_end_registration_complete_user_data', 'set_member_id');

    I should add that I am not an expert in PHP coding so would not be at all surprised if others pick holes in what I have done and point out both errors and/or more concise ways of doing this! In fact, please do for both mine and others education. Hopefully someone else finds these useful though.

    Plugin Support mbrsolution

    (@mbrsolution)

    Thank you for sharing your solution. I am sure this will help or guide others with a similar issue as yourself.

    Kind regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘member_id not matching user_id’ is closed to new replies.