-
-
Save imath/00630617d731b51e4db4ef9f81752eb5 to your computer and use it in GitHub Desktop.
Testing external REST API requests
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 | |
// Exit if accessed directly | |
defined( 'ABSPATH' ) || exit; | |
function test_wp_api_request() { | |
wp_enqueue_script( 'wp-api-request' ); | |
wp_add_inline_script( 'wp-api-request', ' | |
wp.apiRequest( { | |
url: \'https://imathi.eu/wp-json/wp/v2/posts\', | |
type: \'GET\', | |
data: { | |
context: \'view\', | |
search: \'core.trac.wordpress.org\' | |
} | |
} ).done( function( data ) { | |
console.log( data ); | |
} ).fail( function( error ) { | |
console.log( error ); | |
} ); | |
' ); | |
} | |
add_action( 'wp_enqueue_scripts', 'test_wp_api_request' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment