Google_Maps_Builder_Core_Scripts

Class Google_Maps_Builder_Core_Scripts.

Defined (1)

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

/vendor/wordimpress/maps-builder-core/includes/class-gmc-scripts.php  
  1. abstract class Google_Maps_Builder_Core_Scripts { 
  2.  
  3. /** 
  4. * The plugin's settings 
  5. * @since 2.0.0 
  6. * @var array 
  7. */ 
  8. protected $plugin_settings; 
  9.  
  10. /** 
  11. * Var for loading google maps api 
  12. * Var for dependency 
  13. * @var bool 
  14. */ 
  15. protected $google_maps_conflict = false; 
  16.  
  17. /** 
  18. * Asset paths 
  19. * @since 2.1.0 
  20. * @var Google_Maps_Builder_Core_Asset_Paths 
  21. */ 
  22. protected $paths; 
  23.  
  24. /** 
  25. * Google_Maps_Builder_Core_Scripts constructor. 
  26. */ 
  27. public function __construct() { 
  28. $this->paths = Google_Maps_Builder_Core_Asset_Paths::get_instance(); 
  29. $this->plugin_settings = get_option( 'gmb_settings' ); 
  30. if( is_admin() ) { 
  31. add_action( 'admin_print_scripts', array( $this, 'check_for_multiple_google_maps_api_calls' ) ); 
  32. }else{ 
  33. add_action( 'wp_print_scripts', array( $this, 'check_for_multiple_google_maps_api_calls' ) ); 
  34.  
  35. $this->hooks(); 
  36.  
  37. /** 
  38. * Use to add hooks in parent class 
  39. * @since 1.0 
  40. * @return string 
  41. */ 
  42. protected function hooks() { 
  43. //left empty since can't declare abstract in dinoPHP 
  44.  
  45. /** 
  46. * Load Google Maps API 
  47. * Determine if Google Maps API script has already been loaded 
  48. * @since : 1.0.3 
  49. * @return bool $multiple_google_maps_api 
  50. */ 
  51. public function check_for_multiple_google_maps_api_calls() { 
  52. global $wp_scripts; 
  53.  
  54. if ( ! $wp_scripts ) { 
  55. return false; 
  56.  
  57. //loop through registered scripts 
  58. foreach ( $wp_scripts->registered as $registered_script ) { 
  59.  
  60. //find any that have the google script as the source, ensure it's not enqueud by this plugin 
  61. if ( 
  62. ( strpos( $registered_script->src, 'maps.googleapis.com/maps/api/js' ) !== false && 
  63. strpos( $registered_script->handle, 'google-maps-builder' ) === false ) || 
  64. ( strpos( $registered_script->src, 'maps.google.com/maps/api/js' ) !== false && 
  65. strpos( $registered_script->handle, 'google-maps-builder' ) === false ) 
  66. ) { 
  67.  
  68. //Remove this script from loading 
  69. wp_deregister_script( $registered_script->handle ); 
  70. wp_dequeue_script( $registered_script->handle ); 
  71.  
  72.  
  73. $this->google_maps_conflict = true; 
  74. //ensure we can detect scripts on the frontend from backend; we'll use an option to do this 
  75. if ( ! is_admin() ) { 
  76. update_option( 'gmb_google_maps_conflict', true ); 
  77.  
  78.  
  79.  
  80. //Ensure that if user resolved conflict on frontend we remove the option flag 
  81. if ( $this->google_maps_conflict === false && ! is_admin() ) { 
  82. update_option( 'gmb_google_maps_conflict', false ); 
  83.  
  84.  
  85. /** 
  86. * Construct a Google Maps API URL 
  87. * @param bool $signed_in_option 
  88. * @param string $libraries Optional. Default is 'places, drawing'. Which libraries to load. 
  89. * @return string 
  90. */ 
  91. protected function google_maps_url( $signed_in_option, $libraries = 'places, drawing' ) { 
  92.  
  93. $google_maps_api_key = gmb_get_option( 'gmb_maps_api_key' ); 
  94. $gmb_language = gmb_get_option( 'gmb_language' ); 
  95.  
  96. $google_maps_api_url_args = array( 
  97. 'libraries' => $libraries 
  98. ); 
  99.  
  100. //Google Maps API key present? 
  101. if ( ! empty( $google_maps_api_key ) ) { 
  102. $google_maps_api_url_args[ 'key' ] = $google_maps_api_key; 
  103.  
  104. //Preferred Language? 
  105. if ( ! empty( $google_maps_api_key ) ) { 
  106. $google_maps_api_url_args[ 'language' ] = $gmb_language; 
  107.  
  108. //Signed In? 
  109. if ( ! empty( $signed_in_option ) && $signed_in_option == 'enabled' ) { 
  110. $google_maps_api_url_args[ 'signed_in' ] = true; 
  111.  
  112. $google_maps_api_url = add_query_arg( $google_maps_api_url_args, 'https://maps.googleapis.com/maps/api/js?v=3.exp' ); 
  113.  
  114. return $google_maps_api_url; 
  115.  
  116.