• Resolved waley168

    (@waley168)


    It’s a perfect plugin, but I have an odd question.

    I have an order management system for a manager to create an order and meanwhile create the customer connected to this order by shop-as-client.

    There is only billing_phone in customer’s data because we don’t ask for email.

    I use nsl_registration_require_extra_input to ensure a new registration of member having a billing_phone data.

    Therefore, there is no email to automatically connect the existing account upon registration. How to connect the existing account upon registration by phone numbers(billing_phone)?

    	if ( $users = get_users( array(
    		'meta_key'     => 'billing_phone',
    		'meta_value'   => $userData['billing_phone'],
    		'meta_compare' => '='
    	))) {
    		$user_id = $users[0]->ID;
    		add_filter('nsl_line_link_user', function ($user_id) {
    		}, 10, 2);
    

    Which filter or action can I use for this situation?
    Thanks a lot

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Laszlo

    (@laszloszalvak)

    Hi @waley168

    About linking by phone numbers in general:
    We don’t have such feature, but if you will do that with custom coding, then have you also implemented some sort of Phone number validation logic? If you haven’t then you shouldn’t implement the linking either, since that way people can enter the phone number of somebody else, and if there is an account with that phone number then you would basically link social media accounts to the WordPress account of somebody else, meaning that you would allow people to abuse the accounts of others.

    As for your usecase:
    Please note that we can not provide support for custom coding, but I will try to give you some tips that will hopefully help you in achieving your goals.
    The first thing that you need to know is that, if you ended up in our registration flow, then it is already a registration action, so you can not link the account to another one, as we will try to create a new account and link the social media account to that. The best, you can do is preventing this registration with an error message, over the “nsl_registration_user_data” filter:

    and at the same time link the account to the existing one if you managed to find one.
    Your error message should inform the user about what has happened exactly, and if the link was successful, then the next time the person tries to login with social login they would login to the linked WordPress account.

    About the linking process:
    On the provider instance we have a function that you can call to link a WordPress User ID to a Social Media account:
    $provider->linkUserToProviderIdentifier($wordpress_user_id, $socialID);

    You can get the $wordpress_user_id from the function parameters of some actions/filters, or if you link the account after the login, then you can get the user ID of the current logged in user e.g. with get_current_user_id() – https://developer.wordpress.org/reference/functions/get_current_user_id/

    And you during our flow, you could get the $socialID also from the $provider instance, like:
    $provider->getAuthUserData('id');

    The ‘nsl_{{provider-id}}_link_user’ filter has a different purpose, and its functuonality is rather connected to the Pro version, that we can not discuss on this forum, as per the forum guidelines:

    So if you would like to know more about that, or if you have further questions connected to Pro Addon features, then please get in touch with us rather over the ticket system.

    Best regards,
    Laszlo.

    Thread Starter waley168

    (@waley168)

    I appreciate your elaborate answer.

    I made an arrangement:

    
    add_filter('nsl_registration_user_data', function($userData, $provider){
    	if (isset($userData['billing_phone']) && !empty($userData['billing_phone'])) {
    		if ( $users = get_users( array(
    		'meta_key'     => 'billing_phone',
    		'meta_value'   => $userData['billing_phone'],
    		'meta_compare' => '='
    		))) {
    			$user_id = $users[0]->ID;
    			$socialID = $provider->getAuthUserData('id');
    		}
            if (!empty($user_id)) {
    		    $provider->linkUserToProviderIdentifier($user_id, $socialID);
    			$userData['username']=$provider->getAuthUserData('first_name').'-'.$provider->getAuthUserData('last_name');
                return $user_data;
            }
        }
        return $userData;
    },10,2);
    

    It works in the condition of some session remaining but I don’t get it.
    I guess there is a wrong sequence in use of filter.

    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @waley168

    In your code there is no validation logic for the phone number, so you shouldn’t implement this linking at all, since as I mentioned above without validation you are basically allowing everybody to enter random phone numbers and they will be able to link their social media accounts to the WordPress account of somebody else.

    Also please note that, as I mentioned above, we can not provide support for custom coding and problems caused by custom codes. But in your code I see two problems:

    1. In the condition, you return an undefined variable: $user_data
    2. As I mentioned above, if you get to this point, we will already try to register a new account and we will link the social media account to the registered account. If you also link this social media account to another account by doing custom coding then you can end up creating links to two WordPress accounts. Like I described above, the best you can do is preventing the registration by adding an error in to the $errors parameter like you saw in the documentation: https://nextendweb.com/nextend-social-login-docs/backend-developer/#prevent-registration – that will stop the entire flow and will display your error message. If you linked the social media account to the WordPress account, then the next time the person tries to login the user will be already linked to the WordPress account so we will log the user in to that account.

    Best regards,
    Laszlo.

    Thread Starter waley168

    (@waley168)

    Hi @laszloszalvak

    Thanks for your warning, I would use OTP for verification.

    I have a general idea of how it works, thanks for the detailed explanation.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to connect the existing account upon registration by phone numbers’ is closed to new replies.