确定当前请求是否为 WordPress Ajax 请求,如果是 WordPress Ajax 请求则为 True,否则为 false。
函数原型:
wp_doing_ajax(): bool
函数源码:
function wp_doing_ajax() {
/**
* Filters whether the current request is a WordPress Ajax request.
*
* @since 4.7.0
*
* @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request.
*/
return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
}
使用举例:
function wpdocs_render() {
/* ........ SOME LOGIC ....... */
$return_data = array( 'success' => true );
if ( wp_doing_ajax() ) {
wp_send_json_success( $return_data );
} else {
return $return_data;
}
}
-
WordPress函数:wp_update_post 更新修改文章WordPress函数:wp_update_post 更新修改文章
-
WordPress函数:wp_trash_post_comments 移动文章评论到垃圾站WordPress函数:wp_trash_post_comments 移动文章评论到垃圾站
-
WordPress函数:wp_delete_attachment 删除附件WordPress函数:wp_delete_attachment 删除评论
-
WordPress函数:wp_update_user 更新用户信息WordPress函数:wp_update_user 更新用户信息
-
WordPress函数:add_shortcode 添加短代码WordPress函数:add_shortcode 添加短代码
-
WordPress函数:remove_shortcode 删除短代码WordPress函数:remove_shortcode 删除短代码
暂无评论,抢个沙发...