Guest User

Untitled

a guest
Nov 18th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX )
  2. {
  3. // do something
  4. }
  5.  
  6. if ( wp_doing_ajax() )
  7. {
  8. // do something
  9. }
  10.  
  11. File: /wp-includes/load.php
  12. 1037: /**
  13. 1038: * Determines whether the current request is a WordPress Ajax request.
  14. 1039: *
  15. 1040: * @since 4.7.0
  16. 1041: *
  17. 1042: * @return bool True if it's a WordPress Ajax request, false otherwise.
  18. 1043: */
  19. 1044: function wp_doing_ajax() {
  20. 1045: /**
  21. 1046: * Filters whether the current request is a WordPress Ajax request.
  22. 1047: *
  23. 1048: * @since 4.7.0
  24. 1049: *
  25. 1050: * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request.
  26. 1051: */
  27. 1052: return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
  28. 1053: }
  29.  
  30. File: /wp-admin/admin-ajax.php
  31. 11: /**
  32. 12: * Executing Ajax process.
  33. 13: *
  34. 14: * @since 2.1.0
  35. 15: */
  36. 16: define( 'DOING_AJAX', true );
  37. 17: if ( ! defined( 'WP_ADMIN' ) ) {
  38. 18: define( 'WP_ADMIN', true );
  39. 19: }
  40.  
  41. function saveIsAdmin() {
  42. //Ajax request are always identified as administrative interface page
  43. //so let's check if we are calling the data for the frontend or backend
  44. if (wp_doing_ajax() === true) {
  45. $adminUrl = get_admin_url();
  46. //If the referer is an admin url we are requesting the data for the backend
  47. return (substr($_SERVER['HTTP_REFERER'], 0, strlen($adminUrl)) === $adminUrl);
  48. }
  49.  
  50. //No ajax request just use the normal function
  51. return is_admin();
  52. }
Add Comment
Please, Sign In to add comment