Add a front end Ajax handler. Props Denis-de-Bernardy. See #12400

git-svn-id: http://svn.automattic.com/wordpress/trunk@13527 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dd32 2010-03-01 11:49:50 +00:00
parent d5427d9210
commit ffe41241ef
3 changed files with 51 additions and 1 deletions

30
wp-ajax.php Normal file
View File

@ -0,0 +1,30 @@
<?php
/**
* Execute an AJAX action.
*
* To take full advantage of this file, call wp_ajaxurl(); in your theme
* or plugin while registering your front-end scripts. Doing so will make
* an ajaxurl variable available for use in javascripts. The ajaxurl
* variable will point to this file's absolute URL.
*
* In the admin area, an ajaxurl variable is always available, and points
* to wp-admin/admin-ajax.php instead.
*
* @since 3.0
*/
define('DOING_AJAX', true);
require_once('wp-load.php');
@header('Content-Type: text/html; charset=' . get_option('blog_charset'));
do_action('ajax_init');
$hook = !empty($_REQUEST['action']) ? 'ajax_' . $_REQUEST['action'] : false;
if ( empty($hook) || ! has_action($hook) ) {
status_header(400);
exit;
}
do_action($hook);
?>

View File

@ -2015,4 +2015,24 @@ function rel_canonical() {
echo "<link rel='canonical' href='$link' />\n";
}
/**
* Prints the ajax url on the front end
*
* @since 3.0
**/
function _wp_ajaxurl() {
echo '<script type="text/javascript">',
"var ajaxurl = '", esc_js(site_url('wp-ajax.php')), "';",
"</script>\n";
}
/**
* Hooks _wp_ajaxurl() to wp_head
*
* @since 3.0
**/
function wp_ajaxurl() {
add_action('wp_head', '_wp_ajaxurl', 1);
}
?>

View File

@ -289,7 +289,7 @@ do_action( 'init' );
/**
* This hook is fired once WP, all plugins, and the theme are fully loaded and instantiated.
*
* AJAX requests should use wp-admin/admin-ajax.php.
* AJAX requests should use wp-ajax.php and wp-admin/admin-ajax.php instead.
*
* @since 3.0.0
*/