From 3bd65d73c7527aa4eff1f2d650340d4361d0473e Mon Sep 17 00:00:00 2001 From: Brienne Kordis Date: Tue, 6 Sep 2022 17:48:13 -0400 Subject: [PATCH] create aliases --- wpAliases.php | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 wpAliases.php 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; +}