gmb_test_ajax_works

Check if AJAX works as expected.

Description

gmb_test_ajax_works(); 

Usage

  1. if ( !function_exists( 'gmb_test_ajax_works' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'maps-builder/vendor/wordimpress/maps-builder-core/includes/misc-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = gmb_test_ajax_works(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/vendor/wordimpress/maps-builder-core/includes/misc-functions.php  
  1. function gmb_test_ajax_works() { 
  2.  
  3. // Check if the Airplane Mode plugin is installed 
  4. if ( class_exists( 'Airplane_Mode_Core' ) ) { 
  5.  
  6. $airplane = Airplane_Mode_Core::getInstance(); 
  7.  
  8. if ( method_exists( $airplane, 'enabled' ) ) { 
  9.  
  10. if ( $airplane->enabled() ) { 
  11. return true; 
  12.  
  13. } else { 
  14.  
  15. if ( $airplane->check_status() == 'on' ) { 
  16. return true; 
  17.  
  18. add_filter( 'block_local_requests', '__return_false' ); 
  19.  
  20. if ( get_transient( '_gmb_ajax_works' ) ) { 
  21. return true; 
  22.  
  23. $params = array( 
  24. 'sslverify' => false,  
  25. 'timeout' => 30,  
  26. 'body' => array( 
  27. 'action' => 'gmb_test_ajax' 
  28. ); 
  29.  
  30. $ajax = wp_remote_post( gmb_get_ajax_url(), $params ); 
  31. $works = true; 
  32.  
  33. if ( is_wp_error( $ajax ) ) { 
  34.  
  35. $works = false; 
  36.  
  37. } else { 
  38.  
  39. if ( empty( $ajax['response'] ) ) { 
  40. $works = false; 
  41.  
  42. if ( empty( $ajax['response']['code'] ) || 200 !== (int) $ajax['response']['code'] ) { 
  43. $works = false; 
  44.  
  45. if ( empty( $ajax['response']['message'] ) || 'OK' !== $ajax['response']['message'] ) { 
  46. $works = false; 
  47.  
  48. if ( ! isset( $ajax['body'] ) || 0 !== (int) $ajax['body'] ) { 
  49. $works = false; 
  50.  
  51.  
  52. if ( $works ) { 
  53. set_transient( '_gmb_ajax_works', '1', DAY_IN_SECONDS ); 
  54.  
  55. return $works;