确定当前请求是否为 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函数:get_template_part 用法简介get_template_part 有什么优点
-
WordPress函数:wp_is_writable 判断路径是否可写检查文件权限的方便函数
-
WordPress函数:wp_title 主题页面标题WordPress 页面标题SEO
-
WordPress函数:wp_timezone_string 返回后台设置的时区当前设置的时区是什么
-
WordPress函数:current_time 返回当前时间在 WordPress 如何获取当前时间
-
WordPress函数:set_query_var 与 get_query_var 设置与获取查询参数一对WordPress函数
暂无评论,抢个沙发...