Skip to content

Instantly share code, notes, and snippets.

@zackkatz
Forked from rafaehlers/gv-rest-api-nonce.php
Created August 5, 2021 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackkatz/abcc0a94223b5934fc3cd3fa172418a0 to your computer and use it in GitHub Desktop.
Save zackkatz/abcc0a94223b5934fc3cd3fa172418a0 to your computer and use it in GitHub Desktop.
Code snippet for this: https://docs.gravityview.co/article/468-rest-api (Authentication section)
<?php
$entries_url = 'https://try.gravityview.co/demo/wp-json/gravityview/v1/views/148/entries.json';
$nonce = wp_create_nonce( 'wp_rest' );
?>
<script type="text/javascript">
jQuery.ajax( {
url: <?php echo json_encode( $entries_url ); ?>,
method: 'GET',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', <?php echo json_encode( $nonce ); ?> );
},
} ).done( function ( response ) {
console.log( response );
} );
</script>
<?php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment