Created
October 21, 2011 23:49
-
-
Save agustibr/1305291 to your computer and use it in GitHub Desktop.
Frontend AJAX in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Frontend AJAX in WordPress //http://codex.wordpress.org/AJAX_in_Plugins | |
define('DOING_AJAX', true); | |
/* Assuming you will put this file in your plugin's directory */ | |
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'wp-load.php'); | |
if(!isset($_REQUEST['action']) || trim($_REQUEST['action'])=='') | |
{ | |
die('-1'); | |
} | |
@header('Content-Type: text/html; charset='.get_option('blog_charset')); | |
/* Including your plugin's main file where ajax actions are defined */ | |
include_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'main-plugin-file.php'); | |
send_nosniff_header(); | |
if(has_action('wp_ajax_'.$_REQUEST['action'])) | |
{ | |
do_action('wp_ajax_'.$_REQUEST['action']); | |
exit; | |
} | |
status_header(404); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment