Google_Maps_Builder_Core_Engine

Class Google_Maps_Builder_Core_Engine.

Defined (1)

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

/vendor/wordimpress/maps-builder-core/includes/class-gmc-engine.php  
  1. abstract class Google_Maps_Builder_Core_Engine { 
  2.  
  3.  
  4. /** 
  5. * Google Maps Builder Engine 
  6. * Hooks and actions start here. 
  7. * @since 1.0.0 
  8. */ 
  9. public function __construct() { 
  10.  
  11. // Filter to automatically add maps to post type content 
  12. add_filter( 'the_content', array( $this, 'the_content' ), 2 ); 
  13.  
  14. //add shortcode support 
  15. add_shortcode( 'google_maps', array( $this, 'google_maps_shortcode' ) ); 
  16.  
  17.  
  18. /** 
  19. * Google Map display on Single Posts. 
  20. * The [google_maps] shortcode will be prepended/appended to the post body,  
  21. * once for each map. The shortcode is used so it can be filtered. 
  22. * For example WordPress will remove it in excerpts by default. 
  23. * @param $content 
  24. * @return mixed 
  25. */ 
  26. function the_content( $content ) { 
  27.  
  28. global $post; 
  29.  
  30. if ( is_main_query() && is_singular( 'google_maps' ) || is_post_type_archive( 'google_maps' ) ) { 
  31.  
  32. $shortcode = '[google_maps '; 
  33. $shortcode .= 'id="' . $post->ID . '"'; 
  34. $shortcode .= ']'; 
  35.  
  36. //Output shortcode 
  37. return $shortcode; 
  38.  
  39.  
  40. return $content; 
  41.  
  42.  
  43.  
  44. /** 
  45. * Single Template Function 
  46. * @param $single_template 
  47. * @return string 
  48. */ 
  49. public function get_google_maps_template( $single_template ) { 
  50.  
  51. if ( file_exists( get_stylesheet_directory() . '/google-maps/' . $single_template ) ) { 
  52. $output = get_stylesheet_directory() . '/google-maps/' . $single_template; 
  53. } else { 
  54. $output = gmb_find_view( 'views/' . $single_template ); 
  55.  
  56. return $output; 
  57.  
  58.  
  59. /** 
  60. * Google Maps Builder Shortcode 
  61. * Google Maps output relies on the shortcode to display 
  62. * @param $atts 
  63. * @return string 
  64. */ 
  65. public function google_maps_shortcode( $atts ) { 
  66. _doing_it_wrong( __FUNCTION__, 'Override in parent class!', '2.0.0' ); 
  67.  
  68. /** 
  69. * Localize Scripts 
  70. * Add params to AJAX for Shortcode Usage 
  71. * @see : http://benjaminrojas.net/using-wp_localize_script-dynamically/ 
  72. * @param $localized_data 
  73. */ 
  74. function array_push_localized_script( $localized_data ) { 
  75. global $wp_scripts; 
  76. $data = $wp_scripts->get_data( 'google-maps-builder-plugin-script', 'data' ); 
  77.  
  78. if ( empty( $data ) ) { 
  79. wp_localize_script( 'google-maps-builder-plugin-script', 'gmb_data', $localized_data ); 
  80. } else { 
  81.  
  82. if ( ! is_array( $data ) ) { 
  83.  
  84. $data = json_decode( str_replace( 'var gmb_data = ', '', substr( $data, 0, - 1 ) ), true ); 
  85.  
  86.  
  87. foreach ( $data as $key => $value ) { 
  88. $localized_data[ $key ] = $value; 
  89.  
  90. $wp_scripts->add_data( 'google-maps-builder-plugin-script', 'data', '' ); 
  91. wp_localize_script( 'google-maps-builder-plugin-script', 'gmb_data', $localized_data ); 
  92.  
  93.  
  94.  
  95.