Skip to content

Instantly share code, notes, and snippets.

@thaicloud
Last active July 14, 2022 15:35
Show Gist options
  • Save thaicloud/5e596a8f2f83b2ae15c1ac4826f2515e to your computer and use it in GitHub Desktop.
Save thaicloud/5e596a8f2f83b2ae15c1ac4826f2515e to your computer and use it in GitHub Desktop.
Sending Authenticated Requests Using WP HTTP API
$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