Last active
July 14, 2022 15:35
-
-
Save thaicloud/5e596a8f2f83b2ae15c1ac4826f2515e to your computer and use it in GitHub Desktop.
Sending Authenticated Requests Using WP HTTP API
This file contains 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
$wp_request_headers = array( | |
'Authorization' => 'Basic ' . base64_encode( 'username:password' ) | |
); | |
$wp_request_url = 'http://localserver/wordpress-api/wp-json/wp/v2/posts/52'; | |
$wp_delete_post_response = wp_remote_request( | |
$wp_request_url, | |
array( | |
'method' => 'DELETE', | |
'headers' => $wp_request_headers | |
) | |
); | |
echo wp_remote_retrieve_response_code( $wp_delete_post_response ) . ' ' . wp_remote_retrieve_response_message( $wp_delete_post_response ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment