Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX )
- {
- // do something
- }
- if ( wp_doing_ajax() )
- {
- // do something
- }
- File: /wp-includes/load.php
- 1037: /**
- 1038: * Determines whether the current request is a WordPress Ajax request.
- 1039: *
- 1040: * @since 4.7.0
- 1041: *
- 1042: * @return bool True if it's a WordPress Ajax request, false otherwise.
- 1043: */
- 1044: function wp_doing_ajax() {
- 1045: /**
- 1046: * Filters whether the current request is a WordPress Ajax request.
- 1047: *
- 1048: * @since 4.7.0
- 1049: *
- 1050: * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request.
- 1051: */
- 1052: return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
- 1053: }
- File: /wp-admin/admin-ajax.php
- 11: /**
- 12: * Executing Ajax process.
- 13: *
- 14: * @since 2.1.0
- 15: */
- 16: define( 'DOING_AJAX', true );
- 17: if ( ! defined( 'WP_ADMIN' ) ) {
- 18: define( 'WP_ADMIN', true );
- 19: }
- function saveIsAdmin() {
- //Ajax request are always identified as administrative interface page
- //so let's check if we are calling the data for the frontend or backend
- if (wp_doing_ajax() === true) {
- $adminUrl = get_admin_url();
- //If the referer is an admin url we are requesting the data for the backend
- return (substr($_SERVER['HTTP_REFERER'], 0, strlen($adminUrl)) === $adminUrl);
- }
- //No ajax request just use the normal function
- return is_admin();
- }
Add Comment
Please, Sign In to add comment