Google_Maps_Builder_Widget

The Maps Builder Google Maps Builder Widget class.

Defined (1)

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

/vendor/wordimpress/maps-builder-core/includes/class-gmc-widget.php  
  1. class Google_Maps_Builder_Widget extends WP_Widget { 
  2.  
  3. /** 
  4. * Array of Private Options 
  5. * @since 2.0 
  6. * @var array 
  7. */ 
  8. public $widget_defaults = array( 
  9. 'title' => '',  
  10. 'id' => '',  
  11. ); 
  12.  
  13.  
  14. /** 
  15. * Register widget with WordPress. 
  16. */ 
  17. public function __construct() { 
  18.  
  19. parent::__construct( 
  20. 'gmb_maps_widget', // Base ID 
  21. __( 'Maps Builder Widget', 'google-maps-builder' ), // Name 
  22. array( 
  23. 'classname' => 'gmb-maps-widget',  
  24. 'description' => __( 'Display a Google Map in your theme\'s widget powered sidebar.', 'google-maps-builder' ) 
  25. ) //Args 
  26. ); 
  27.  
  28. //Actions 
  29. add_action( 'admin_enqueue_scripts', array( $this, 'admin_widget_scripts' ) ); 
  30.  
  31.  
  32.  
  33. //Load Widget JS Script ONLY on Widget page 
  34. public function admin_widget_scripts( $hook ) { 
  35.  
  36. // Use minified libraries if SCRIPT_DEBUG is turned off 
  37. $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; 
  38.  
  39. //Widget Script 
  40. if ( $hook == 'widgets.php' ) { 
  41.  
  42. wp_register_style( 'google-maps-builder-admin-styles', GMB_CORE_URL . 'assets/css/gmb-admin' . $suffix . '.css', array(), GMB_VERSION ); 
  43. wp_enqueue_style( 'google-maps-builder-admin-styles' ); 
  44.  
  45. wp_register_script( 'gmb-qtip', GMB_CORE_URL . 'assets/js/plugins/jquery.qtip' . $suffix . '.js', array( 'jquery' ), GMB_VERSION ); 
  46. wp_enqueue_script( 'gmb-qtip' ); 
  47.  
  48. wp_register_script( 'gmb-admin-widgets-scripts', GMB_CORE_URL . 'assets/js/admin/admin-widget' . $suffix . '.js', array( 'jquery' ), GMB_VERSION, false ); 
  49. wp_enqueue_script( 'gmb-admin-widgets-scripts' ); 
  50.  
  51.  
  52.  
  53.  
  54. /** 
  55. * Back-end widget form. 
  56. * @param array $instance 
  57. * @return null 
  58. * @see WP_Widget::form() 
  59. */ 
  60. public function form( $instance ) { 
  61.  
  62. $instance = wp_parse_args( (array) $instance, $this->widget_defaults ); ?> 
  63.  
  64. <!-- Title --> 
  65. <p> 
  66. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Widget Title', 'gpr' ); ?></label> 
  67. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" 
  68. name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $instance['title']; ?>" /> 
  69. </p> 
  70.  
  71.  
  72. <?php 
  73. //Query Give Forms 
  74. $args = array( 
  75. 'post_type' => 'google_maps',  
  76. 'posts_per_page' => - 1,  
  77. 'post_status' => 'publish',  
  78. ); 
  79. $gmb_forms = get_posts( $args ); 
  80. ?> 
  81. <p> 
  82. <label for="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"><?php _e( 'Select a Map:', 'google-maps-builder' ); ?> 
  83. <span class="dashicons gmb-tooltip-icon" data-tooltip="<?php _e( 'Select a map that you would like to embed in this widget area.', 'google-maps-builder' ); ?>"></span> 
  84. </label> 
  85. <select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'id' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"> 
  86. <option value="current"><?php _e( 'Please select...', 'google-maps-builder' ); ?></option> 
  87. <?php foreach ( $gmb_forms as $gmb_form ) { ?> 
  88. <option <?php selected( absint( $instance['id'] ), $gmb_form->ID ); ?> value="<?php echo esc_attr( $gmb_form->ID ); ?>"><?php echo $gmb_form->post_title; ?></option> 
  89. <?php } ?> 
  90. </select> 
  91. </p> 
  92. <!-- Give Form Field --> 
  93.  
  94. <?php 
  95. /** 
  96. * Runs at end of the widget admin form 
  97. * @since 2.1.0 
  98. */ 
  99. do_action( 'gmb_after_widget_form' ); 
  100. } //end form function 
  101.  
  102.  
  103. /** 
  104. * Front-end display of widget. 
  105. * @see WP_Widget::widget() 
  106. * @param array $args Widget arguments. 
  107. * @param array $instance Saved values from database. 
  108. */ 
  109. public function widget( $args, $instance ) { 
  110.  
  111. echo $args['before_widget']; 
  112.  
  113. do_action( 'gmb_before_forms_widget' ); 
  114.  
  115. if ( ! empty( $instance['title'] ) ) { 
  116. echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title']; 
  117.  
  118. $atts = array( 
  119. 'id' => $instance['id'],  
  120. ); 
  121.  
  122. //Ensure a map has been set 
  123. if ( $instance['id'] !== 'current' ) { 
  124. echo Google_Maps_Builder()->engine->google_maps_shortcode( $atts ); 
  125.  
  126. echo $args['after_widget']; 
  127.  
  128. /** 
  129. * Runs at end of the widget front-end display 
  130. * @since 2.1.0 
  131. */ 
  132. do_action( 'gmb_after_forms_widget' ); 
  133.  
  134.  
  135.  
  136. /** 
  137. * Updates the widget options via foreach loop 
  138. * @DESC: Saves the widget options 
  139. * @SEE WP_Widget::update 
  140. */ 
  141. function update( $new_instance, $old_instance ) { 
  142. $instance = $old_instance; 
  143. //loop through options array and save to new instance 
  144. foreach ( $this->widget_defaults as $field => $value ) { 
  145. $instance[ $field ] = strip_tags( stripslashes( $new_instance[ $field ] ) ); 
  146.  
  147. return $instance; 
  148.  
  149.  
  150.