Created
July 15, 2019 20:36
-
-
Save wordpress-lab/f4607adb922a54d1e5721ccb2a5f0d8d to your computer and use it in GitHub Desktop.
wp-remote
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 | |
$data = array('slug' => 'rest_insert' , 'title' => 'wp remote API insert wp update 1817' , 'content' => 'The content of our stuff update post 2', 'excerpt' => 'smaller' ); | |
$data_string = json_encode($data); | |
$id= 1827; | |
$args = array( | |
'headers' => array( | |
//'Authorization' => 'Bearer ' . $token | |
'Authorization' => 'Basic ' . base64_encode( $username . ':' . $password ), | |
'Content-Type' => 'application/json', | |
), | |
'sslverify' => false, | |
'method' => 'POST', | |
'body' => $data_string | |
); | |
$response = wp_remote_post( 'http://wordpress-300829-921065.cloudwaysapps.com/wp-json/wp/v2/posts/'.$id, $args ); | |
$response_code = wp_remote_retrieve_response_code( $response ); | |
$body = wp_remote_retrieve_body( $response ); | |
var_dump($body); |
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
$id = 1780; | |
$args = array( | |
'headers' => array( | |
//'Authorization' => 'Bearer ' . $token | |
'Authorization' => 'Basic ' . base64_encode( $username . ':' . $password ), | |
'Content-Type' => 'application/json', | |
), | |
'sslverify' => false | |
); | |
$response = wp_remote_get( 'https://wordpress-300829-921065.cloudwaysapps.com/wp-json/wp/v2/posts/'.$id, $args ); | |
$response_code = wp_remote_retrieve_response_code( $response ); | |
$body = wp_remote_retrieve_body( $response ); | |
/* | |
wp_remote_retrieve_body() gets the response’s body, | |
the wp_remote_retrieve_header() function gets a named header. The | |
wp_remote_retrieve_headers() function returns all headers in array form, | |
wp_remote_retrieve_response_code() gives you the response code and | |
wp_remote_retrieve_response_message() returns the response message. | |
*/ | |
var_dump($body); |
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
$data = array('slug' => 'rest_insert' , 'title' => 'wp remote API insert wp' , 'content' => 'The content of our stuff update post 2', 'excerpt' => 'smaller' ); | |
$data_string = json_encode($data); | |
$args = array( | |
'headers' => array( | |
//'Authorization' => 'Bearer ' . $token | |
'Authorization' => 'Basic ' . base64_encode( $username . ':' . $password ), | |
'Content-Type' => 'application/json', | |
), | |
'sslverify' => false, | |
'method' => 'POST', | |
'body' => $data_string | |
); | |
$response = wp_remote_post( 'http://wordpress-300829-921065.cloudwaysapps.com/wp-json/wp/v2/posts/', $args ); | |
$response_code = wp_remote_retrieve_response_code( $response ); | |
$body = wp_remote_retrieve_body( $response ); | |
var_dump($body); |
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
$data = array('slug' => 'rest_insert' , 'title' => 'wp remote API insert wp update 1817' , 'content' => 'The content of our stuff update post 2', 'excerpt' => 'smaller' ); | |
$data_string = json_encode($data); | |
$id= 1827; | |
$args = array( | |
'headers' => array( | |
//'Authorization' => 'Bearer ' . $token | |
'Authorization' => 'Basic ' . base64_encode( $username . ':' . $password ), | |
'Content-Type' => 'application/json', | |
), | |
'sslverify' => false, | |
'method' => 'DELETE', | |
'body' => $data_string | |
); | |
$response = wp_remote_post( 'http://wordpress-300829-921065.cloudwaysapps.com/wp-json/wp/v2/posts/'.$id, $args ); | |
$response_code = wp_remote_retrieve_response_code( $response ); | |
$body = wp_remote_retrieve_body( $response ); | |
var_dump($body); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment