/**
 * Validates a new or prospective WordPress user in phpBB
 * @param string $username username
 * @param string $email e-mail
 * @param WP_Error $errors WordPress error object
 * @return bool|WP_Error false (on success) or modified WP_Error object (on failure)
 */
function wpu_validate_new_user($username, $email, $errors)
{
    global $phpbbForum;
    $foundErrors = 0;
    if (function_exists('phpbb_validate_username')) {
        $fStateChanged = $phpbbForum->foreground();
        $result = phpbb_validate_username($username, false);
        $emailResult = validate_email($email);
        $phpbbForum->restore_state($fStateChanged);
        if ($result !== false) {
            switch ($result) {
                case 'INVALID_CHARS':
                    $errors->add('phpbb_invalid_chars', __('The username contains invalid characters', 'wp-united'));
                    $foundErrors++;
                    break;
                case 'USERNAME_TAKEN':
                    $errors->add('phpbb_username_taken', __('The username is already taken', 'wp-united'));
                    $foundErrors++;
                    break;
                case 'USERNAME_DISALLOWED':
                default:
                    $errors->add('phpbb_username_disallowed', __('The username you chose is not allowed', 'wp-united'));
                    $foundErrors++;
                    break;
            }
        }
        if ($emailResult !== false) {
            switch ($emailResult) {
                case 'DOMAIN_NO_MX_RECORD':
                    $errors->add('phpbb_invalid_email_mx', __('The email address does not appear to exist (No MX record)', 'wp-united'));
                    $foundErrors++;
                    break;
                case 'EMAIL_BANNED':
                    $errors->add('phpbb_email_banned', __('The e-mail address is banned', 'wp-united'));
                    $foundErrors++;
                    break;
                case 'EMAIL_TAKEN':
                    $errors->add('phpbb_email_taken', __('The e-mail address is already taken', 'wp-united'));
                    break;
                case 'EMAIL_INVALID':
                default:
                    $errors->add('phpbb_invalid_email', __('The email address is invalid', 'wp-united'));
                    $foundErrors++;
                    break;
            }
        }
    }
    return $foundErrors ? $errors : false;
}
Beispiel #2
0
 /**
  * TODO: Under consideration for future rewrite: Function 'validate_username_conflict()' - Handles the conflict between validate_username
  * in WP & phpBB. This is only really a problem in integrated pages when naughty WordPress plugins pull in
  * registration.php. 
  * 
  * These functions should NOT collide in usage -- only in namespace. If user integration is turned on, we don't need
  * WP's validate_username. 
  * 
  * Furthermore, if phpbb_validate_username is defined, then we know we most likely need to use the phpBB version.
  * 
  * We unfortunately cannot control their usage -- phpbb expects 2 arguments, whereas WordPress only expects one.
  * Therefore here we just try to avoid namespace errors. 
  * If they are actually invoked while renamed, the result is undefined and things could spontaneously ignite.
  *
  * @param string $wpValidUser the validated WP username
  * @param string $username the original WP username
  * @return string hopefully something nice
  */
 public function validate_username_conflict($wpValdUser, $username)
 {
     global $phpbbForum;
     if ($phpbbForum->get_state() == 'phpbb') {
         if (function_exists('phpbb_validate_username')) {
             return phpbb_validate_username($username, false);
         }
     }
     return $wpValdUser;
 }