wp_doing_ajax() WP 4.7.0
Determines whether the current request is a WordPress Ajax request.
This function is a wrapper for:
defined( 'DOING_AJAX' ) && DOING_AJAX
1 time = 0.000007s = speed of light | 50000 times = 0.01s = speed of light | PHP 7.0.8, WP 4.7
Hooks from the function
Return
true/false. True if it's a WordPress Ajax request, false otherwise.
Usage
if( wp_doing_ajax() ){ // this is AJAX request } ### Examples #### #1 Do something if the current request is an AJAX request Add AJAX hooks only for AJAX request. ```php if( wp_doing_ajax() ){ add_action( 'wp_ajax_myaction', 'ajax_handler' ); add_action( 'wp_ajax_nopriv_myaction', 'ajax_handler' ); function ajax_handler(){ // ajax request handler } }
Changelog
Since 4.7.0 | Introduced. |
Code of wp_doing_ajax() wp doing ajax WP 5.6
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 );
}Related Functions
From tag: AJAX
More from tag: Conditional tags (page type and request)
- is_404()
- is_admin()
- is_archive()
- is_attachment()
- is_author()
- is_blog_admin()
- is_category()
- is_comment_feed()
- is_customize_preview()
- is_date()
- is_day()
- is_embed()
More from tag: Conditional tags (all)
- cat_is_ancestor_of()
- comments_open()
- email_exists()
- has_category()
- has_custom_header()
- has_excerpt()
- has_nav_menu()
- has_post_thumbnail()
- has_shortcode()
- has_tag()
- has_term()
- have_comments()
- have_posts()
- in_category()
- in_the_loop()
- is_active_sidebar()
More from category: Helper Functions
- __return_empty_array()
- __return_empty_string()
- __return_false()
- __return_null()
- __return_true()
- __return_zero()
- build_query()
- get_page_hierarchy()
- get_temp_dir()
- human_readable_duration()
- is_email()
- is_php_version_compatible()
- is_serialized()
- is_serialized_string()
- is_wp_version_compatible()
- map_deep()
- maybe_serialize()
- maybe_unserialize()
- path_join()
- seems_utf8()
- stripslashes_deep()
- timer_stop()
- urlencode_deep()
- wp_array_slice_assoc()
- wp_basename()
- wp_debug_backtrace_summary()
- wp_extract_urls()
- wp_filter_object_list()
- wp_generate_uuid4()
- wp_html_split()
- wp_is_json_request()
- wp_is_numeric_array()
- wp_is_uuid()
- wp_kses_array_lc()
- wp_kses_hair()
- wp_kses_uri_attributes()
- wp_list_filter()
- wp_list_pluck()