Created
August 16, 2016 21:57
-
-
Save sfgarza/8e57cc1eceabcbcb93738741978ea8d8 to your computer and use it in GitHub Desktop.
Revisions
-
Santiago Garza created this gist
Aug 16, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,76 @@ <?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" $all_installs = array( 'install1', 'install2', 'install3, ); # Grab options from command line $options = getopt("i:c:"); # Break out into variables $install = $options["i"]; $command = $options["c"]; if ( isset( $command ) ){ if( isset( $install )){ send_request( $install, $command ); } else{ foreach ( $all_installs as $site ) { send_request( $site, $command ); } } echo "\n"; } else{ echo "Error - No command inputted\n"; } function send_request( $install, $command ){ # 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"]; } } ?>