Created
October 27, 2011 20:57
-
-
Save andredublin/1320847 to your computer and use it in GitHub Desktop.
Usually I have to create custom scripts to respond to ajax
This file contains 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
/** | |
* Define WP_USE_THEMES | |
* | |
**/ | |
define('WP_USE_THEMES', false); | |
require($_SERVER['DOCUMENT_ROOT'] . '/wp-blog-header.php'); | |
header('HTTP/1.1 200 OK'); | |
header('Content-type: application/json;'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When creating custom php scripts that will respond to ajax calls it is necessary to include core wordpress files and set the response headers to 200 and json. Make sure to have a condition that prevents users from viewing the file directly such as a preg_match for your $_POST or $_GET constants index or if the required index of either super global array is not set then initiate die() or exit() or redirect with header()