429) ); } if ($name === '' || $email === '') { return new WP_Error( 'rapidchat_invalid_input', __('Please enter a valid name and email address!', 'rapidchat'), array('status' => 422) ); } if (!is_email($email)) { return new WP_Error( 'rapidchat_invalid_email', __('Please enter a valid email address!', 'rapidchat'), array('status' => 422) ); } $name = mb_substr($name, 0, 100); rapidchat_event('before_guest_login', $email, $name); if ($returning) { $account_id = (int) $actor['id']; $wpdb->update( $wpdb->rapidchat_accounts, array('full_name' => $name, 'email' => $email, 'last_seen' => current_time('mysql')), array('id' => $account_id), array('%s', '%s', '%s'), array('%d') ); rapidchat_issue_token($account_id); rapidchat_event('after_guest_login', $account_id, $email, $name); return array('id' => $account_id, 'created' => false); } $inserted = $wpdb->insert( $wpdb->rapidchat_accounts, array( 'email' => $email, 'full_name' => $name, 'role' => 'Guest', 'last_seen' => current_time('mysql'), 'ip_address' => $ip, 'country' => '', 'status' => 'Idle', ), array('%s', '%s', '%s', '%s', '%s', '%s', '%s') ); if (!$inserted) { return new WP_Error( 'rapidchat_insert_failed', __('Could not start a chat session. Please try again.', 'rapidchat'), array('status' => 500) ); } $account_id = (int) $wpdb->insert_id; rapidchat_issue_token($account_id); rapidchat_schedule_country_lookup($account_id, $ip); rapidchat_event('after_guest_login', $account_id, $email, $name); return array('id' => $account_id, 'created' => true); }