Skip to content

Instantly share code, notes, and snippets.

@Kevinlearynet
Created May 21, 2014 17:30
Show Gist options
  • Save Kevinlearynet/b4203d09e7a8d605725e to your computer and use it in GitHub Desktop.
Save Kevinlearynet/b4203d09e7a8d605725e to your computer and use it in GitHub Desktop.
Faster admin-ajax.php for WordPress AJAX actions
<?php
define('DOING_AJAX', true);
if ( ! isset( $_POST['action'] ) )
die('-1');
require_once('../../../../wp-load.php');
// headers for JSON
header('Content-Type: application/json');
send_nosniff_header();
// no cache
header('Cache-Control: no-cache');
header('Pragma: no-cache');
$action = esc_attr( trim( $_POST['action'] ) );
// security
$allowed_actions = array(
'rapid_generate_license',
);
if ( in_array( $action, $allowed_actions ) ) {
if ( is_user_logged_in() )
do_action( 'wp_fast_ajax_' . $action );
else
do_action( 'wp_fast_ajax_nopriv_' . $action );
} else {
die('-1');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment