Google_Maps_Builder_Admin

Class Google_Maps_Builder_Admin.

Defined (1)

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

/includes/admin/class-gmb-admin.php  
  1. class Google_Maps_Builder_Admin extends Google_Maps_Builder_Core_Admin { 
  2.  
  3. /** 
  4. * Instance of this class. 
  5. * @since 1.0.0 
  6. * @var object 
  7. */ 
  8. protected static $instance = null; 
  9.  
  10. /** 
  11. * Initialize the plugin by loading admin scripts & styles and adding a 
  12. * settings page and menu. 
  13. * @since 1.0.0 
  14. */ 
  15. public function __construct() { 
  16.  
  17. parent::__construct(); 
  18.  
  19. add_action( 'cmb2_render_google_maps_preview', array( $this, 'cmb2_render_google_maps_preview' ), 10, 2 ); 
  20. // Load admin style sheet and JavaScript. 
  21. add_action( 'wp_ajax_hide_welcome', array( $this, 'hide_welcome_callback' ) ); 
  22.  
  23. //Add links/information to plugin row meta 
  24. add_filter( 'cmb2_get_metabox_form_format', array( $this, 'gmb_modify_cmb2_form_output' ), 10, 3 ); 
  25.  
  26. //Widget upsell 
  27. add_action( 'gmb_after_widget_form', array( $this, 'widget_upsell' ) ); 
  28.  
  29. //Useful class for free-only styling 
  30. add_filter( 'admin_body_class', array( $this, 'admin_body_classes' ) ); 
  31.  
  32.  
  33. /** 
  34. * Custom Google Geocoder field 
  35. * @since 1.0.0 
  36. */ 
  37. function cmb2_render_google_maps_preview( $field, $meta ) { 
  38.  
  39. /** @var $post */ 
  40. global $post; 
  41.  
  42. $meta = wp_parse_args( $meta, array() ); 
  43. $wh_value = get_post_meta( $post->ID, 'gmb_width_height', true ); 
  44. $lat_lng = get_post_meta( $post->ID, 'gmb_lat_lng', true ); 
  45. $default_options = $this->get_default_map_options(); 
  46.  
  47. $output = '<div class="places-loading wpgp-loading">' . __( 'Loading Places', 'google-maps-builder' ) . '</div><div id="google-map-wrap">'; 
  48. $output .= '<div id="map" style="height:600px; width:100%;"></div>'; 
  49.  
  50. $output .= '<div class="map-modal-upsell"><p class="upsell-intro">' . __( 'Want more?', 'google-maps-builder' ) . '</p><a href="https://wordimpress.com/plugins/maps-builder-pro?utm_source=MBF&utm_medium=BANNER&utm_content=MODAL&utm_campaign=MBF%20Modal" class="button button-small upsell-button" target="_blank">' . __( 'Go Pro!', 'google-maps-builder' ) . '</a></div>'; 
  51.  
  52. //Toolbar 
  53. $output .= '<div id="map-toolbar">'; 
  54. $output .= '<button class="add-location button button-small gmb-magnific-inline" data-target="cmb2-id-gmb-geocoder" data-auto-focus="true"><span class="dashicons dashicons-pressthis"></span>' . __( 'Add Location', 'google-maps-builder' ) . '</button>'; 
  55. $output .= '<button class="drop-marker button button-small"><span class="dashicons dashicons-location"></span>' . __( 'Drop a Marker', 'google-maps-builder' ) . '</button>'; 
  56. $output .= '<button class="goto-location button button-small gmb-magnific-inline" data-target="map-autocomplete-wrap" data-auto-focus="true"><span class="dashicons dashicons-admin-site"></span>' . __( 'Goto Location', 'google-maps-builder' ) . '</button>'; 
  57. $output .= '<button class="edit-title button button-small gmb-magnific-inline" data-target="map-title-wrap" data-auto-focus="true"><span class="dashicons dashicons-edit"></span>' . __( 'Edit Map Title', 'google-maps-builder' ) . '</button>'; 
  58.  
  59. $output .= '<div class="live-lat-lng-wrap clearfix">'; 
  60. $output .= '<button disabled class="update-lat-lng button button-small">' . __( 'Set Lat/Lng', 'google-maps-builder' ) . '</button>'; 
  61. $output .= '<div class="live-latitude-wrap"><span class="live-latitude-label">' . __( 'Lat:', 'google-maps-builder' ) . '</span><span class="live-latitude">' . ( isset( $lat_lng['latitude'] ) ? $lat_lng['latitude'] : '' ) . '</span></div>'; 
  62. $output .= '<div class="live-longitude-wrap"><span class="live-longitude-label">' . __( 'Lng:', 'google-maps-builder' ) . '</span><span class="live-longitude">' . ( isset( $lat_lng['longitude'] ) ? $lat_lng['longitude'] : '' ) . '</span></div>'; 
  63. $output .= '</div>'; //End .live-lat-lng-wrap 
  64. $output .= '</div>'; //End #map-toolbar 
  65. $output .= '</div>'; //End #map 
  66.  
  67.  
  68. //@TODO: Obviously Need Wrapper function 
  69. $output .= '<div class="white-popup mfp-hide map-title-wrap">'; 
  70. $output .= '<div class="inner-modal-wrap">'; 
  71. $output .= '<div class="inner-modal-container">'; 
  72. $output .= '<div class="inner-modal clearfix">'; 
  73. $output .= '<label for="post_title" class="map-title">' . __( 'Map Title', 'google-maps-builder' ) . '</label>'; 
  74. $output .= '<p class="cmb2-metabox-description">' . __( 'Give your Map a descriptive title', 'google-maps-builder' ) . '</p>'; 
  75. $output .= '<button type="button" class="gmb-modal-close">×</button><input type="text" name="model_post_title" size="30" value="' . get_the_title() . '" id="modal_title" spellcheck="true" autocomplete="off" placeholder="' . __( 'Enter map title', 'google-maps-builder' ) . '">'; 
  76. $output .= '</div>'; 
  77. $output .= '</div>'; 
  78. $output .= '</div>'; 
  79. $output .= '</div>'; 
  80.  
  81. $output .= '<div class="white-popup mfp-hide map-autocomplete-wrap">'; 
  82. $output .= '<div class="inner-modal-wrap">'; 
  83. $output .= '<div class="inner-modal-container">'; 
  84. $output .= '<div class="inner-modal clearfix">'; 
  85. $output .= '<label for="map-location-autocomplete" class="map-title">' . __( 'Enter a Location', 'google-maps-builder' ) . '</label>'; 
  86. $output .= '<p class="cmb2-metabox-description">' . __( 'Type your point of interest below and the map will be re-centered over that location', 'google-maps-builder' ) . '</p>'; 
  87. $output .= '<button type="button" class="gmb-modal-close">×</button>'; 
  88. $output .= '<input type="text" name="" size="30" id="map-location-autocomplete">'; 
  89. $output .= '</div>'; 
  90. $output .= '</div>'; 
  91. $output .= '</div>'; 
  92. $output .= '</div>'; 
  93.  
  94. $output .= '<div class="warning-message wpgp-message"></div>'; 
  95.  
  96. //Markers Modal 
  97. gmb_include_view( 'admin/views/markers.php', false, $this->view_data() ); 
  98.  
  99. echo apply_filters( 'google_maps_preview', $output ); 
  100.  
  101.  
  102. /** 
  103. * Modify CMB2 Default Form Output 
  104. * @param string @args 
  105. * @since 2.0 
  106. * @param $form_format 
  107. * @param $object_id 
  108. * @param $cmb 
  109. * @return string 
  110. */ 
  111. function gmb_modify_cmb2_form_output( $form_format, $object_id, $cmb ) { 
  112.  
  113. //only modify the give settings form 
  114. if ( 'gmb_settings' == $object_id && 'plugin_options' == $cmb->cmb_id ) { 
  115.  
  116. return '<form class="cmb-form" method="post" id="%1$s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="object_id" value="%2$s">%3$s<div class="gmb-submit-wrap"><input type="submit" name="submit-cmb" value="' . __( 'Save Settings', 'give' ) . '" class="button-primary"></div></form>'; 
  117.  
  118. return $form_format; 
  119.  
  120.  
  121.  
  122. /** 
  123. * Add upsell to the widget form 
  124. * @since 2.1.0 
  125. * @uses "gmb_after_widget_form" action 
  126. */ 
  127. public function widget_upsell() { 
  128. ?> 
  129. <div class="gmb-widget-upgrade clear"> 
  130. <span class="powered-by"></span> 
  131. <a href="https://wordimpress.com/plugins/maps-builder-pro?utm_source=MBF&utm_medium=BANNER&utm_content=WIDGET&utm_campaign=MBF%20Widgets" target="_blank" class="button button-small"> 
  132. <?php _e( 'Upgrade to Pro', 'google-maps-builder' ); ?> 
  133. <span class="new-window"></span> 
  134. </a> 
  135. </div> 
  136. <?php 
  137.  
  138.  
  139.  
  140. /** 
  141. * Adds a Free 
  142. * @param String $classes Current body classes. 
  143. * @return String Altered body classes. 
  144. */ 
  145. function admin_body_classes( $classes ) { 
  146.  
  147. global $post; 
  148.  
  149. if ( isset( $post->post_type ) && $post->post_type == 'google_maps' ) { 
  150. $classes .= 'maps-builder-free'; 
  151.  
  152. return $classes; 
  153.  
  154.  
  155.  
  156. } //end class