Update contact plugin so @ and . aren't removed from usernames.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 7 Aug 2018 18:41:28 +0000 (14:41 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 7 Aug 2018 18:41:28 +0000 (14:41 -0400)
Use sanitize_user to clean user name.

classes/data/dataContacts.php
models/admin/contacts/index.php
models/admin/import/contacts.php
models/admin/management/contacts.php

index be75079..7eb36e9 100644 (file)
@@ -566,7 +566,7 @@ class GlmDataContacts extends GlmDataAbstract
 
         // Clean up username for WorkPress (no punctuation other than _ and -
         if ($username != false) {
-            $username = preg_replace('/[^a-zA-Z0-9_-]+/', '', $username);
+            $username = sanitize_user( $username, true );
         }
 
         $r = array(
index aec75f0..5eea84b 100644 (file)
@@ -243,7 +243,7 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts
 
                 // Clean up username to be compatible with WordPress
                 if (isset($_REQUEST['username'])) {
-                    $_REQUEST['username'] = preg_replace('/[^a-zA-Z0-9_-]+/', '', $_REQUEST['username']);
+                    $_REQUEST['username'] = sanitize_user( $_REQUEST['username'], true );
                 }
 
                 // Check for existing contact in Wordpress and Contacts
index e45fa7a..608b5c1 100644 (file)
@@ -390,7 +390,7 @@ class GlmMembersAdmin_import_contacts extends GlmDataContacts
             // Get the contact data into standard parameters
             $oldMemberID        = ($c[0]-0);
             $memberName         = trim($c[1]);
-            $memberLogin        = trim($c[2]);//preg_replace('/[^a-zA-Z0-9_-.\\@]+/', '', trim($c[2]));
+            $memberLogin        = trim($c[2]);
             $memberPasswd       = trim($c[3]);
             $memberContactEmail = trim($c[4]);
             $contactFname       = trim($c[5]);
index 007c9c4..4189a02 100644 (file)
@@ -760,7 +760,7 @@ class GlmMembersAdmin_management_contacts extends GlmDataContacts
             $okToImport = true;
 
             // Clean up member login to remove restricted characters
-            $memberLogin = preg_replace('/[^a-zA-Z0-9_-]+/', '', $c['member_login']);
+            $memberLogin = sanitize_user( $c['member_login'], true );
             if ($memberLogin != $c['member_login']) {
 
                 // Report that we're stripping illegal characters from the username
@@ -859,19 +859,19 @@ class GlmMembersAdmin_management_contacts extends GlmDataContacts
                         $this->wpdb->insert(
                             GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . 'contacts',
                             array(
-                                'active' => true,
+                                'active'          => true,
                                 'primary_contact' => true,
-                                'access' => $this->config['access_numb']['NotDisplayedModerated'],
-                                'fname' => $c['primary_contact_fname'],
-                                'lname' => $c['primary_contact_lname'],
-                                'contact_type' => $contactType,
-                                'contact_role' => $contactRoleNumb,
-                                'email' => $c['process_email'],
-                                'username' => preg_replace('/[^a-zA-Z0-9_-]+/', '', $c['member_login']),
-                                'notes' => 'Imported from old Web site.',
-                                'create_time' => date('Y-m-d H:i:s', time()),
-                                'ref_type' => $this->config['ref_type_numb']['Member'],
-                                'ref_dest' => $memb['id']
+                                'access'          => $this->config['access_numb']['NotDisplayedModerated'],
+                                'fname'           => $c['primary_contact_fname'],
+                                'lname'           => $c['primary_contact_lname'],
+                                'contact_type'    => $contactType,
+                                'contact_role'    => $contactRoleNumb,
+                                'email'           => $c['process_email'],
+                                'username'        => $memberLogin,
+                                'notes'           => 'Imported from old Web site.',
+                                'create_time'     => date('Y-m-d H:i:s', time()),
+                                'ref_type'        => $this->config['ref_type_numb']['Member'],
+                                'ref_dest'        => $memb['id']
                             ),
                             array(
                                 '%d',
@@ -1025,7 +1025,7 @@ class GlmMembersAdmin_management_contacts extends GlmDataContacts
             // Get the contact data into standard parameters
             $oldMemberID = ($c[0]-0);
             $memberName = trim($c[1]);
-            $memberLogin = preg_replace('/[^a-zA-Z0-9_-]+/', '', trim($c[2]));
+            $memberLogin = sanitize_user( $c[2], true );
             $memberPasswd = trim($c[3]);
             $memberContactEmail = trim($c[4]);