我想我会this nifty shortinit trick 转一圈。然而,当我在自定义ajax处理程序中包含此内容时,我的回调没有得到任何响应。如果我对它进行评论,它的效果很好。有什么变化吗?
<?php
//mimic the actual admin-ajax
define(\'DOING_AJAX\', true);
if (!isset( $_POST[\'action\']))
die(\'-1\');
ini_set(\'html_errors\', 0);
define(\'SHORTINIT\', true);
require_once(\'wp/wp-load.php\');
//Typical headers
header(\'Content-Type: text/html\');
send_nosniff_header();
//Disable caching
header(\'Cache-Control: no-cache\');
header(\'Pragma: no-cache\');
$action = esc_attr(trim($_POST[\'action\']));
$allowed_actions = array(
\'posts\',
\'status\',
);
if(in_array($action, $allowed_actions)){
if(is_user_logged_in())
do_action(\'handle_tumblr_\'.$action);
else
do_action(\'handle_tumblr_nopriv_\'.$action);
}
else{
die(\'-1\');
}
function tumblr_status() {
echo \'whos there?\';
exit;
}
add_action(\'handle_tumblr_status\',\'tumblr_status\');
add_action(\'handle_tumblr_nopriv_status\',\'tumblr_status\');
function tumblr_posts() {
echo \'k\';
exit;
}
add_action(\'handle_tumblr_posts\',\'tumblr_posts\');
add_action(\'handle_tumblr_nopriv_posts\',\'tumblr_posts\');