Created
May 12, 2020 14:55
-
-
Save maheshwaghmare/a7efce9a4904b51ce2f4de15c2bddf23 to your computer and use it in GitHub Desktop.
Perform the "Basic Authentication" request in WordPress with plugin "JSON Basic Authentication". Read more at https://maheshwaghmare.com/doc/basic-authentication/
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
<?php | |
if( ! function_exists( 'prefix_create_new_post' ) ) : | |
/** | |
* Create new post with wp_remote_post() | |
* | |
* @since 1.0.0 | |
* @return void | |
*/ | |
function prefix_create_new_post() { | |
$username = 'admin'; | |
$password = 'admin'; | |
$site_url = 'http://localhost/maheshwaghmare.com/'; | |
$request = wp_remote_post( $site_url . 'wp-json/wp/v2/posts/', array( | |
'body' => array( | |
'title' => 'Rest API Post 3', | |
), | |
'headers' => array( | |
'Authorization' => 'Basic ' . base64_encode( $username . ':' . $password ), | |
), | |
) ); | |
} | |
add_action( 'admin_head', 'prefix_create_new_post' ); | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment