Created
May 12, 2020 15:07
-
-
Save maheshwaghmare/9e3e7806b345bebf9e3d84df64097cf1 to your computer and use it in GitHub Desktop.
Perform the "Basic Authentication" request in WordPress with plugin "Application Passwords". Read more at https://maheshwaghmare.com/doc/application-passwords/
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 = 'mK7M wZmN Fuj5 IKYF XUAv EZ8H'; | |
$site_url = 'http://localhost/dev.test/'; | |
$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