API Route for User Registration

Sample Code for User Registration via API Routes

PHP Curl

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL =&gt; 'https://mysite.com/wp-json/wpcargo/v1/api/register_user',
  CURLOPT_RETURNTRANSFER =&gt; true,
  CURLOPT_ENCODING =&gt; '',
  CURLOPT_MAXREDIRS =&gt; 10,
  CURLOPT_TIMEOUT =&gt; 0,
  CURLOPT_FOLLOWLOCATION =&gt; true,
  CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST =&gt; 'POST',
  CURLOPT_POSTFIELDS =&gt;'{
    "username": "xxxxxyyyy",
    "email": "xxx000000@gmail.com",
    "password": "123456",
    "phone": "123654789",
    "address": "Philippines",
    "city": "Iloilo city1"
}
',
  CURLOPT_HTTPHEADER =&gt; array(
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Sample Response:

{
    "code": 406,
    "message": "Email is already exists, please try another email",
    "data": {
        "status": 400
    }
}

PHP HTTP Request2


<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://jeffreydula.iloiloadventure.com/wp-json/wpcargo/v1/api/register_user');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
$request->setHeader(array(
  'Content-Type' => 'application/json'
));
$request->setBody('{
\n    "username": "xxxxxyyyy",
\n    "email": "xxx000000@gmail.com",
\n    "password": "123456",
\n    "phone": "123654789",
\n    "address": "Philippines",
\n    "city": "Iloilo city1"
\n}
\n');
try {
  $response = $request->send();
  if ($response->getStatus() == 200) {
    echo $response->getBody();
  }
  else {
    echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
  }
}
catch(HTTP_Request2_Exception $e) {
  echo 'Error: ' . $e->getMessage();
}

0
    0
    Your Cart
    Your cart is emptyReturn to Shop