Пример #1
0
 protected function user_name()
 {
     global $wpdb;
     if (!empty($this->fields['user_name'])) {
         return;
     }
     $user_name = filter_input(INPUT_POST, 'user_name', FILTER_SANITIZE_STRING);
     if (empty($user_name)) {
         $this->errors['user_name'] = SwpmUtils::_('Username is required');
         return;
     }
     if (!SwpmMemberUtils::is_valid_user_name($user_name)) {
         $this->errors['user_name'] = SwpmUtils::_('Username contains invalid character');
         return;
     }
     $saned = sanitize_text_field($user_name);
     $query = "SELECT count(member_id) FROM {$wpdb->prefix}swpm_members_tbl WHERE user_name= %s";
     $result = $wpdb->get_var($wpdb->prepare($query, strip_tags($saned)));
     if ($result > 0) {
         if ($saned != $this->fields['user_name']) {
             $this->errors['user_name'] = SwpmUtils::_('Username already exists.');
             return;
         }
     }
     $this->sanitized['user_name'] = $saned;
 }
Пример #2
0
 public static function validate_user_name_ajax()
 {
     global $wpdb;
     $field_value = filter_input(INPUT_GET, 'fieldValue');
     $field_id = filter_input(INPUT_GET, 'fieldId');
     if (!SwpmMemberUtils::is_valid_user_name($field_value)) {
         echo '[ "' . $field_id . '",false,"χ ' . SwpmUtils::_('Name contains invalid character') . '"]';
         exit;
     }
     $table = $wpdb->prefix . "swpm_members_tbl";
     $query = $wpdb->prepare("SELECT COUNT(*) FROM {$table} WHERE user_name = %s", $field_value);
     $exists = $wpdb->get_var($query) > 0;
     echo '[ "' . $field_id . ($exists ? '",false,"χ ' . SwpmUtils::_('Aready taken') . '"]' : '",true,"√ ' . SwpmUtils::_('Available') . '"]');
     exit;
 }