Skip to content

Instantly share code, notes, and snippets.

@soderlind
Last active March 16, 2021 22:57
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 soderlind/3c6098708cedf5de3c51101d0691a6ad to your computer and use it in GitHub Desktop.
Save soderlind/3c6098708cedf5de3c51101d0691a6ad to your computer and use it in GitHub Desktop.
WP Ajax transient demo.
<?php
/**
* Ajax action, triggerd by fetch() in es6-wp-ajax-demo.js
*
* @return void
*/
function es6_ajax_action() {
header( 'Content-type: application/json' );
if ( check_ajax_referer( 'es6_wp_ajax_nonce', 'nonce', false ) ) {
$response['response'] = 'success';
$response['data'] = get_transienT( 'MY_TRANSIENT' );
} else {
$response['response'] = 'failed';
$response['message'] = 'invalid nonse';
}
echo wp_json_encode( $response );
wp_die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment