send($customer_id); } /** * Build the payload and POST it to Afileasy. * * @param int $customer_id */ public function send($customer_id): void { $connection = Connection::get(); if ($connection === null) { return; } $user = get_userdata((int) $customer_id); if (! $user || ! is_email($user->user_email)) { return; } $ref = get_user_meta($user->ID, self::USER_META_KEY, true); if (! is_string($ref) || $ref === '') { return; } $payload = [ 'public_key' => $connection['o'], 'code' => $ref, 'email' => $user->user_email, 'name' => $this->name($user), ]; wp_remote_post(Connection::leadUrl($connection), [ 'headers' => [ 'Content-Type' => 'application/json', 'Accept' => 'application/json', ], 'body' => wp_json_encode($payload), 'timeout' => 20, 'blocking' => true, ]); } private function name(\WP_User $user): ?string { $full = trim($user->first_name.' '.$user->last_name); if ($full !== '') { return $full; } return $user->display_name !== '' ? $user->display_name : null; } }