Google_Maps_Builder_Core_Admin

Class Google_Maps_Builder_Core_Admin.

Defined (1)

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

/vendor/wordimpress/maps-builder-core/includes/admin/class-gmc-admin.php  
  1. abstract class Google_Maps_Builder_Core_Admin extends Google_Maps_Builder_Core_Interface { 
  2.  
  3. /** 
  4. * Markerbox CMB2 object. 
  5. * @since 2.1.0 
  6. * @var CMB2 
  7. */ 
  8. protected $marker_box; 
  9.  
  10. /** 
  11. * Markerbox group field ID. 
  12. * @since 2.1.0 
  13. * @var string 
  14. */ 
  15. protected $marker_box_group_field_id; 
  16.  
  17. /** 
  18. * Search options CMB2 object. 
  19. * @since 2.1.0 
  20. * @var CMB2 
  21. */ 
  22. protected $search_options; 
  23.  
  24. /** 
  25. * Display options CMB2 object. 
  26. * @since 2.1.0 
  27. * @var CMB2 
  28. */ 
  29. protected $display_options; 
  30.  
  31. /** 
  32. * Control options CMB2 object. 
  33. * @since 2.1.0 
  34. * @var CMB2 
  35. */ 
  36. protected $control_options; 
  37.  
  38. /** 
  39. * Initialize the plugin by loading admin scripts & styles and adding a settings page and menu. 
  40. * @since 1.0.0 
  41. */ 
  42. public function __construct() { 
  43. parent::__construct(); 
  44.  
  45. //CPT 
  46. add_filter( 'manage_edit-google_maps_columns', array( $this, 'setup_custom_columns' ) ); 
  47. add_action( 'manage_google_maps_posts_custom_column', array( $this, 'configure_custom_columns' ), 10, 2 ); 
  48. add_filter( 'get_user_option_closedpostboxes_google_maps', array( $this, 'closed_meta_boxes' ) ); 
  49.  
  50. //Custom Meta Fields 
  51. add_action( 'cmb2_render_google_geocoder', array( $this, 'cmb2_render_google_geocoder' ), 10, 2 ); 
  52. add_action( 'cmb2_render_google_maps_preview', array( $this, 'cmb2_render_google_maps_preview' ), 10, 2 ); 
  53. // add_action( 'cmb2_render_destination_point', array( $this, 'cmb2_render_destination_point' ), 10, 5 ); 
  54. // add_action( 'cmb2_sanitize_destination_point', array( $this, 'cmb2_sanitize_destination_point' ), 10, 5 ); 
  55. add_action( 'cmb2_render_search_options', array( $this, 'cmb2_render_search_options' ), 10, 2 ); 
  56. add_action( 'cmb2_render_width_height', array( $this, 'cmb2_render_width_height' ), 10, 2 ); 
  57. add_action( 'cmb2_render_lat_lng', array( $this, 'cmb2_render_lat_lng' ), 10, 2 ); 
  58. add_action( 'post_submitbox_misc_actions', array( $this, 'gmb_add_shortcode_to_publish_metabox' ) ); 
  59.  
  60. //Add metaboxes and fields to CPT 
  61. add_action( 'cmb2_init', array( $this, 'cpt2_metaboxes_fields' ) ); 
  62.  
  63.  
  64. /** 
  65. * Add Shortcode to Publish Metabox 
  66. * @return bool 
  67. */ 
  68. public function gmb_add_shortcode_to_publish_metabox() { 
  69.  
  70. if ( 'google_maps' !== get_post_type() ) { 
  71. return false; 
  72.  
  73. global $post; 
  74.  
  75. //Only enqueue scripts for CPT on post type screen 
  76. if ( 'google_maps' === $post->post_type ) { 
  77. echo '<a href="#" class="button disabled button-primary" id="map-builder"><span class="dashicons dashicons-location-alt"></span>' . __( 'Open Map Builder', 'google-maps-builder' ) . '</a>'; 
  78. //Shortcode column with select all input 
  79. $shortcode = htmlentities( '[google_maps id="' . $post->ID . '"]' ); 
  80. echo '<div class="shortcode-wrap box-sizing"><label>' . __( 'Map Shortcode:', 'google-maps-builder' ) . '</label><input onClick="this.setSelectionRange(0, this.value.length)" type="text" class="shortcode-input" readonly value="' . $shortcode . '"></div>'; 
  81.  
  82.  
  83. return false; 
  84.  
  85. /** 
  86. * Get Default Map Options. 
  87. * Helper function that returns default map options from settings. 
  88. * @return array 
  89. */ 
  90. public function get_default_map_options() { 
  91.  
  92. $width_height = gmb_get_option( 'gmb_width_height' ); 
  93.  
  94. $defaults = array( 
  95. 'width' => ( isset( $width_height['width'] ) ) ? $width_height['width'] : '100',  
  96. 'width_unit' => ( isset( $width_height['map_width_unit'] ) ) ? $width_height['map_width_unit'] : '%',  
  97. 'height' => ( isset( $width_height['height'] ) ) ? $width_height['height'] : '600',  
  98. 'height_unit' => ( isset( $width_height['map_height_unit'] ) ) ? $width_height['map_height_unit'] : 'px' 
  99. ); 
  100.  
  101. return $defaults; 
  102.  
  103.  
  104. /** 
  105. * Register our settings with WP. 
  106. * @since 1.0 
  107. */ 
  108. public function settings_init() { 
  109. register_setting( 'google-maps-builder', 'google-maps-builder' ); 
  110.  
  111. /** 
  112. * Defines the Google Places CPT metabox and field configuration. 
  113. * @since 1.0.0 
  114. * @return array 
  115. */ 
  116. public function cpt2_metaboxes_fields() { 
  117.  
  118. $prefix = 'gmb_'; 
  119.  
  120. $default_options = $this->get_default_map_options(); 
  121.  
  122. // Google map preview. 
  123. $preview_box = cmb2_get_metabox( array( 
  124. 'id' => 'google_maps_preview_metabox',  
  125. 'title' => __( 'Google Map Preview', 'google-maps-builder' ),  
  126. 'object_types' => array( 'google_maps' ), // post type 
  127. 'context' => 'normal', // 'normal', 'advanced', or 'side' 
  128. 'priority' => 'high', // 'high', 'core', 'default' or 'low' 
  129. 'show_names' => false, // Show field names on the left 
  130. ) ); 
  131. $preview_box->add_field( array( 
  132. 'name' => __( 'Map Preview', 'google-maps-builder' ),  
  133. 'id' => $prefix . 'preview',  
  134. 'type' => 'google_maps_preview',  
  135. 'default' => '',  
  136. ) ); 
  137.  
  138. // Google maps markers. 
  139. $this->marker_box = cmb2_get_metabox( array( 
  140. 'id' => 'google_maps_markers',  
  141. 'title' => __( 'Map Markers', 'google-maps-builder' ),  
  142. 'object_types' => array( 'google_maps' ), // post type 
  143. 'context' => 'normal', // 'normal', 'advanced', or 'side' 
  144. 'priority' => 'high', // 'high', 'core', 'default' or 'low' 
  145. 'show_names' => true, // Show field names on the left 
  146. ) ); 
  147. $this->marker_box->add_field( array( 
  148. 'name' => __( 'Create Marker', 'google-maps-builder' ),  
  149. 'id' => $prefix . 'geocoder',  
  150. 'type' => 'google_geocoder' 
  151. ) ); 
  152.  
  153. $this->marker_box_group_field_id = $this->marker_box->add_field( array( 
  154. 'name' => __( 'Existing Markers', 'google-maps-builder' ),  
  155. 'id' => $prefix . 'markers_group',  
  156. 'type' => 'group',  
  157. 'description' => __( 'Map marker data is contained within the repeatable fields below. You may add or update marker data here or directly on the map.', 'google-maps-builder' ) . '<a href="#" class="button button-small toggle-repeater-groups">' . __( 'Toggle Marker Groups', 'google-maps-builder' ) . '</a>',  
  158. 'options' => array( 
  159. 'group_title' => __( 'Marker: {#}', 'cmb' ),  
  160. 'add_button' => __( 'Add Another Marker', 'google-maps-builder' ),  
  161. 'remove_button' => __( 'Remove Marker', 'google-maps-builder' ),  
  162. 'sortable' => true, // beta 
  163. ),  
  164. ) ); 
  165. $this->marker_box->add_group_field( $this->marker_box_group_field_id, array( 
  166. 'name' => __( 'Marker Title', 'google-maps-builder' ),  
  167. 'id' => 'title',  
  168. 'type' => 'text',  
  169. ) ); 
  170. $this->marker_box->add_group_field( $this->marker_box_group_field_id, array( 
  171. 'name' => __( 'Marker Description', 'google-maps-builder' ),  
  172. 'description' => __( 'Write a short description for this marker', 'google-maps-builder' ),  
  173. 'id' => 'description',  
  174. 'type' => 'textarea_small',  
  175. 'sanitization_cb' => false 
  176. ) ); 
  177. $this->marker_box->add_group_field( $this->marker_box_group_field_id, array( 
  178. 'name' => __( 'Marker Reference', 'google-maps-builder' ),  
  179. 'id' => 'reference',  
  180. 'type' => 'text',  
  181. ) ); 
  182. $this->marker_box->add_group_field( $this->marker_box_group_field_id, array( 
  183. 'name' => __( 'Marker Place ID', 'google-maps-builder' ),  
  184. 'id' => 'place_id',  
  185. 'type' => 'text',  
  186. ) ); 
  187. $this->marker_box->add_group_field( $this->marker_box_group_field_id, array( 
  188. 'name' => __( 'Hide Place Details', 'google-maps-builder' ),  
  189. 'id' => 'hide_details',  
  190. 'type' => 'checkbox',  
  191. ) ); 
  192. $this->marker_box->add_group_field( $this->marker_box_group_field_id, array( 
  193. 'name' => __( 'Marker Latitude', 'google-maps-builder' ),  
  194. 'id' => 'lat',  
  195. 'type' => 'text',  
  196. ) ); 
  197. $this->marker_box->add_group_field( $this->marker_box_group_field_id, array( 
  198. 'name' => __( 'Marker Longitude', 'google-maps-builder' ),  
  199. 'id' => 'lng',  
  200. 'type' => 'text',  
  201. ) ); 
  202. $this->marker_box->add_group_field( $this->marker_box_group_field_id, array( 
  203. 'name' => __( 'Custom Marker Image', 'google-maps-builder' ),  
  204. 'id' => 'marker_img',  
  205. 'row_classes' => 'gmb-hidden',  
  206. 'type' => 'file',  
  207. 'options' => array( 
  208. 'url' => false,  
  209. 'add_upload_file_text' => __( 'Add Marker Image', 'google-maps-builder' ) 
  210. ),  
  211. ) ); 
  212. $this->marker_box->add_group_field( $this->marker_box_group_field_id, array( 
  213. 'name' => __( 'Included Marker Icon', 'google-maps-builder' ),  
  214. 'row_classes' => 'gmb-hidden',  
  215. 'id' => 'marker_included_img',  
  216. 'type' => 'text',  
  217. ) ); 
  218. $this->marker_box->add_group_field( $this->marker_box_group_field_id, array( 
  219. 'name' => __( 'Marker Data', 'google-maps-builder' ),  
  220. 'row_classes' => 'gmb-hidden',  
  221. 'id' => 'marker',  
  222. 'type' => 'textarea_code',  
  223. ) ); 
  224. $this->marker_box->add_group_field( $this->marker_box_group_field_id, array( 
  225. 'name' => __( 'Marker Label Data', 'google-maps-builder' ),  
  226. 'row_classes' => 'gmb-hidden',  
  227. 'id' => 'label',  
  228. 'type' => 'textarea_code',  
  229. ) ); 
  230.  
  231. // Search options. 
  232. $this->search_options = cmb2_get_metabox( array( 
  233. 'id' => 'google_maps_search_options',  
  234. 'title' => __( 'Google Places', 'google-maps-builder' ),  
  235. 'object_types' => array( 'google_maps' ), // post type 
  236. 'context' => 'normal', // 'normal', 'advanced', or 'side' 
  237. 'priority' => 'core', // 'high', 'core', 'default' or 'low' 
  238. 'show_names' => true, // Show field names on the left 
  239. ) ); 
  240.  
  241. $this->search_options->add_field( 
  242. array( 
  243. 'name' => __( 'Show Places?', 'google-maps-builder' ),  
  244. 'desc' => __( 'Display establishments, prominent points of interest, geographic locations, and more.', 'google-maps-builder' ),  
  245. 'id' => $prefix . 'show_places',  
  246. 'type' => 'radio_inline',  
  247. 'options' => array( 
  248. 'yes' => __( 'Yes', 'cmb' ),  
  249. 'no' => __( 'No', 'cmb' ),  
  250. ),  
  251. ); 
  252.  
  253. $this->search_options->add_field( 
  254. array( 
  255. 'name' => __( 'Search Radius', 'google-maps-builder' ),  
  256. 'desc' => __( 'Defines the distance (in meters) within which to return Place markers. The maximum allowed radius is 50, 000 meters.', 'google-maps-builder' ),  
  257. 'default' => '3000',  
  258. 'id' => $prefix . 'search_radius',  
  259. 'type' => 'text_small' 
  260. ); 
  261.  
  262. $this->search_options->add_field( 
  263. array( 
  264. 'name' => __( 'Place Types', 'google-maps-builder' ),  
  265. 'desc' => __( 'Select which type of places you would like to display on this map.', 'google-maps-builder' ),  
  266. 'id' => $prefix . 'places_search_multicheckbox',  
  267. 'type' => 'multicheck',  
  268. 'options' => apply_filters( 'gmb_place_types', array( 
  269. 'accounting' => __( 'Accounting', 'google-maps-builder' ),  
  270. 'airport' => __( 'Airport', 'google-maps-builder' ),  
  271. 'amusement_park' => __( 'Amusement Park', 'google-maps-builder' ),  
  272. 'aquarium' => __( 'Aquarium', 'google-maps-builder' ),  
  273. 'art_gallery' => __( 'Art Gallery', 'google-maps-builder' ),  
  274. 'atm' => __( 'ATM', 'google-maps-builder' ),  
  275. 'bakery' => __( 'Bakery', 'google-maps-builder' ),  
  276. 'bank' => __( 'Bank', 'google-maps-builder' ),  
  277. 'bar' => __( 'Bar', 'google-maps-builder' ),  
  278. 'beauty_salon' => __( 'Beauty Salon', 'google-maps-builder' ),  
  279. 'bicycle_store' => __( 'Bicycle Store', 'google-maps-builder' ),  
  280. 'book_store' => __( 'Book Store', 'google-maps-builder' ),  
  281. 'bowling_alley' => __( 'Bowling Alley', 'google-maps-builder' ),  
  282. 'bus_station' => __( 'Bus Station', 'google-maps-builder' ),  
  283. 'cafe' => __( 'Cafe', 'google-maps-builder' ),  
  284. 'campground' => __( 'Campground', 'google-maps-builder' ),  
  285. 'car_dealer' => __( 'Car Dealer', 'google-maps-builder' ),  
  286. 'car_rental' => __( 'Car Rental', 'google-maps-builder' ),  
  287. 'car_repair' => __( 'Car Repair', 'google-maps-builder' ),  
  288. 'car_wash' => __( 'Car Wash', 'google-maps-builder' ),  
  289. 'casino' => __( 'Casino', 'google-maps-builder' ),  
  290. 'cemetery' => __( 'Cemetery', 'google-maps-builder' ),  
  291. 'church' => __( 'Church', 'google-maps-builder' ),  
  292. 'city_hall' => __( 'City Hall', 'google-maps-builder' ),  
  293. 'clothing_store' => __( 'Clothing Store', 'google-maps-builder' ),  
  294. 'convenience_store' => __( 'Convenience Store', 'google-maps-builder' ),  
  295. 'courthouse' => __( 'Courthouse', 'google-maps-builder' ),  
  296. 'dentist' => __( 'Dentist', 'google-maps-builder' ),  
  297. 'department_store' => __( 'Department Store', 'google-maps-builder' ),  
  298. 'doctor' => __( 'Doctor', 'google-maps-builder' ),  
  299. 'electrician' => __( 'Electrician', 'google-maps-builder' ),  
  300. 'electronics_store' => __( 'Electronics Store', 'google-maps-builder' ),  
  301. 'embassy' => __( 'Embassy', 'google-maps-builder' ),  
  302. 'establishment' => __( 'Establishment', 'google-maps-builder' ),  
  303. 'finance' => __( 'Finance', 'google-maps-builder' ),  
  304. 'fire_station' => __( 'Fire Station', 'google-maps-builder' ),  
  305. 'florist' => __( 'Florist', 'google-maps-builder' ),  
  306. 'food' => __( 'Food', 'google-maps-builder' ),  
  307. 'funeral_home' => __( 'Funeral Home', 'google-maps-builder' ),  
  308. 'furniture_store' => __( 'Furniture_store', 'google-maps-builder' ),  
  309. 'gas_station' => __( 'Gas Station', 'google-maps-builder' ),  
  310. 'general_contractor' => __( 'General Contractor', 'google-maps-builder' ),  
  311. 'grocery_or_supermarket' => __( 'Grocery or Supermarket', 'google-maps-builder' ),  
  312. 'gym' => __( 'Gym', 'google-maps-builder' ),  
  313. 'hair_care' => __( 'Hair Care', 'google-maps-builder' ),  
  314. 'hardware_store' => __( 'Hardware Store', 'google-maps-builder' ),  
  315. 'health' => __( 'Health', 'google-maps-builder' ),  
  316. 'hindu_temple' => __( 'Hindu Temple', 'google-maps-builder' ),  
  317. 'home_goods_store' => __( 'Home Goods Store', 'google-maps-builder' ),  
  318. 'hospital' => __( 'Hospital', 'google-maps-builder' ),  
  319. 'insurance_agency' => __( 'Insurance Agency', 'google-maps-builder' ),  
  320. 'jewelry_store' => __( 'Jewelry Store', 'google-maps-builder' ),  
  321. 'laundry' => __( 'Laundry', 'google-maps-builder' ),  
  322. 'lawyer' => __( 'Lawyer', 'google-maps-builder' ),  
  323. 'library' => __( 'Library', 'google-maps-builder' ),  
  324. 'liquor_store' => __( 'Liquor Store', 'google-maps-builder' ),  
  325. 'local_government_office' => __( 'Local Government Office', 'google-maps-builder' ),  
  326. 'locksmith' => __( 'Locksmith', 'google-maps-builder' ),  
  327. 'lodging' => __( 'Lodging', 'google-maps-builder' ),  
  328. 'meal_delivery' => __( 'Meal Delivery', 'google-maps-builder' ),  
  329. 'meal_takeaway' => __( 'Meal Takeaway', 'google-maps-builder' ),  
  330. 'mosque' => __( 'Mosque', 'google-maps-builder' ),  
  331. 'movie_rental' => __( 'Movie Rental', 'google-maps-builder' ),  
  332. 'movie_theater' => __( 'Movie Theater', 'google-maps-builder' ),  
  333. 'moving_company' => __( 'Moving Company', 'google-maps-builder' ),  
  334. 'museum' => __( 'Museum', 'google-maps-builder' ),  
  335. 'night_club' => __( 'Night Club', 'google-maps-builder' ),  
  336. 'painter' => __( 'Painter', 'google-maps-builder' ),  
  337. 'park' => __( 'Park', 'google-maps-builder' ),  
  338. 'parking' => __( 'Parking', 'google-maps-builder' ),  
  339. 'pet_store' => __( 'Pet Store', 'google-maps-builder' ),  
  340. 'pharmacy' => __( 'Pharmacy', 'google-maps-builder' ),  
  341. 'physiotherapist' => __( 'Physiotherapist', 'google-maps-builder' ),  
  342. 'place_of_worship' => __( 'Place of Worship', 'google-maps-builder' ),  
  343. 'plumber' => __( 'Plumber', 'google-maps-builder' ),  
  344. 'police' => __( 'Police', 'google-maps-builder' ),  
  345. 'post_office' => __( 'Post Office', 'google-maps-builder' ),  
  346. 'real_estate_agency' => __( 'Real Estate Agency', 'google-maps-builder' ),  
  347. 'restaurant' => __( 'Restaurant', 'google-maps-builder' ),  
  348. 'roofing_contractor' => __( 'Roofing Contractor', 'google-maps-builder' ),  
  349. 'rv_park' => __( 'RV Park', 'google-maps-builder' ),  
  350. 'school' => __( 'School', 'google-maps-builder' ),  
  351. 'shoe_store' => __( 'Shoe Store', 'google-maps-builder' ),  
  352. 'shopping_mall' => __( 'Shopping Mall', 'google-maps-builder' ),  
  353. 'spa' => __( 'Spa', 'google-maps-builder' ),  
  354. 'stadium' => __( 'Stadium', 'google-maps-builder' ),  
  355. 'storage' => __( 'Storage', 'google-maps-builder' ),  
  356. 'store' => __( 'Store', 'google-maps-builder' ),  
  357. 'subway_station' => __( 'Subway Station', 'google-maps-builder' ),  
  358. 'synagogue' => __( 'Synagogue', 'google-maps-builder' ),  
  359. 'taxi_stand' => __( 'Taxi Stand', 'google-maps-builder' ),  
  360. 'train_station' => __( 'Train Station', 'google-maps-builder' ),  
  361. 'travel_agency' => __( 'Travel Agency', 'google-maps-builder' ),  
  362. 'university' => __( 'University', 'google-maps-builder' ),  
  363. 'veterinary_care' => __( 'Veterinary Care', 'google-maps-builder' ),  
  364. 'zoo' => __( 'Zoo', 'google-maps-builder' ) 
  365. ) ) 
  366. ); 
  367.  
  368. /** 
  369. * Display Options 
  370. */ 
  371. $this->display_options = cmb2_get_metabox( array( 
  372. 'id' => 'google_maps_options',  
  373. 'title' => __( 'Display Options', 'google-maps-builder' ),  
  374. 'object_types' => array( 'google_maps' ), // post type 
  375. 'context' => 'side', // 'normal', 'advanced', or 'side' 
  376. 'priority' => 'default', // 'high', 'core', 'default' or 'low' 
  377. 'show_names' => true, // Show field names on the left 
  378. ) ); 
  379.  
  380. $this->display_options->add_field( array( 
  381. 'name' => __( 'Map Size', 'google-maps-builder' ),  
  382. 'id' => $prefix . 'width_height',  
  383. 'type' => 'width_height',  
  384. 'width_std' => $default_options['width'],  
  385. 'width_unit_std' => $default_options['width_unit'],  
  386. 'height_std' => $default_options['height'],  
  387. 'desc' => '',  
  388. ) ); 
  389. $this->display_options->add_field( array( 
  390. 'name' => __( 'Map Location', 'google-maps-builder' ),  
  391. 'id' => $prefix . 'lat_lng',  
  392. 'type' => 'lat_lng',  
  393. 'lat_std' => '',  
  394. 'lng_std' => '',  
  395. 'desc' => '',  
  396. ) ); 
  397. $this->display_options->add_field( array( 
  398. 'name' => __( 'Map Type', 'google-maps-builder' ),  
  399. 'id' => $prefix . 'type',  
  400. 'type' => 'select',  
  401. 'default' => 'default',  
  402. 'options' => array( 
  403. 'RoadMap' => __( 'Road Map', 'google-maps-builder' ),  
  404. 'Satellite' => __( 'Satellite', 'google-maps-builder' ),  
  405. 'Hybrid' => __( 'Hybrid', 'google-maps-builder' ),  
  406. 'Terrain' => __( 'Terrain', 'google-maps-builder' ) 
  407. ),  
  408. ) ); 
  409. $this->display_options->add_field( array( 
  410. 'name' => 'Zoom',  
  411. 'desc' => __( 'Adjust the map zoom (0-21)', 'google-maps-builder' ),  
  412. 'id' => $prefix . 'zoom',  
  413. 'type' => 'select',  
  414. 'default' => '15',  
  415. 'options' => apply_filters( 'gmb_map_zoom_levels', array( 
  416. '21' => '21',  
  417. '20' => '20',  
  418. '19' => '19',  
  419. '18' => '18',  
  420. '17' => '17',  
  421. '16' => '16',  
  422. '15' => '15',  
  423. '14' => '14',  
  424. '13' => '13',  
  425. '12' => '12',  
  426. '11' => '11',  
  427. '10' => '10',  
  428. '9' => '9',  
  429. '8' => '8',  
  430. '7' => '7',  
  431. '6' => '6',  
  432. '5' => '5',  
  433. '4' => '4',  
  434. '3' => '3',  
  435. '2' => '2',  
  436. '1' => '1',  
  437. '0' => '0',  
  438. ) ); 
  439. $this->display_options->add_field( array( 
  440. 'name' => 'Map Layers',  
  441. 'desc' => __( 'Layers provide additional information overlayed on the map.', 'google-maps-builder' ),  
  442. 'id' => $prefix . 'layers',  
  443. 'type' => 'multicheck',  
  444. 'select_all_button' => false,  
  445. 'options' => apply_filters( 'gmb_map_zoom_levels', array( 
  446. 'traffic' => __( 'Traffic', 'google-maps-builder' ),  
  447. 'transit' => __( 'Transit', 'google-maps-builder' ),  
  448. 'bicycle' => __( 'Bicycle', 'google-maps-builder' ),  
  449. ) ); 
  450.  
  451. $this->display_options->add_field( array( 
  452. 'name' => __( 'Map Theme', 'google-maps-builder' ),  
  453. 'desc' => sprintf( __( 'Set optional preconfigured <a href="%1s" class="snazzy-link new-window" target="_blank">Snazzy Maps</a> styles by selecting from the dropdown above.', 'google-maps-builder' ), esc_url( 'http://snazzymaps.com' ) ),  
  454. 'id' => $prefix . 'theme',  
  455. 'type' => 'select',  
  456. 'default' => 'none',  
  457. 'options' => apply_filters( 'gmb_snazzy_maps', array( 
  458. 'none' => __( 'None', 'google-maps-builder' ),  
  459. '68' => __( 'Aqua', 'google-maps-builder' ),  
  460. '73' => __( 'A Dark World', 'google-maps-builder' ),  
  461. '28' => __( 'Bluish', 'google-maps-builder' ),  
  462. '80' => __( 'Cool Grey', 'google-maps-builder' ),  
  463. '77' => __( 'Clean Cut', 'google-maps-builder' ),  
  464. '36' => __( 'Flat Green', 'google-maps-builder' ),  
  465. '44' => __( 'MapBox', 'google-maps-builder' ),  
  466. '83' => __( 'Muted Blue', 'google-maps-builder' ),  
  467. '22' => __( 'Old Timey', 'google-maps-builder' ),  
  468. '1' => __( 'Pale Dawn', 'google-maps-builder' ),  
  469. '19' => __( 'Paper', 'google-maps-builder' ),  
  470. '37' => __( 'Lunar Landscape', 'google-maps-builder' ),  
  471. '75' => __( 'Shade of Green', 'google-maps-builder' ),  
  472. '27' => __( 'Shift Worker', 'google-maps-builder' ),  
  473. '15' => __( 'Subtle Grayscale', 'google-maps-builder' ),  
  474. '50' => __( 'The Endless Atlas', 'google-maps-builder' ),  
  475. ) ) 
  476. ) ); 
  477. $this->display_options->add_field( array( 
  478. 'name' => __( 'Custom Map Theme JSON', 'google-maps-builder' ),  
  479. 'desc' => __( 'Paste the Snazzy Map JSON code into the field above to set the theme.', 'google-maps-builder' ),  
  480. 'id' => $prefix . 'theme_json',  
  481. 'type' => 'textarea_code' 
  482. ) ); 
  483.  
  484.  
  485. // Control options. 
  486. $this->control_options = cmb2_get_metabox( array( 
  487. 'id' => 'google_maps_control_options',  
  488. 'title' => __( 'Map Controls', 'google-maps-builder' ),  
  489. 'object_types' => array( 'google_maps' ), // post type 
  490. 'context' => 'side', // 'normal', 'advanced', or 'side' 
  491. 'priority' => 'default', // 'high', 'core', 'default' or 'low' 
  492. 'show_names' => true, // Show field names on the left 
  493. ) ); 
  494.  
  495. $this->control_options->add_field( array( 
  496. 'name' => __( 'Zoom Control', 'google-maps-builder' ),  
  497. 'id' => $prefix . 'zoom_control',  
  498. 'type' => 'select',  
  499. 'default' => 'default',  
  500. 'options' => array( 
  501. 'none' => __( 'None', 'google-maps-builder' ),  
  502. 'small' => __( 'Small', 'google-maps-builder' ),  
  503. 'large' => __( 'Large', 'google-maps-builder' ),  
  504. 'default' => __( 'Default', 'google-maps-builder' ),  
  505. ),  
  506. ) ); 
  507.  
  508. $this->control_options->add_field( array( 
  509. 'name' => __( 'Street View', 'google-maps-builder' ),  
  510. 'id' => $prefix . 'street_view',  
  511. 'type' => 'select',  
  512. 'default' => 'true',  
  513. 'options' => array( 
  514. 'none' => __( 'None', 'google-maps-builder' ),  
  515. 'true' => __( 'Standard', 'google-maps-builder' ),  
  516. ),  
  517. ) ); 
  518.  
  519. $this->control_options->add_field( array( 
  520. 'name' => __( 'Pan Control', 'google-maps-builder' ),  
  521. 'id' => $prefix . 'pan',  
  522. 'type' => 'select',  
  523. 'default' => 'true',  
  524. 'options' => array( 
  525. 'none' => __( 'None', 'google-maps-builder' ),  
  526. 'true' => __( 'Standard', 'google-maps-builder' ),  
  527. ),  
  528. ) ); 
  529.  
  530. $this->control_options->add_field( array( 
  531. 'name' => __( 'Map Type Control', 'google-maps-builder' ),  
  532. 'id' => $prefix . 'map_type_control',  
  533. 'type' => 'select',  
  534. 'default' => 'horizontal_bar',  
  535. 'options' => array( 
  536. 'none' => __( 'None', 'google-maps-builder' ),  
  537. 'dropdown_menu' => __( 'Dropdown Menu', 'google-maps-builder' ),  
  538. 'horizontal_bar' => __( 'Horizontal Bar', 'google-maps-builder' ),  
  539. ),  
  540. ) ); 
  541.  
  542. $this->control_options->add_field( array( 
  543. 'name' => __( 'Draggable Map', 'google-maps-builder' ),  
  544. 'id' => $prefix . 'draggable',  
  545. 'type' => 'select',  
  546. 'default' => 'true',  
  547. 'options' => array( 
  548. 'none' => __( 'None', 'google-maps-builder' ),  
  549. 'true' => __( 'Standard', 'google-maps-builder' ),  
  550. ),  
  551. ) ); 
  552.  
  553. $this->control_options->add_field( array( 
  554. 'name' => __( 'Double Click to Zoom', 'google-maps-builder' ),  
  555. 'id' => $prefix . 'double_click',  
  556. 'type' => 'select',  
  557. 'default' => 'true',  
  558. 'options' => array( 
  559. 'none' => __( 'None', 'google-maps-builder' ),  
  560. 'true' => __( 'Standard', 'google-maps-builder' ),  
  561. ),  
  562. ) ); 
  563.  
  564. $this->control_options->add_field( array( 
  565. 'name' => __( 'Mouse Wheel to Zoom', 'google-maps-builder' ),  
  566. 'id' => $prefix . 'wheel_zoom',  
  567. 'type' => 'select',  
  568. 'default' => 'true',  
  569. 'options' => array( 
  570. 'none' => __( 'Disabled', 'google-maps-builder' ),  
  571. 'true' => __( 'Standard', 'google-maps-builder' ),  
  572. ),  
  573. ) ); 
  574.  
  575.  
  576.  
  577. /** 
  578. * CMB Width Height 
  579. * Custom CMB field for Gmap width and height 
  580. * @param $field 
  581. * @param $meta 
  582. */ 
  583. function cmb2_render_width_height( $field, $meta ) { 
  584. $default_options = $this->get_default_map_options(); 
  585. $meta = wp_parse_args( 
  586. $meta, array( 
  587. 'width' => $default_options['width'],  
  588. 'map_width_unit' => $default_options['width_unit'],  
  589. 'height' => $default_options['height'],  
  590. 'map_height_unit' => $default_options['height_unit'],  
  591. ); 
  592.  
  593. $output = '<div id="width_height_wrap" class="clear">'; 
  594.  
  595. //width 
  596. $output .= '<div id="width_wrap" class="clear">'; 
  597. $output .= '<label class="width-label size-label">' . __( 'Width', 'google-maps-builder' ) . ':</label><input type="text" class="regular-text map-width" name="' . $field->args( 'id' ) . '[width]" id="' . $field->args( 'id' ) . '-width" value="' . ( $meta['width'] ? $meta['width'] : $field->args( 'width_std' ) ) . '" />'; 
  598. $output .= '<div class="size-labels-wrap">'; 
  599. $output .= '<input id="width_unit_percent" type="radio" name="' . $field->args( 'id' ) . '[map_width_unit]" class="width_radio" value="%" ' . ( $meta['map_width_unit'] === '%' || $field->args( 'width_unit_std' ) === '%' ? 'checked="checked"' : '' ) . '><label class="width_unit_label">%</label>'; 
  600. $output .= '<input id="width_unit_px" type="radio" name="' . $field->args( 'id' ) . '[map_width_unit]" class="width_radio" value="px" ' . ( $meta['map_width_unit'] === 'px' ? 'checked="checked"' : '' ) . ' ><label class="width_unit_label">px</label>'; 
  601. $output .= '</div>'; 
  602. $output .= '</div>'; 
  603.  
  604. //height 
  605. $output .= '<div id="height_wrap" class="clear clearfix">'; 
  606. $output .= '<label for="' . $field->args( 'id' ) . '[height]" class="height-label size-label">' . __( 'Height', 'google-maps-builder' ) . ':</label><input type="text" class="regular-text map-height" name="' . $field->args( 'id' ) . '[height]" id="' . $field->args( 'id' ) . '-height" value="' . ( $meta['height'] ? $meta['height'] : $field->args( 'height_std' ) ) . '" />'; 
  607.  
  608. $output .= '<div class="size-labels-wrap">'; 
  609. $output .= '<input id="height_unit_percent" type="radio" name="' . $field->args( 'id' ) . '[map_height_unit]" class="height_radio" value="%" ' . ( $meta['map_height_unit'] === '%' || $field->args( 'height_unit_std' ) === '%' ? 'checked="checked"' : '' ) . '><label class="height_unit_label">%</label>'; 
  610. $output .= '<input id="height_unit_px" type="radio" name="' . $field->args( 'id' ) . '[map_height_unit]" class="height_radio" value="px" ' . ( $meta['map_height_unit'] === 'px' ? 'checked="checked"' : '' ) . ' ><label class="height_unit_label">px</label>'; 
  611. $output .= '</div>'; 
  612. $output .= '</div>'; 
  613.  
  614. $output .= '<p class="cmb2-metabox-description">' . __( 'Configure the default map width and height.', 'google-maps-builder' ) . '</p>'; 
  615.  
  616. $output .= '</div>'; //end #width_height_wrap 
  617.  
  618.  
  619. echo $output; 
  620.  
  621.  
  622.  
  623.  
  624. /** 
  625. * CMB Lat Lng 
  626. * Custom CMB field for Gmap latitude and longitude 
  627. * @param $field 
  628. * @param $meta 
  629. */ 
  630. function cmb2_render_lat_lng( $field, $meta ) { 
  631. $meta = wp_parse_args( 
  632. $meta, array( 
  633. 'latitude' => '',  
  634. 'longitude' => '',  
  635. ); 
  636.  
  637. //lat lng 
  638. $output = '<div id="lat-lng-wrap"> 
  639. <div class="coordinates-wrap clear"> 
  640. <div class="lat-lng-wrap lat-wrap clear"><span>' . __( 'Latitude:', 'google-maps-builder' ) . '</span> 
  641. <input type="text" class="regular-text latitude" name="' . $field->args( 'id' ) . '[latitude]" id="' . $field->args( 'id' ) . '-latitude" value="' . ( $meta['latitude'] ? $meta['latitude'] : $field->args( 'lat_std' ) ) . '" /> 
  642. </div> 
  643. <div class="lat-lng-wrap lng-wrap clear"><span>' . __( 'Longitude:', 'google-maps-builder' ) . '</span> 
  644. <input type="text" class="regular-text longitude" name="' . $field->args( 'id' ) . '[longitude]" id="' . $field->args( 'id' ) . '-longitude" value="' . ( $meta['longitude'] ? $meta['longitude'] : $field->args( 'lng_std' ) ) . '" /> 
  645. </div>'; 
  646. $output .= '<div class="wpgp-message lat-lng-change-message clear"><p>' . __( 'Lat/lng changed', 'google-maps-builder' ) . '</p><a href="#" class="button lat-lng-update-btn button-small" data-lat="" data-lng="">' . __( 'Update', 'google-maps-builder' ) . '</a></div>'; 
  647. $output .= '</div><!-- /.coordinates-wrap --> 
  648. </div>'; 
  649.  
  650.  
  651. echo $output; 
  652.  
  653.  
  654.  
  655. /** 
  656. * Custom Google Geocoder field 
  657. * @since 1.0.0 
  658. * @param $field 
  659. * @param $meta 
  660. * @return array 
  661. */ 
  662. function cmb2_render_google_geocoder( $field, $meta ) { 
  663.  
  664. $meta = wp_parse_args( 
  665. $meta, array( 
  666. 'geocode' => '',  
  667. ); 
  668.  
  669. echo '<div class="autocomplete-wrap"><input type="text" name="' . $field->args( 'id' ) . '[geocode]" id="' . $field->args( 'id' ) . '" value="" class="search-autocomplete" /><p class="autocomplete-description">' . 
  670. sprintf( __( 'Enter the name of a place or an address above to create a map marker or %1$sDrop a Marker%2$s', 'google-maps-builder' ), '<a href="#" class="drop-marker button button-small"><span class="dashicons dashicons-location"></span>', '</a>' ) . 
  671. '</p></div>'; 
  672.  
  673.  
  674. /** 
  675. * Custom Google Geocoder field 
  676. * @since 1.0.0 
  677. */ 
  678. function cmb2_render_google_maps_preview( $field, $meta ) { 
  679. global $post; 
  680. $meta = wp_parse_args( $meta, array() ); 
  681. $wh_value = get_post_meta( $post->ID, 'gmb_width_height', true ); 
  682. $lat_lng = get_post_meta( $post->ID, 'gmb_lat_lng', true ); 
  683. $default_options = $this->get_default_map_options(); 
  684.  
  685.  
  686. $output = '<div class="places-loading wpgp-loading">' . __( 'Loading Places', 'google-maps-builder' ) . '</div>'; 
  687. $output .= '<div id="google-map-wrap">'; 
  688. $output .= '<div id="map" style="height:600px; width:100%;"></div>'; 
  689.  
  690. //Toolbar 
  691. $output .= '<div id="map-toolbar">'; 
  692. $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>'; 
  693. $output .= '<button class="drop-marker button button-small"><span class="dashicons dashicons-location"></span>' . __( 'Drop a Marker', 'google-maps-builder' ) . '</button>'; 
  694. $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>'; 
  695. $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>'; 
  696.  
  697. $output .= '<div class="live-lat-lng-wrap clearfix">'; 
  698. $output .= '<button disabled class="update-lat-lng button button-small">' . __( 'Set Lat/Lng', 'google-maps-builder' ) . '</button>'; 
  699. $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>'; 
  700. $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>'; 
  701. $output .= '</div>'; //End .live-lat-lng-wrap 
  702. $output .= '</div>'; //End #map-toolbar 
  703. $output .= '</div>'; //End #map 
  704.  
  705. $output .= '<div class="white-popup mfp-hide map-title-wrap">'; 
  706. $output .= '<div class="inner-modal-wrap">'; 
  707. $output .= '<div class="inner-modal-container">'; 
  708. $output .= '<div class="inner-modal">'; 
  709. $output .= '<label for="post_title" class="map-title">' . __( 'Map Title', 'google-maps-builder' ) . '</label>'; 
  710. $output .= '<p class="cmb2-metabox-description">' . __( 'Give your Map a descriptive title', 'google-maps-builder' ) . '</p>'; 
  711. $output .= '<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' ) . '">'; 
  712. $output .= '<button type="button" class="gmb-modal-close">×</button>'; 
  713. $output .= '</div>'; 
  714. $output .= '</div>'; 
  715. $output .= '</div>'; 
  716. $output .= '</div>'; 
  717.  
  718. $output .= '<div class="white-popup mfp-hide map-autocomplete-wrap">'; 
  719. $output .= '<div class="inner-modal-wrap">'; 
  720. $output .= '<div class="inner-modal-container">'; 
  721. $output .= '<div class="inner-modal">'; 
  722. $output .= '<label for="map-location-autocomplete" class="map-title">' . __( 'Enter a Location', 'google-maps-builder' ) . '</label>'; 
  723. $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>'; 
  724. $output .= '<button type="button" class="gmb-modal-close">×</button>'; 
  725. $output .= '<input type="text" name="" size="30" id="map-location-autocomplete">'; 
  726. $output .= '</div>'; 
  727. $output .= '</div>'; 
  728. $output .= '</div>'; 
  729. $output .= '</div>'; 
  730.  
  731. //Markers Modal 
  732. gmb_include_view( 'admin/views/markers.php', false, $this->view_data() ); 
  733.  
  734. //Places search 
  735. $output = $this->places_search( $output ); 
  736. echo apply_filters( 'google_maps_preview', $output ); 
  737.  
  738.  
  739.  
  740. /** 
  741. * Setup Custom CPT Columns 
  742. * @param $columns 
  743. * @return array 
  744. */ 
  745. function setup_custom_columns( $columns ) { 
  746. $columns = array( 
  747. 'cb' => '<input type="checkbox" />',  
  748. 'title' => __( 'Google Map Title', 'google-maps-builder' ),  
  749. 'shortcode' => __( 'Shortcode', 'google-maps-builder' ),  
  750. 'date' => __( 'Creation Date', 'google-maps-builder' ) 
  751. ); 
  752.  
  753. return $columns; 
  754.  
  755.  
  756. /** 
  757. * Configure Custom Columns 
  758. * Sets the content of the custom column contents 
  759. * @param $column 
  760. * @param $post_id 
  761. */ 
  762. function configure_custom_columns( $column, $post_id ) { 
  763. switch ( $column ) { 
  764. case 'shortcode' : 
  765.  
  766. //Shortcode column with select all input 
  767. $shortcode = htmlentities( '[google_maps id="' . $post_id . '"]' ); 
  768. echo '<input onClick="this.setSelectionRange(0, this.value.length)" type="text" class="shortcode-input" readonly value="' . $shortcode . '">'; 
  769.  
  770. break; 
  771. /** Just break out of the switch statement for everything else. */ 
  772. default : 
  773. break; 
  774.  
  775.  
  776. /** 
  777. * Close certain metaboxes by default 
  778. * @param $closed 
  779. * @return array 
  780. */ 
  781. function closed_meta_boxes( $closed ) { 
  782.  
  783. if ( false === $closed ) { 
  784. $closed = array( 'google_maps_options', 'google_maps_control_options', 'google_maps_markers' ); 
  785.  
  786. return $closed; 
  787.  
  788. /** 
  789. * Used in pro to add places search to output 
  790. * @since 2.1.0 
  791. * @param $output 
  792. * @return string 
  793. */ 
  794. function places_search( $output ) { 
  795. return $output; 
  796.  
  797.