/**
  * Validate username field.
  *
  * @access public
  * @since 1.0.0
  * @return void
  */
 public static function validate_username($passed, $fields, $values)
 {
     $nickname = $values['register']['username'];
     if (wpum_get_option('exclude_usernames') && array_key_exists($nickname, wpum_get_disabled_usernames())) {
         return new WP_Error('nickname-validation-error', __('This nickname cannot be used.', 'wpum'));
     }
     // Check for nicknames if permalink structure requires unique nicknames.
     if (get_option('wpum_permalink') == 'nickname') {
         $current_user = wp_get_current_user();
         if ($username !== $current_user->user_nicename && wpum_nickname_exists($username)) {
             return new WP_Error('username-validation-error', __('This nickname cannot be used.', 'wpum'));
         }
     }
     return $passed;
 }
Exemplo n.º 2
0
/**
 * Given $user_data checks against $method_type if the user exists.
 *
 * @since 1.0.0
 * @param string  $user_data   Either ID/Username/Nickname
 * @param string  $method_type Either user_id/username/nickname - usually retrieve thorugh get_option('wpum_permalink')
 * @return bool
 */
function wpum_user_exists($user_data, $method_type)
{
    $exists = false;
    // Check if user exists by ID
    if (!empty($user_data) && $method_type == 'user_id' && get_user_by('id', intval($user_data))) {
        $exists = true;
    }
    // Check if user exists by username
    if (!empty($user_data) && $method_type == 'username' && get_user_by('login', esc_attr($user_data))) {
        $exists = true;
    }
    // Check if user exists by nickname
    if (!empty($user_data) && $method_type == 'nickname' && wpum_nickname_exists($user_data)) {
        $exists = true;
    }
    return $exists;
}