Skip to content

Instantly share code, notes, and snippets.

@soderlind
Last active Mar 16, 2021
Embed
What would you like to do?
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