PluginProbe
Maps Plugin using Google Maps for WordPress – WP Google Map / trunk
Maps Plugin using Google Maps for WordPress – WP Google Map vtrunk
1.9.7 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 All 96 releases
gmap-embed / includes / traits / Settings.php

Settings.php in Maps Plugin using Google Maps for WordPress – WP Google Map trunk, at includes/traits/Settings.php

547 lines 21.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WGMSRM\Traits;
4
5 use WGMSRM\Classes\Migration;
6
7 if (!defined('ABSPATH')) {
8 exit;
9 }
10
11
12
13 /**
14 * Trait Settings
15 */
16 trait Settings
17 {
18
19 /**
20 * Sanitize the map language option.
21 */
22 public function wgm_sanitize_gmap_language($value)
23 {
24 $languages = function_exists('gmap_embed_get_languages') ? gmap_embed_get_languages() : array();
25 $value = sanitize_text_field($value);
26 return array_key_exists($value, $languages) ? $value : 'en';
27 }
28
29 /**
30 * Settings section callback code(BLANK NOW)
31 */
32 public function gmap_embed_settings_section_callback()
33 {
34 // code...
35 }
36
37 /**
38 * Custom CSS part markup
39 */
40 public function gmap_embed_s_custom_css_markup()
41 { ?>
42 <textarea rows="10" cols="100" name="wpgmap_s_custom_css"
43 id="wpgmap_custom_css"><?php echo esc_textarea(get_option('wpgmap_s_custom_css')); ?></textarea>
44 <p class="description" id="tagline-description" style="font-style: italic;">
45 <?php esc_html_e('Add your custom CSS code if needed.', 'gmap-embed'); ?>
46 </p>
47 <?php
48 }
49
50 /**
51 * Custom JS part markup
52 */
53 public function wpgmap_s_custom_js_markup()
54 {
55 ?>
56 <textarea rows="10" cols="100" name="wpgmap_s_custom_js"
57 id="wpgmap_custom_js"><?php echo esc_textarea(get_option('wpgmap_s_custom_js')); ?></textarea>
58 <p class="description" id="tagline-description" style="font-style: italic;">
59 <?php esc_html_e('Add your custom JS code if needed.', 'gmap-embed'); ?>
60 </p>
61 <?php
62 }
63
64 /**
65 * Where Map API engine should be -> Markup
66 *
67 * @since 1.7.5
68 */
69 public function wgm_load_api_condition_markup()
70 {
71 ?>
72 <select name="_wgm_load_map_api_condition" id="_wgm_load_map_api_condition">
73 <option value="where-required" <?php selected(get_option('_wgm_load_map_api_condition'), 'where-required'); ?>>
74 <?php esc_html_e('Where required', 'gmap-embed'); ?>
75 </option>
76 <option value="always" <?php selected(get_option('_wgm_load_map_api_condition'), 'always'); ?>>
77 <?php esc_html_e('Always', 'gmap-embed'); ?>
78 </option>
79 <option value="only-front-end" <?php selected(get_option('_wgm_load_map_api_condition'), 'only-front-end'); ?>>
80 <?php esc_html_e('Only Front End', 'gmap-embed'); ?>
81 </option>
82 <option value="only-back-end" <?php selected(get_option('_wgm_load_map_api_condition'), 'only-back-end'); ?>>
83 <?php esc_html_e('Only Back End', 'gmap-embed'); ?>
84 </option>
85 <option value="never" <?php selected(get_option('_wgm_load_map_api_condition'), 'never'); ?>>
86 <?php esc_html_e('Never', 'gmap-embed'); ?>
87 </option>
88 </select>
89 <?php
90 }
91
92 /**
93 * Directions option -> Distance Unit
94 *
95 * @since 1.9.0
96 */
97 public function wgm_distance_unit()
98 {
99 ?>
100 <select name="_wgm_distance_unit" id="_wgm_distance_unit">
101 <option value="km" <?php selected(get_option('_wgm_distance_unit'), 'km'); ?>>
102 <?php esc_html_e('Kilometers', 'gmap-embed'); ?>
103 </option>
104 <option value="mi" <?php selected(get_option('_wgm_distance_unit'), 'mi'); ?>>
105 <?php esc_html_e('Miles', 'gmap-embed'); ?>
106 </option>
107 </select>
108 <?php
109 }
110
111 /**
112 * Category selection logic -> OR/AND
113 *
114 * @since 1.2
115 */
116 public function wgm_category_selection_logic_markup()
117 {
118 ?>
119 <select name="wgm_category_selection_logic" id="wgm_category_selection_logic">
120 <option value="OR" <?php selected(get_option('wgm_category_selection_logic', 'OR'), 'OR'); ?>>
121 <?php esc_html_e('OR (Show if any category matches)', 'gmap-embed'); ?>
122 </option>
123 <option value="AND" <?php selected(get_option('wgm_category_selection_logic', 'OR'), 'AND'); ?>>
124 <?php esc_html_e('AND (Show if all categories match)', 'gmap-embed'); ?>
125 </option>
126 </select>
127 <p class="description">
128 <?php esc_html_e('Choose how multiple selected categories should be filtered on the frontend.', 'gmap-embed'); ?>
129 </p>
130 <?php
131 }
132
133 /**
134 * Minimum Role for Map Edit
135 *
136 * @since 1.9.0
137 */
138 public function _wgm_minimum_role_for_map_edit()
139 {
140 ?>
141 <select id="_wgm_minimum_role_for_map_edit" name="_wgm_minimum_role_for_map_edit">
142 <option value="manage_options" <?php selected(get_option('_wgm_minimum_role_for_map_edit'), 'manage_options'); ?>>
143 <?php esc_html_e('Administrator', 'gmap-embed'); ?>
144 </option>
145 <option value="edit_pages" <?php selected(get_option('_wgm_minimum_role_for_map_edit'), 'edit_pages'); ?>>
146 <?php esc_html_e('Editor', 'gmap-embed'); ?>
147 </option>
148 <option value="publish_posts" <?php selected(get_option('_wgm_minimum_role_for_map_edit'), 'publish_posts'); ?>>
149 <?php esc_html_e('Author', 'gmap-embed'); ?>
150 </option>
151 <option value="edit_posts" <?php selected(get_option('_wgm_minimum_role_for_map_edit'), 'edit_posts'); ?>>
152 <?php esc_html_e('Contributor', 'gmap-embed'); ?>
153 </option>
154 <option value="read" <?php selected(get_option('_wgm_minimum_role_for_map_edit'), 'read'); ?>>
155 <?php esc_html_e('Subscriber', 'gmap-embed'); ?>
156 </option>
157 </select>
158 <?php
159 }
160
161 /**
162 * Prevent API load by other plugin or theme markup
163 *
164 * @since 1.7.5
165 */
166 public function wgm_prevent_api_load_markup()
167 {
168 ?>
169 <input type="checkbox" name="_wgm_prevent_other_plugin_theme_api_load" id="_wgm_prevent_other_plugin_theme_api_load"
170 value="Y" <?php checked(get_option('_wgm_prevent_other_plugin_theme_api_load'), 'Y'); ?>>
171 <?php esc_html_e('Check this option if your want to prevent other plugin or theme loading map api, in case of you are getting api key error, included multiple api key error.', 'gmap-embed'); ?>
172 <br />
173 <?php
174 }
175
176 /**
177 * General Map Settings under General Settings
178 *
179 * @since 1.7.5
180 */
181 public function wgm_general_map_settings_markup()
182 {
183 ?>
184 <input type="checkbox" name="_wgm_disable_full_screen_control" id="_wgm_disable_full_screen_control" value="Y" <?php checked(get_option('_wgm_disable_full_screen_control'), 'Y'); ?>>
185 <?php esc_html_e('Disable Full Screen Control', 'gmap-embed'); ?>
186 <br />
187 <input type="checkbox" name="_wgm_disable_street_view" id="_wgm_disable_street_view" value="Y" <?php checked(get_option('_wgm_disable_street_view'), 'Y'); ?>> <?php esc_html_e('Disable StreetView', 'gmap-embed'); ?>
188 <br />
189 <input type="checkbox" name="_wgm_disable_zoom_control" id="_wgm_disable_zoom_control" value="Y" <?php checked(get_option('_wgm_disable_zoom_control'), 'Y'); ?>>
190 <?php esc_html_e('Disable Zoom Controls', 'gmap-embed'); ?>
191 <br />
192 <input type="checkbox" name="_wgm_disable_pan_control" id="_wgm_disable_pan_control" value="Y" <?php checked(get_option('_wgm_disable_pan_control'), 'Y'); ?>> <?php esc_html_e('Disable Pan Controls', 'gmap-embed'); ?>
193 <br />
194 <input type="checkbox" name="_wgm_disable_map_type_control" id="_wgm_disable_map_type_control" value="Y" <?php checked(get_option('_wgm_disable_map_type_control'), 'Y'); ?>>
195 <?php esc_html_e('Disable Map Type Controls', 'gmap-embed'); ?>
196 <br />
197 <input type="checkbox" name="_wgm_disable_mouse_wheel_zoom" id="_wgm_disable_mouse_wheel_zoom" value="Y" <?php checked(get_option('_wgm_disable_mouse_wheel_zoom'), 'Y'); ?>>
198 <?php esc_html_e('Disable Mouse Wheel Zoom', 'gmap-embed'); ?>
199 <br />
200 <input type="checkbox" name="_wgm_disable_mouse_dragging" id="_wgm_disable_mouse_dragging" value="Y" <?php checked(get_option('_wgm_disable_mouse_dragging'), 'Y'); ?>>
201 <?php esc_html_e('Disable Mouse Dragging', 'gmap-embed'); ?>
202 <br />
203 <input type="checkbox" name="_wgm_disable_mouse_double_click_zooming" id="_wgm_disable_mouse_double_click_zooming"
204 value="Y" <?php checked(get_option('_wgm_disable_mouse_double_click_zooming'), 'Y'); ?>>
205 <?php esc_html_e('Disable Mouse Double Click Zooming', 'gmap-embed'); ?>
206 <br />
207 <?php if (_wgm_is_premium()) { ?>
208 <input type="checkbox" name="_wgm_enable_direction_form_auto_complete" id="_wgm_enable_direction_form_auto_complete"
209 value="Y" <?php checked(get_option('_wgm_enable_direction_form_auto_complete'), 'Y'); ?>>
210 <?php esc_html_e('Enable direction From/To Auto Complete', 'gmap-embed'); ?>
211 <br />
212 <?php
213 }
214 }
215
216 /**
217 * Language selection part markup
218 */
219 public function gmap_embed_s_map_language_markup()
220 {
221 ?>
222 <select id="srm_gmap_lng" name="srm_gmap_lng" class="regular-text" style="width: 100%;max-width:100%;">
223 <?php
224 $wpgmap_languages = gmap_embed_get_languages();
225 if (count($wpgmap_languages) > 0) {
226 foreach ($wpgmap_languages as $lng_key => $language) {
227 $selected = (get_option('srm_gmap_lng', 'en') == $lng_key) ? 'selected' : '';
228 echo "<option value='" . esc_attr($lng_key) . "' " . esc_attr($selected) . '>' . esc_html($language) . '</option>';
229 }
230 }
231 ?>
232 </select>
233 <p class="description" id="tagline-description" style="font-style: italic;">
234 <?php esc_html_e('Chose your desired map language', 'gmap-embed'); ?>
235 </p>
236 <?php
237 }
238
239 /**
240 * Region selection part markup
241 */
242 public function gmap_embed_s_map_region_markup()
243 {
244 ?>
245 <select id="region" name="srm_gmap_region" class="regular-text" style="width: 100%;max-width: 100%;">
246 <?php
247 $wpgmap_regions = gmap_embed_get_regions();
248 if (count($wpgmap_regions) > 0) {
249 foreach ($wpgmap_regions as $region_key => $region) {
250 $selected = (get_option('srm_gmap_region', 'US') == $region_key) ? 'selected' : '';
251 echo "<option value='" . esc_attr($region_key) . "' " . esc_attr($selected) . '>' . esc_html($region) . '</option>';
252 }
253 }
254 ?>
255
256 </select>
257 <p class="description" id="tagline-description" style="font-style: italic;">
258 <?php esc_html_e('Chose your regional area', 'gmap-embed'); ?>
259 </p>
260 <?php
261 }
262
263 /**
264 * Settings section, fields register
265 */
266 public function gmapsrm_settings()
267 {
268 // Language settings section and fields
269 add_settings_section(
270 'gmap_embed_language_settings_section',
271 __('Map Language and Regional Settings<hr/>', 'gmap-embed'),
272 array($this, 'gmap_embed_settings_section_callback'),
273 'gmap-embed-settings-page-ls'
274 );
275
276 add_settings_field(
277 'srm_gmap_lng',
278 __('Map Language:', 'gmap-embed'),
279 array($this, 'gmap_embed_s_map_language_markup'),
280 'gmap-embed-settings-page-ls',
281 'gmap_embed_language_settings_section'
282 );
283
284 add_settings_field(
285 'srm_gmap_region',
286 __('Map Region:', 'gmap-embed'),
287 array($this, 'gmap_embed_s_map_region_markup'),
288 'gmap-embed-settings-page-ls',
289 'gmap_embed_language_settings_section'
290 );
291
292 // Custom Scripts section and fields
293 add_settings_section(
294 'gmap_embed_custom_scripts_section',
295 __('Custom Scripts<hr/>', 'gmap-embed'),
296 array($this, 'gmap_embed_settings_section_callback'),
297 'gmap-embed-settings-page-cs'
298 );
299
300 add_settings_field(
301 'wpgmap_s_custom_css',
302 __('Custom CSS:', 'gmap-embed'),
303 array($this, 'gmap_embed_s_custom_css_markup'),
304 'gmap-embed-settings-page-cs',
305 'gmap_embed_custom_scripts_section'
306 );
307
308 add_settings_field(
309 'wpgmap_s_custom_js',
310 __('Custom JS:', 'gmap-embed'),
311 array($this, 'wpgmap_s_custom_js_markup'),
312 'gmap-embed-settings-page-cs',
313 'gmap_embed_custom_scripts_section'
314 );
315
316 /**
317 * General map settings section and fields
318 *
319 * @since 1.7.5
320 */
321 add_settings_section(
322 'gmap_embed_general_map_settings_section',
323 null, // Use null instead of empty string for no title
324 array($this, 'gmap_embed_settings_section_callback'),
325 'gmap-embed-general-settings'
326 );
327
328 // General map settings related all fields are included
329 add_settings_field(
330 'wpgm_disable_full_screen_control',
331 __('Map Control Options:', 'gmap-embed'),
332 array($this, 'wgm_general_map_settings_markup'),
333 'gmap-embed-general-settings',
334 'gmap_embed_general_map_settings_section'
335 );
336
337 /**
338 * Advance settings section and fields
339 *
340 * @since 1.7.5
341 */
342 add_settings_section(
343 'wgm_advance_settings_section',
344 null, // Use null instead of empty string for no title
345 array($this, 'gmap_embed_settings_section_callback'),
346 'wgm_advance_settings-page'
347 );
348
349 add_settings_field(
350 '_wgm_load_map_api_condition',
351 __('Load Map API:', 'gmap-embed'),
352 array($this, 'wgm_load_api_condition_markup'),
353 'wgm_advance_settings-page',
354 'wgm_advance_settings_section'
355 );
356
357 add_settings_field(
358 '_wgm_prevent_other_plugin_theme_api_load',
359 __('Prevent Map API loading for other plugin and themes:', 'gmap-embed'),
360 array($this, 'wgm_prevent_api_load_markup'),
361 'wgm_advance_settings-page',
362 'wgm_advance_settings_section'
363 );
364
365 add_settings_field(
366 '_wgm_distance_unit',
367 __('Distance Unit:', 'gmap-embed'),
368 array($this, 'wgm_distance_unit'),
369 'wgm_advance_settings-page',
370 'wgm_advance_settings_section'
371 );
372
373 add_settings_field(
374 '_wgm_minimum_role_for_map_edit',
375 __('Minimum Role for Map Editor:', 'gmap-embed'),
376 array($this, '_wgm_minimum_role_for_map_edit'),
377 'wgm_advance_settings-page',
378 'wgm_advance_settings_section'
379 );
380
381 // Marker Settings section and fields
382 add_settings_section(
383 'wgm_marker_settings_section',
384 null, // Use null instead of empty string for no title
385 array($this, 'gmap_embed_settings_section_callback'),
386 'wgm_marker_settings-page'
387 );
388
389 add_settings_field(
390 'wgm_category_selection_logic',
391 __('Category Selection Logic:', 'gmap-embed'),
392 array($this, 'wgm_category_selection_logic_markup'),
393 'wgm_marker_settings-page',
394 'wgm_marker_settings_section'
395 );
396
397 register_setting(
398 'wpgmap_general_settings',
399 'srm_gmap_lng',
400 array(
401 'sanitize_callback' => array($this, 'wgm_sanitize_gmap_language')
402 )
403 );
404 register_setting('wpgmap_general_settings', 'srm_gmap_region', array(
405 'sanitize_callback' => 'sanitize_text_field'
406 ));
407 register_setting('wpgmap_general_settings', 'wpgmap_s_custom_css', array(
408 'sanitize_callback' => 'wp_strip_all_tags'
409 ));
410 register_setting('wpgmap_general_settings', 'wpgmap_s_custom_js', array(
411 'sanitize_callback' => 'wp_strip_all_tags'
412 ));
413 /**
414 * Map General Settings
415 *
416 * @since 1.7.5
417 */
418 register_setting('wpgmap_general_settings', '_wgm_disable_full_screen_control', array(
419 'sanitize_callback' => 'sanitize_text_field'
420 ));
421 register_setting('wpgmap_general_settings', '_wgm_disable_street_view', array(
422 'sanitize_callback' => 'sanitize_text_field'
423 ));
424 register_setting('wpgmap_general_settings', '_wgm_disable_zoom_control', array(
425 'sanitize_callback' => 'sanitize_text_field'
426 ));
427 register_setting('wpgmap_general_settings', '_wgm_disable_pan_control', array(
428 'sanitize_callback' => 'sanitize_text_field'
429 ));
430 register_setting('wpgmap_general_settings', '_wgm_disable_map_type_control', array(
431 'sanitize_callback' => 'sanitize_text_field'
432 ));
433 register_setting('wpgmap_general_settings', '_wgm_disable_mouse_wheel_zoom', array(
434 'sanitize_callback' => 'sanitize_text_field'
435 ));
436 register_setting('wpgmap_general_settings', '_wgm_disable_mouse_dragging', array(
437 'sanitize_callback' => 'sanitize_text_field'
438 ));
439 register_setting('wpgmap_general_settings', '_wgm_disable_mouse_double_click_zooming', array(
440 'sanitize_callback' => 'sanitize_text_field'
441 ));
442 register_setting('wpgmap_general_settings', '_wgm_enable_direction_form_auto_complete', array(
443 'sanitize_callback' => 'sanitize_text_field'
444 ));
445 /**
446 * Advance Settings
447 *
448 * @since 1.7.5
449 */
450 register_setting('wgm_advance_settings', '_wgm_load_map_api_condition', array(
451 'sanitize_callback' => 'sanitize_text_field'
452 ));
453 register_setting('wgm_advance_settings', '_wgm_prevent_other_plugin_theme_api_load', array(
454 'sanitize_callback' => 'sanitize_text_field'
455 ));
456 register_setting('wgm_advance_settings', '_wgm_distance_unit', array(
457 'sanitize_callback' => 'sanitize_text_field'
458 ));
459 register_setting('wgm_advance_settings', '_wgm_minimum_role_for_map_edit', array(
460 'sanitize_callback' => 'sanitize_text_field'
461 ));
462
463 /**
464 * Marker Settings
465 *
466 * @since 1.2
467 */
468 register_setting('wgm_marker_settings', 'wgm_category_selection_logic', array(
469 'sanitize_callback' => 'sanitize_text_field'
470 ));
471 }
472
473 /**
474 * Save API Key from settings page
475 * @since 1.9.1
476 */
477 public function wgm_save_api_key()
478 {
479 check_admin_referer('wgm_settings_api_key_update', '_wp_nonce');
480
481 if (!current_user_can($this->capability)) {
482 wp_die(esc_html__('You do not have permission to update settings.', 'gmap-embed'));
483 }
484
485 $api_key = isset($_POST['wpgmapembed_key']) ? sanitize_text_field(wp_unslash($_POST['wpgmapembed_key'])) : '';
486 if ($api_key !== '') {
487 update_option('wpgmap_api_key', $api_key, 'yes');
488 }
489
490 $settings_nonce = wp_create_nonce('wgm_settings');
491 wp_safe_redirect(add_query_arg(['page' => 'wpgmapembed-settings', 'message' => 3, 'wgm_settings_nonce' => $settings_nonce], admin_url('admin.php')));
492 exit;
493 }
494
495 /**
496 * Save and validate License Key from settings page
497 * @since 1.9.1
498 */
499 public function wgm_save_license()
500 {
501 check_admin_referer('wgm_settings_lc_key_update', '_wp_nonce');
502
503 if (!current_user_can($this->capability)) {
504 wp_die(esc_html__('You do not have permission to update settings.', 'gmap-embed'));
505 }
506
507 $license = isset($_POST['wpgmapembed_license']) ? sanitize_text_field(wp_unslash($_POST['wpgmapembed_license'])) : '';
508 $api_base_url = 'https://wpgooglemap.com';
509
510 $msg_code = 5; // Default error
511
512 if ($license !== '') {
513 $remote_ip = isset($_SERVER['REMOTE_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])) : '';
514 $remote_host = isset($_SERVER['HTTP_HOST']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_HOST'])) : '';
515
516 $request_url = esc_url_raw($api_base_url . '/paypal/api.php?key=' . rawurlencode($license) . '&ip=' . rawurlencode($remote_ip) . '&host=' . rawurlencode($remote_host));
517 $response = wp_remote_get($request_url);
518 $code = wp_remote_retrieve_response_code($response);
519 $body = wp_remote_retrieve_body($response);
520 $data = json_decode($body);
521
522 // Hardening: Robust validation of remote response
523 $is_valid = (
524 $code === 200 &&
525 $data &&
526 is_object($data) &&
527 isset($data->status) &&
528 $data->status === true
529 );
530
531 if ($is_valid) {
532 update_option('wpgmapembed_license', $license, 'yes');
533 update_option('_wgm_is_p_v', 'Y');
534 $msg_code = 4; // Success
535 } else {
536 $msg_code = 5; // Error
537 }
538 } else {
539 $msg_code = 6; // Empty
540 }
541
542 $settings_nonce = wp_create_nonce('wgm_settings');
543 wp_safe_redirect(add_query_arg(['page' => 'wpgmapembed-settings', 'message' => $msg_code, 'wgm_settings_nonce' => $settings_nonce], admin_url('admin.php')));
544 exit;
545 }
546 }
547