Created
March 8, 2016 01:35
-
-
Save austinginder/8b17ae51269c5add6874 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
### PHP command line wrapper for WP Engine's web based WP-CLI | |
### Example command line: php wp_engine_cli.php -i wp_install_name -c "cli info" | |
# Grab options from command line | |
$options = getopt("i:c:"); | |
# Break out into variables | |
$install = $options["i"]; | |
$command = $options["c"]; | |
# Replay token and cookie from valid WP Engine web request | |
$token = "######"; | |
$cookie = "######"; | |
$curl_url = "https://my.wpengine.com/installs/$install/wp_cli?command=" .urlencode($command); | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_URL => $curl_url, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_ENCODING => "", | |
CURLOPT_MAXREDIRS => 10, | |
CURLOPT_TIMEOUT => 30, | |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | |
CURLOPT_CUSTOMREQUEST => "POST", | |
CURLOPT_HTTPHEADER => array( | |
"cache-control: no-cache", | |
"cookie: $cookie", | |
"x-csrf-token: $token" | |
), | |
)); | |
$response = curl_exec($curl); | |
$err = curl_error($curl); | |
curl_close($curl); | |
if ($err) { | |
echo "cURL Error #:" . $err; | |
} else { | |
# convert json output to PHP array | |
$array = json_decode($response, true); | |
# output reponse from array back to command line | |
echo $array["response"]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment