diff --git a/wpAliases.php b/wpAliases.php new file mode 100755 index 0000000..cfbc62c --- /dev/null +++ b/wpAliases.php @@ -0,0 +1,88 @@ +#!/usr/bin/php + $curlHeaders, + CURLOPT_RETURNTRANSFER => TRUE, + CURLOPT_POST => 1, + CURLOPT_URL => ENDPOINT . $operation, + CURLOPT_POSTFIELDS => $postFields ? json_encode($postFields) : NULL, + ]; + $curl = curl_init(); + curl_setopt_array($curl, $curlOptions); + $result = curl_exec($curl); + curl_close($curl); + return json_decode($result); +} + +function get($curlHeaders, $operation, $body = NULL) +{ + $curlHeaders[] = 'Accept: application/json'; + $curlOptions = [ + CURLOPT_HTTPHEADER => $curlHeaders, + CURLOPT_RETURNTRANSFER => TRUE, + CURLOPT_URL => ENDPOINT . $operation, + ]; + $curl = curl_init(); + curl_setopt_array($curl, $curlOptions); + $result = curl_exec($curl); + curl_close($curl); + return json_decode($result, TRUE); +}; + +/** + * Handle login (including getting a CSRF header) + * @return array $headers The necessary headers to perform further POST/GET actions. + */ +function login($password) +{ + $creds = [ + 'username' => USERNAME, + 'password' => $password, + ]; + + $result = post(NULL, 'user/login.json', $creds); + $headers[] = "Cookie: $result->session_name=$result->sessid"; + return $headers; +}