Example #1
0
/**
 * Handles registering a new user.
 *
 * @since 2.5.0
 *
 * @param string $user_login User's username for logging in
 * @param string $user_email User's email address to send password and add
 * @return int|WP_Error Either user's ID or error on failure.
 */
function register_new_user($user_login, $user_email, $display_name, $phone_number)
{
    $errors = new WP_Error();
    $sanitized_user_login = sanitize_user($user_login);
    /**
     * Filter the email address of a user being registered.
     *
     * @since 2.1.0
     *
     * @param string $user_email The email address of the new user.
     */
    $user_email = apply_filters('user_registration_email', $user_email);
    // Check the username
    if ($sanitized_user_login == '') {
        $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.'));
    } elseif (!validate_username($user_login)) {
        $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.'));
        $sanitized_user_login = '';
    } elseif (username_exists($sanitized_user_login)) {
        $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.'));
    }
    // Check the display name
    if ($display_name == '') {
        $errors->add('empty_display_name', __('<strong>ERROR</strong>: Please enter your Name.'));
    }
    // Check the phone number
    if ($phone_number == '') {
        $errors->add('empty_phone_number', __('<strong>ERROR</strong>: Please enter your phone number.'));
    } elseif (!validate_phone_number($phone_number)) {
        $errors->add('invalid_phone_number', __('<strong>ERROR</strong>: Please enter valid phone number.'));
    }
    // Check the e-mail address
    if ($user_email == '') {
        $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.'));
    } elseif (!is_email($user_email)) {
        $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn&#8217;t correct.'));
        $user_email = '';
    } elseif (email_exists($user_email)) {
        $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'));
    }
    /**
     * Fires when submitting registration form data, before the user is created.
     *
     * @since 2.1.0
     *
     * @param string   $sanitized_user_login The submitted username after being sanitized.
     * @param string   $user_email           The submitted email.
     * @param WP_Error $errors               Contains any errors with submitted username and email,
     *                                       e.g., an empty field, an invalid username or email,
     *                                       or an existing username or email.
     */
    do_action('register_post', $sanitized_user_login, $user_email, $display_name, $phone_number, $errors);
    /**
     * Filter the errors encountered when a new user is being registered.
     *
     * The filtered WP_Error object may, for example, contain errors for an invalid
     * or existing username or email address. A WP_Error object should always returned,
     * but may or may not contain errors.
     *
     * If any errors are present in $errors, this will abort the user's registration.
     *
     * @since 2.1.0
     *
     * @param WP_Error $errors               A WP_Error object containing any errors encountered
     *                                       during registration.
     * @param string   $sanitized_user_login User's username after it has been sanitized.
     * @param string   $user_email           User's email.
     */
    $errors = apply_filters('registration_errors', $errors, $sanitized_user_login, $user_email, $display_name, $phone_number);
    if ($errors->get_error_code()) {
        return $errors;
    }
    $user_pass = wp_generate_password(12, false);
    $user_id = wp_create_user($sanitized_user_login, $user_pass, $user_email, $display_name, $phone_number);
    if (!$user_id || is_wp_error($user_id)) {
        $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you&hellip; please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email')));
        return $errors;
    }
    update_user_option($user_id, 'default_password_nag', true, true);
    //Set up the Password change nag.
    wp_new_user_notification($user_id, null, 'both');
    return $user_id;
}
    // one but not the other we do $city $state, which will either become
    // "$city[space]" or "[space]$state" Then we tack on country if we have
    // it. So we'll either have
    // "$city, $state $country"
    // "$city[space][space]"
    // "$city[space]$country]"
    // "$city, $state[space]"
    // ...and all the other permutations.
    // Finally we do a trim to take off any of the extra spaces on the ends
    // that might be there from not having a piece of information.
    if (strlen($call_city) > 0 && strlen($call_state) > 0) {
        $call_location = $call_city . ', ' . $call_state;
    } else {
        $call_location = $call_city . ' ' . $call_state;
    }
    $call_location = trim($call_location . ' ' . $call_country);
    if (validate_phone_number($from) && isset($call_sid)) {
        $query = 'INSERT INTO ' . DB::$calls . ' (' . DB::$calls_incoming_twilio_sid . ', ' . DB::$calls_from . ', ' . DB::$calls_location . ') VALUES (' . DB::clean($call_sid, $db) . ', ' . DB::clean($from, $db) . ', ' . DB::clean($call_location, $db) . ')';
        $db->Execute($query);
        $call_id = $db->Insert_ID();
        if (SHOW_CALLER) {
            $caller_id = $from;
        } else {
            $caller_id = SUPPORT_NUMBER;
        }
        echo '<Dial action="' . $base_url . 'handle_call_status.php?call_id=' . $call_id . '" callerId="' . $caller_id . '" method="GET">' . FORWARD_TO_NUMBER . '</Dial>';
    }
} catch (ADODB_Exception $e) {
    echo '<Say voice="woman">' . ERROR_RESPONSE . '</Say>';
}
echo '</Response>';