Title: Allow same number from multiple wp users
Last modified: September 8, 2023

---

# Allow same number from multiple wp users

 *  [snas35](https://wordpress.org/support/users/snas35/)
 * (@snas35)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/allow-same-number-from-multiple-wp-users/)
 * Hi,
 * I have 2 people that have the same telephone number. When I create the 2 users
   on WordPress and I put the same number on registration, WordPress not allow me
   to complete the registration and inform me on the second registration that this
   number is linked to another user. Is any way to skip this checking and allowing
   multiple users with the same telephone number?
 * Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [snas35](https://wordpress.org/support/users/snas35/)
 * (@snas35)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/allow-same-number-from-multiple-wp-users/#post-17042403)
 * Any trick?
 *  Plugin Author [Mostafa Soufi](https://wordpress.org/support/users/mostafas1990/)
 * (@mostafas1990)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/allow-same-number-from-multiple-wp-users/#post-17042540)
 * Hey,
 * Since there is no filter on the validation, the only way is to modify the handler.
   here is an example (but I haven’t tested it)
 *     ```wp-block-code
       add_action('wp_sms_mobile_filed_handler', function ($handlers) {
           $handlers['add_mobile_field_in_profile'] = CustomWordPressMobileFieldHandler::class;
   
           return $handlers;
       });
   
       use WP_SMS\Helper;
       use WP_SMS\Option;
   
       class CustomWordPressMobileFieldHandler
       {
           public function register()
           {
               add_action('user_new_form', array($this, 'add_mobile_field_to_newuser_form'));
               add_filter('wp_sms_user_profile_fields', array($this, 'add_mobile_field_to_profile_form'), 10, 2);
   
               add_action('register_form', array($this, 'add_mobile_field_to_register_form'));
               add_filter('registration_errors', array($this, 'frontend_registration_errors'), 10, 3);
   
               add_action('user_profile_update_errors', array($this, 'admin_registration_errors'), 10, 3);
   
               add_action('user_register', array($this, 'updateMobileNumberCallback'), 999999);
               add_action('profile_update', array($this, 'updateMobileNumberCallback'));
           }
   
           public function getMobileNumberByUserId($userId)
           {
               $mobileNumber = get_user_meta($userId, $this->getUserMobileFieldName(), true);
               return apply_filters('wp_sms_user_mobile_number', $mobileNumber, $userId);
           }
   
           public function getUserMobileFieldName()
           {
               return apply_filters('wp_sms_user_mobile_field', 'mobile');
           }
   
           // add mobile field input to add user admin page
           public function add_mobile_field_to_newuser_form()
           {
               echo Helper::loadTemplate('mobile-field.php');
           }
   
           /**
            * @param $fields
            * @param $userId
            * @return mixed
            */
           public function add_mobile_field_to_profile_form($fields, $userId)
           {
               $currentValue = Helper::getUserMobileNumberByUserId($userId);
   
               $fields['mobile'] = [
                   'id' => 'mobile',
                   'title' => __('Mobile', 'wp-sms'),
                   'content' => '<input class="wp-sms-input-mobile regular-text ltr" type="text" name="mobile" value="' . esc_attr($currentValue) . '">'
               ];
   
               return $fields;
           }
   
           // add mobile filed input to add user in front-end
           public function add_mobile_field_to_register_form()
           {
               $mobile = (isset($_POST['mobile'])) ? Helper::sanitizeMobileNumber($_POST['mobile']) : '';
   
               echo Helper::loadTemplate('mobile-field-register.php', array(
                   'mobile' => $mobile
               ));
           }
   
           /**
            * Handle errors for registration through the front-end WordPress login form
            *
            * @param $errors
            * @param $sanitized_user_login
            * @param $user_email
            *
            * @return mixed
            */
           public function frontend_registration_errors($errors, $sanitized_user_login, $user_email)
           {
               $mobile_number = isset($_POST['mobile']) ? $_POST['mobile'] : (isset($_POST['phone_number']) ? $_POST['phone_number'] : null);
               if (Option::getOption('optional_mobile_field', false) !== 'optional' && !$mobile_number) {
                   $errors->add('mobile_number_error', __('<strong>ERROR</strong>: You must enter the mobile number.', 'wp-sms'));
               }
   
               if ($mobile_number) {
                   $mobile = Helper::sanitizeMobileNumber($mobile_number);
                   $validity = Helper::checkMobileNumberValidity($mobile);
   
                   if (is_wp_error($validity)) {
                       $errors->add($validity->get_error_code(), $validity->get_error_message());
                   }
               }
   
               return $errors;
           }
   
           /**
            * save user mobile number in database
            *
            * @param $user_id
            */
           public function updateMobileNumberCallback($user_id)
           {
               $mobile_number = isset($_POST['mobile']) ? $_POST['mobile'] : null;
               if ($mobile_number) {
                   $mobile = Helper::sanitizeMobileNumber($mobile_number);
                   update_user_meta($user_id, $this->getUserMobileFieldName(), $mobile);
               }
           }
   
           /**
            * Handle the mobile field update errors
            *
            * @param $errors
            * @param $update
            * @param $user
            *
            * @return void|\WP_Error
            */
           public function admin_registration_errors($errors, $update, $user)
           {
               if (Option::getOption('optional_mobile_field') !== 'optional' && empty($_POST['mobile'])) {
                   $errors->add('mobile_number_error', __('<strong>ERROR</strong>: You must enter the mobile number.', 'wp-sms'));
               }
   
               /*if (isset($_POST['mobile']) && $_POST['mobile']) {
                   $mobile = Helper::sanitizeMobileNumber($_POST['mobile']);
                   $validity = Helper::checkMobileNumberValidity($mobile, isset($user->ID) ? $user->ID : false);
   
                   if (is_wp_error($validity)) {
                       $errors->add($validity->get_error_code(), $validity->get_error_message());
                   }
               }*/
   
               return $errors;
           }
       }
       ```
   
 *  Thread Starter [snas35](https://wordpress.org/support/users/snas35/)
 * (@snas35)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/allow-same-number-from-multiple-wp-users/#post-17042611)
 * I just tried it, it doesn’t work, unless I need to modify something in the code.
   I didn’t change anything in the code.
 * I tried it on functions.php file.
 *  Plugin Author [Mostafa Soufi](https://wordpress.org/support/users/mostafas1990/)
 * (@mostafas1990)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/allow-same-number-from-multiple-wp-users/#post-17051584)
 * I tested and worked fine, no validation for duplicate numbers in admin → edit
   profile users.
 * Please make sure this option is set to [https://capture.dropbox.com/aFmGniiTFRKJqoa8](https://capture.dropbox.com/aFmGniiTFRKJqoa8)
 *  Thread Starter [snas35](https://wordpress.org/support/users/snas35/)
 * (@snas35)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/allow-same-number-from-multiple-wp-users/#post-17051728)
 * I try it again. No works. I have enabled the mobile field option on WP-SMS settings.
   I put code on functions.php on theme folder. I try to make a second user with
   the same mobile of one existing user and show me the error message that a another
   user has this mobile. I also try to add a random number and later to edit this
   number on User->Profile, set the same number (of a existing user) and I have 
   the same error that a another user use this phone.
 *  Plugin Author [Mostafa Soufi](https://wordpress.org/support/users/mostafas1990/)
 * (@mostafas1990)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/allow-same-number-from-multiple-wp-users/#post-17055598)
 * I think the new handler is not working, please put some logs into the actions
   to make sure that the handler is working fine.
 * As you can see, the function **Helper::checkMobileNumberValidity** which is responsible
   to check the number validity, is commented on the example.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Allow same number from multiple wp users’ is closed to new replies.

 * ![](https://ps.w.org/wp-sms/assets/icon.svg?rev=3477319)
 * [WSMS (formerly WP SMS) – SMS & MMS Notifications with OTP and 2FA for WooCommerce](https://wordpress.org/plugins/wp-sms/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-sms/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-sms/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-sms/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-sms/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-sms/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [Mostafa Soufi](https://wordpress.org/support/users/mostafas1990/)
 * Last activity: [2 years, 8 months ago](https://wordpress.org/support/topic/allow-same-number-from-multiple-wp-users/#post-17055598)
 * Status: not resolved