Skip to content

Instantly share code, notes, and snippets.

@ericrallen
Created March 29, 2013 08:32
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 ericrallen/5269488 to your computer and use it in GitHub Desktop.
Save ericrallen/5269488 to your computer and use it in GitHub Desktop.
Work in Progress for running custom wp_ajax actions
<?php
/*--------------------------------------------------------------------------
Better AJAX for WordPress
inspired by:
http:wordpress.stackexchange.com/questions/28342/is-there-a-way-to-use-the-wordpress-users-but-without-loading-the-entire-wordpre#answer-45011
--------------------------------------------------------------------------*/
//mimic the actuall admin-ajax
define('DOING_AJAX', true);
if(!isset($_POST['action'])) {
die('1');
} else {
ini_set('html_errors', 0);
define('SHORTINIT', true);
//Typical headers
header('Content-Type: text/html');
//Disable caching
header('Cache-Control: no-cache');
header('Pragma: no-cache');
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/wp-load.php');
// Load most of WordPress.
require_once( ABSPATH . WPINC .'/plugin.php');
require_once(ABSPATH . WPINC . '/l10n.php');
require_once( ABSPATH . WPINC . '/class-wp-walker.php' );
require_once( ABSPATH . WPINC . '/formatting.php' );
require_once( ABSPATH . WPINC . '/capabilities.php' );
require_once( ABSPATH . WPINC . '/query.php' );
require_once( ABSPATH . WPINC . '/theme.php' );
require_once( ABSPATH . WPINC . '/user.php' );
require_once( ABSPATH . WPINC . '/meta.php' );
require_once( ABSPATH . WPINC . '/general-template.php' );
require_once( ABSPATH . WPINC . '/link-template.php' );
require_once( ABSPATH . WPINC . '/post.php' );
require_once( ABSPATH . WPINC . '/comment.php' );
require_once( ABSPATH . WPINC . '/rewrite.php' );
require_once( ABSPATH . WPINC . '/kses.php' );
require_once( ABSPATH . WPINC . '/cron.php' );
require_once( ABSPATH . WPINC . '/script-loader.php' );
require_once( ABSPATH . WPINC . '/taxonomy.php' );
require_once( ABSPATH . WPINC . '/shortcodes.php' );
require_once( ABSPATH . WPINC . '/media.php' );
require_once( ABSPATH . WPINC . '/http.php' );
require_once( ABSPATH . WPINC . '/class-http.php' );
require_once( ABSPATH . WPINC . '/widgets.php' );
require_once( ABSPATH . WPINC . '/nav-menu.php' );
wp_plugin_directory_constants();
foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
include_once( $plugin );
}
unset( $plugin );
//call action and exit
$action = trim($_POST['action']);
do_action('ia_custom_ajax_nopriv_' . $action);
die('0');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment