Google_Maps_Builder_Core_Settings

Class Google_Maps_Builder_Core_Settings.

Defined (1)

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

/vendor/wordimpress/maps-builder-core/includes/admin/class-gmc-settings.php  
  1. abstract class Google_Maps_Builder_Core_Settings extends Google_Maps_Builder_Core_Interface { 
  2.  
  3. /** 
  4. * Array of metaboxes/fields 
  5. * @var array 
  6. */ 
  7. protected $plugin_options = array(); 
  8.  
  9.  
  10. /** 
  11. * @var string 
  12. */ 
  13. public $options_page; 
  14.  
  15. /** 
  16. * Option key, and option page slug 
  17. * @var string 
  18. */ 
  19. protected static $key = 'gmb_settings'; 
  20.  
  21. /** 
  22. * Holds settings page name 
  23. * @since 2.1.0 
  24. * @var string 
  25. */ 
  26. protected $page_name; 
  27.  
  28.  
  29. /** 
  30. * Google_Maps_Builder_Core_Settings constructor. 
  31. */ 
  32. public function __construct() { 
  33.  
  34. parent::__construct(); 
  35. $this->page_name = __( 'Maps Builder Settings', 'google-maps-builder' ); 
  36.  
  37. //Create Settings submenu 
  38. add_action( 'admin_init', array( $this, 'mninit' ) ); 
  39. add_action( 'admin_menu', array( $this, 'add_page' ) ); 
  40.  
  41. // Load admin style sheet and JavaScript. 
  42. add_action( 'wp_ajax_hide_welcome', array( $this, 'hide_welcome_callback' ) ); 
  43.  
  44. //Add links/information to plugin row meta 
  45. add_filter( 'plugin_row_meta', array( $this, 'add_plugin_meta_links' ), 10, 2 ); 
  46. add_filter( 'plugin_action_links', array( $this, 'add_plugin_page_links' ), 10, 2 ); 
  47.  
  48. add_action( 'gmb_settings_tabs', array( $this, 'settings_tabs' ) ); 
  49.  
  50.  
  51.  
  52. /** 
  53. * Register our setting to WP 
  54. * @since 0.1.0 
  55. */ 
  56. public function mninit() { 
  57. register_setting( self::$key, self::$key ); 
  58.  
  59. /** 
  60. * Add menu options page 
  61. * @since 1.0.0 
  62. */ 
  63. public function add_page() { 
  64.  
  65. $this->options_page = add_submenu_page( 
  66. 'edit.php?post_type=google_maps',  
  67. $this->page_name,  
  68. __( 'Settings', 'google-maps-builder' ),  
  69. 'manage_options',  
  70. self::$key,  
  71. array( $this, 'admin_page_display' ) 
  72. ); 
  73.  
  74.  
  75.  
  76. /** 
  77. * Hide the Settings welcome on click 
  78. * Sets a user meta key that once set 
  79. */ 
  80. public function hide_welcome_callback() { 
  81. global $current_user; 
  82. $user_id = $current_user->ID; 
  83. add_user_meta( $user_id, 'gmb_hide_pro_welcome', 'true', true ); 
  84. wp_die(); // ajax call must die to avoid trailing 0 in your response 
  85.  
  86.  
  87. /** 
  88. * Admin Page Display 
  89. * Admin page markup. Mostly handled by CMB 
  90. */ 
  91. public function admin_page_display() { 
  92.  
  93. gmb_include_view( 'admin/views/settings-page.php', false, array_merge( $this->common_settings_page_data(), $this->settings_page_data() ) ); 
  94.  
  95.  
  96. /** 
  97. * Handle main data for the settings page 
  98. * Must override in plugin 
  99. * @since 2.1.0 
  100. * @return array 
  101. */ 
  102. protected function settings_page_data() { 
  103. _doing_it_wrong( __FUNCTION__, __( 'Must override in plugin', 'google-maps-builder' ), '2.1.0' ); 
  104.  
  105. //place holder 
  106. $data = array( 
  107. 'welcome' => '',  
  108. 'sub_heading' => '' 
  109. ); 
  110.  
  111. return $this->view_data( $data, true ); 
  112.  
  113. /** 
  114. * Common data for settings page. 
  115. * @since 2.1.0 
  116. * @return array 
  117. */ 
  118. protected function common_settings_page_data() { 
  119. return array( 
  120. 'plugin_slug' => 'google-maps-builder',  
  121. 'key' => $this->key(),  
  122. 'general_option_fields' => $this->general_option_fields(),  
  123. 'map_option_fields' => $this->map_option_fields() 
  124. ); 
  125.  
  126. /** 
  127. * General Option Fields 
  128. * Defines the plugin option metabox and field configuration 
  129. * @since 1.0.0 
  130. * @return array 
  131. */ 
  132. public function general_option_fields() { 
  133. $prefix = $this->prefix(); 
  134.  
  135. $this->plugin_options = array( 
  136. 'id' => 'plugin_options',  
  137. 'show_on' => array( 'key' => 'options-page', 'value' => array( self::$key, ), ),  
  138. 'show_names' => true,  
  139. 'fields' => array( 
  140. array( 
  141. 'name' => __( 'Post Type Slug', 'google-maps-builder' ),  
  142. 'desc' => sprintf( __( 'Customize the default slug for the Maps Builder post type. %1$sResave (flush) permalinks%2$s after customizing.', 'google-maps-builder' ), '<a href="' . esc_url( '/wp-admin/options-permalink.php' ) . '">"', '</a>' ),  
  143. 'default' => 'google-maps',  
  144. 'id' => $prefix . 'custom_slug',  
  145. 'type' => 'text_small' 
  146. ),  
  147. array( 
  148. 'name' => __( 'Menu Position', 'google-maps-builder' ),  
  149. 'desc' => sprintf( __( 'Set the menu position for Google Maps Builder. See the %1$smenu_position arg%2$s.', 'google-maps-builder' ), '<a href="' . esc_url( 'https://codex.wordpress.org/Function_Reference/register_post_type#menu_position' ) . '" class="new-window" target="_blank">', '</a>' ),  
  150. 'default' => '21.3',  
  151. 'id' => $prefix . 'menu_position',  
  152. 'type' => 'text_small' 
  153. ),  
  154. array( 
  155. 'name' => __( 'Has Archive', 'google-maps-builder' ),  
  156. 'id' => $prefix . 'has_archive',  
  157. 'desc' => sprintf( __( 'Controls the post type archive page. See <a href="%s">Resave (flush) permalinks</a> after customizing.', 'google-maps-builder' ), esc_url( '/wp-admin/options-permalink.php' ) ),  
  158. 'type' => 'radio_inline',  
  159. 'options' => array( 
  160. 'true' => __( 'Yes', 'cmb' ),  
  161. 'false' => __( 'No', 'cmb' ),  
  162. ),  
  163. ),  
  164. array( 
  165. 'name' => __( 'Opening Map Builder', 'google-maps-builder' ),  
  166. 'id' => $prefix . 'open_builder',  
  167. 'desc' => __( 'Do you want the Map Builder customizer to open by default when editing maps?', 'google-maps-builder' ),  
  168. 'type' => 'radio_inline',  
  169. 'options' => array( 
  170. 'true' => __( 'Yes', 'cmb' ),  
  171. 'false' => __( 'No', 'cmb' ),  
  172. ),  
  173. ),  
  174.  
  175. ),  
  176. ); 
  177.  
  178. return apply_filters( 'gmb_general_options_fields', $this->plugin_options ); 
  179.  
  180.  
  181. /** 
  182. * Map Option Fields 
  183. * Defines the plugin option metabox and field configuration 
  184. * @return array 
  185. */ 
  186. public function map_option_fields() { 
  187.  
  188. $prefix = $this->prefix(); 
  189.  
  190. $this->plugin_options = array( 
  191. 'id' => 'plugin_options',  
  192. 'show_on' => array( 'key' => 'options-page', 'value' => array( self::$key, ), ),  
  193. 'show_names' => true,  
  194. 'fields' => array( 
  195. array( 
  196. 'name' => __( 'Google Maps API Key', 'google-maps-builder' ),  
  197. 'desc' => sprintf( __( 'Google now requires a valid Google Maps JavaScript API key to function. <br><a href="%1$s" target="_blank" class="new-window">Learn how to obtain a Google Maps API key</a>.', 'google-maps-builder' ), esc_url( 'https://wordimpress.com/documentation/maps-builder-pro/creating-maps-api-key/' ) ),  
  198. 'id' => $prefix . 'maps_api_key',  
  199. 'type' => 'text',  
  200. ),  
  201. array( 
  202. 'name' => __( 'Map Size', 'google-maps-builder' ),  
  203. 'id' => $prefix . 'width_height',  
  204. 'type' => 'width_height',  
  205. 'width_std' => '100',  
  206. 'width_unit_std' => '%',  
  207. 'height_std' => '600',  
  208. 'lat_std' => '32.7153292',  
  209. 'lng_std' => '-117.15725509',  
  210. 'desc' => '',  
  211. ),  
  212. array( 
  213. 'name' => __( 'Default Location', 'google-maps-builder' ),  
  214. 'id' => $prefix . 'lat_lng',  
  215. 'type' => 'lat_lng_default',  
  216. 'lat_std' => '32.7153292',  
  217. 'lng_std' => '-117.15725509',  
  218. 'desc' => '',  
  219. ),  
  220.  
  221. ),  
  222. ); 
  223.  
  224. return apply_filters( 'gmb_map_options_fields', $this->plugin_options ); 
  225.  
  226.  
  227.  
  228. /** 
  229. * CMB Lat Lng. 
  230. * Custom CMB field for Gmap latitude and longitude. 
  231. * @param $field 
  232. * @param $meta 
  233. */ 
  234. function cmb2_render_lat_lng_default( $field, $meta ) { 
  235.  
  236. $meta = wp_parse_args( 
  237. $meta, array( 
  238. 'geolocate_map' => 'no',  
  239. 'latitude' => '',  
  240. 'longitude' => '',  
  241. ); 
  242.  
  243. //lat_lng 
  244. $output = '<div id="lat-lng-wrap"><div class="coordinates-wrap clear">'; 
  245. $output .= '<div class="lat-lng-wrap lat-wrap clear"><span>' . __( 'Latitude', 'google-maps-builder' ) . ': </span> 
  246. <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'] ) . '" /></div><div class="lat-lng-wrap lng-wrap clear"><span>' . __( 'Longitude', 'google-maps-builder' ) . ': </span> 
  247. <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'] ) . '" /> 
  248. </div>'; 
  249.  
  250. $output .= '<p class="small-desc">' . sprintf( __( 'For quick lat/lng lookup use %1$sthis service%2$s', 'google-maps-builder' ), '<a href="' . esc_url( 'http://www.latlong.net/' ) . '" class="new-window" target="_blank">', '</a>' ) . '</p>'; 
  251. $output .= '</div><!-- /.search-coordinates-wrap -->'; 
  252. $output .= '</div>'; 
  253.  
  254. //Geolocate 
  255. $output .= '<div id="geolocate-wrap" class="clear">'; 
  256. $output .= '<label class="geocode-label size-label">' . __( 'Geolocate Position', 'google-maps-builder' ) . ':</label>'; 
  257. $output .= '<div class="geolocate-radio-wrap size-labels-wrap">'; 
  258. $output .= '<label class="yes-label label-left"><input id="geolocate_map_yes" type="radio" name="' . $field->args['id'] . '[geolocate_map]" class="geolocate_map_radio radio-left" value="yes" ' . ( $meta['geolocate_map'] === 'yes' ? 'checked="checked"' : '' ) . '>' . __( 'Yes', 'google-maps-builder' ) . '</label>'; 
  259.  
  260. $output .= '<label class="no-label label-left"><input id="geolocate_map_no" type="radio" name="' . $field->args['id'] . '[geolocate_map]" class="geolocate_map_radio radio-left" value="no" ' . ( ( $meta['geolocate_map'] === 'no' ) ? 'checked="checked"' : '' ) . ' >' . __( 'No', 'google-maps-builder' ) . '</label>'; 
  261. $output .= '</div>'; 
  262. $output .= '<p class="cmb2-metabox-description clear">' . sprintf( __( 'When creating a new map the plugin will use your current longitude and latitude for the base location. Please note, Chrome 50+ %1$srequires a secure https connection%2$s (SSL certificate) to access geolocation features and other browsers may soon follow suit.', 'google-maps-builder' ), '<a href="https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only" class="new-window" target="_blank">', '</a>' ) . '</p>'; 
  263.  
  264. $output .= '</div><!--/end. geolocate-wrap -->'; 
  265.  
  266. echo $output; 
  267.  
  268.  
  269.  
  270.  
  271. /** 
  272. * Make public the protected $key variable. 
  273. * @since 0.1.0 
  274. * @return string Option key 
  275. */ 
  276. public static function key() { 
  277. return self::$key; 
  278.  
  279.  
  280. /** 
  281. * Add links to Plugin listings view 
  282. * @param $links 
  283. * @return mixed 
  284. */ 
  285. function add_plugin_page_links( $links, $file ) { 
  286.  
  287. if ( $file == GMB_PLUGIN_BASE ) { 
  288.  
  289. // Add Widget Page link to our plugin 
  290. $settings_link = '<a href="edit.php?post_type=google_maps&page=' . self::$key . '" title="' . __( 'Visit the Google Maps Builder plugin settings page', 'google-maps-builder' ) . '">' . __( 'Settings', 'google-maps-builder' ) . '</a>'; 
  291.  
  292. array_unshift( $links, $settings_link ); 
  293.  
  294.  
  295. return $links; 
  296.  
  297. /** 
  298. * Add Plugin Meta Links 
  299. * Adds links on the admin plugin listing page 
  300. * @param $meta 
  301. * @param $file 
  302. * @return array 
  303. */ 
  304. function add_plugin_meta_links( $meta, $file ) { 
  305.  
  306. if ( $file == GMB_PLUGIN_BASE ) { 
  307. $meta[] = "<a href='https://wordpress.org/support/view/plugin-reviews/google-maps-builder' target='_blank' title='" . __( 'Rate Google Maps Builder on WordPress.org', 'google-maps-builder' ) . "'>" . __( 'Rate Plugin', 'google-maps-builder' ) . "</a>"; 
  308. $meta[] = '<a href="https://wordpress.org/support/plugin/google-maps-builder/" target="_blank" title="' . __( 'Get plugin support via the WordPress community', 'google-maps-builder' ) . '">' . __( 'Support', 'google-maps-builder' ) . '</a>'; 
  309.  
  310.  
  311. return $meta; 
  312.  
  313.  
  314. /** 
  315. * Modify CMB2 Default Form Output 
  316. * @param string @args 
  317. * @since 2.0 
  318. * @param $form_format 
  319. * @param $object_id 
  320. * @param $cmb 
  321. * @return string 
  322. */ 
  323. function gmb_modify_cmb2_form_output( $form_format, $object_id, $cmb ) { 
  324.  
  325. //only modify the give settings form 
  326. if ( 'gmb_settings' == $object_id && 'plugin_options' == $cmb->cmb_id ) { 
  327.  
  328. 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>'; 
  329.  
  330. return $form_format; 
  331.  
  332.  
  333. /** 
  334. * Get cmb2 prefix 
  335. * @since 2.1.0 
  336. * @return string 
  337. */ 
  338. protected function prefix() { 
  339. $prefix = 'gmb_'; 
  340.  
  341. return $prefix; 
  342.  
  343. /** 
  344. * Markup for settings tab switcher 
  345. * @since 2.1.0 
  346. * @uses "gmb_settings_tabs" action 
  347. */ 
  348. public function settings_tabs( $active_tab ) { 
  349. gmb_include_view( 'admin/views/settings-tabs.php', false, $this->view_data( $this->tab_settings( $active_tab ), true ) ); 
  350.  
  351. /** 
  352. * Tab Settings 
  353. * @param $active_tab 
  354. * @return array 
  355. */ 
  356. protected function tab_settings( $active_tab ) { 
  357. return array( 
  358. 'active_tab' => $active_tab,  
  359. 'key' => $this->key() 
  360. ); 
  361.  
  362.