PluginProbe
CBX Map for Google Map & OpenStreetMap / trunk
CBX Map for Google Map & OpenStreetMap vtrunk
trunk 1.1.10 1.1.11 1.1.12 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5
cbxgooglemap / includes / Helpers / CBXGooglemapHelper.php

CBXGooglemapHelper.php in CBX Map for Google Map & OpenStreetMap trunk, at includes/Helpers/CBXGooglemapHelper.php

617 lines 21.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Cbx\Googlemap\Helpers;
3 // If this file is called directly, abort.
4 if ( ! defined( 'WPINC' ) ) {
5 die;
6 }
7
8 use Cbx\Googlemap\CBXGooglemapSettings;
9
10
11 class CBXGooglemapHelper {
12 /**
13 * Is gutenberg edit page
14 *
15 * @return bool
16 *
17 * @since 1.1.5
18 */
19 public static function is_gutenberg_page() {
20 //if(!is_admin()) return false;
21 if ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page()) {
22 // The Gutenberg plugin is on.
23 return true;
24 }
25
26 $current_screen = get_current_screen();
27 if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
28 // Gutenberg page on 5+.
29 return true;
30 }
31
32 return false;
33 }//end is_gutenberg_page
34
35
36 /**
37 * Enqueue css and js when needed (for map render)
38 *
39 * @param bool $enqueue_js
40 * @param bool $enqueue_css
41 *
42 * @since 1.1.5
43 */
44 public static function enqueue_js_css( $enqueue_js = true, $enqueue_css = true ) {
45 $settings = new CBXGooglemapSettings();;
46 $api_key = $settings->get_field( 'apikey', 'cbxgooglemap_general', '' );
47 $map_source = absint( $settings->get_field( 'mapsource', 'cbxgooglemap_general', 1 ) );
48
49 if ( $enqueue_js ) {
50 //handle enqueue js
51 if ( ( $map_source == 1 && ! empty( $api_key ) ) || $map_source == 0 ) {
52 if ( $map_source == 1 ) {
53 wp_enqueue_script( 'coregooglemapapi' );
54 //wp_enqueue_script( 'jqcbxgooglemap' );
55 } else {
56 wp_enqueue_script( 'coregooglemapapi' );
57 }
58
59 wp_enqueue_script( 'cbxgooglemap-events' );
60 wp_enqueue_script( 'cbxgooglemap-public' );
61 }
62 //end handle enqueue js
63 }
64
65 if ( $enqueue_css ) {
66 //handle enqueue css
67 if ( $map_source == 0 ) {
68 wp_enqueue_style( 'leaflet' );
69 } else {
70 //
71 }
72
73 wp_enqueue_style( 'cbxgooglemap-public' );
74 //end handle enqueue css
75 }
76
77 do_action( 'cbxgooglemap_enqueue_js_css', $enqueue_js, $enqueue_css );
78
79 }//end enqueue_js_css
80
81 /**
82 * Register Custom Post Type cbxgooglemap
83 *
84 * @since 3.7.0
85 */
86 public static function create_googlemap_post_type() {
87 $post_slug_default = 'cbxgooglemap';
88
89 $labels = [
90 'name' => _x( 'Maps', 'Post Type General Name', 'cbxgooglemap' ),
91 'singular_name' => _x( 'Map', 'Post Type Singular Name', 'cbxgooglemap' ),
92 'menu_name' => esc_html__( 'CBX Maps', 'cbxgooglemap' ),
93 'parent_item_colon' => esc_html__( 'Parent Item:', 'cbxgooglemap' ),
94 'all_items' => esc_html__( 'Maps', 'cbxgooglemap' ),
95 'view_item' => esc_html__( 'View Map', 'cbxgooglemap' ),
96 'add_new_item' => esc_html__( 'Add New Map', 'cbxgooglemap' ),
97 'add_new' => esc_html__( 'Add New', 'cbxgooglemap' ),
98 'edit_item' => esc_html__( 'Edit Map', 'cbxgooglemap' ),
99 'update_item' => esc_html__( 'Update Map', 'cbxgooglemap' ),
100 'search_items' => esc_html__( 'Search Map', 'cbxgooglemap' ),
101 'not_found' => esc_html__( 'Not found', 'cbxgooglemap' ),
102 'not_found_in_trash' => esc_html__( 'Not found in Trash', 'cbxgooglemap' ),
103 ];
104
105 $args = [
106 'label' => esc_html__( 'Maps', 'cbxgooglemap' ),
107 'description' => esc_html__( 'Simple map using google map and openstreet map.', 'cbxgooglemap' ),
108 'labels' => apply_filters( 'cbxgooglemap_post_type_labels', $labels ),
109 'supports' => apply_filters( 'cbxgooglemap_post_type_supports', [ 'title' ] ),
110 'hierarchical' => false,
111 'public' => apply_filters( 'cbxgooglemap_post_type_public', false ),
112 'show_ui' => true,
113 'show_in_menu' => true,
114 'show_in_nav_menus' => true,
115 'show_in_admin_bar' => true,
116 'rewrite' => [ 'slug' => apply_filters( 'cbxgooglemap_single_slug', $post_slug_default ) ],
117 //'menu_icon' => 'dashicons-list-view',
118 'menu_icon' => apply_filters( 'cbxgooglemap_menu_icon', 'dashicons-location' ),
119 'can_export' => true,
120 'has_archive' => apply_filters( 'cbxgooglemap_post_type_has_archive', false ),
121 'exclude_from_search' => apply_filters( 'cbxgooglemap_post_type_exclude_from_search', true ),
122 'publicly_queryable' => apply_filters( 'cbxgooglemap_post_type_publicly_queryable', false ),
123 'capability_type' => 'post',
124 ];
125
126 register_post_type( 'cbxgooglemap', apply_filters( 'cbxgooglemap_post_type_args', $args ) );
127 }//end create_googlemap_post_type
128
129 /**
130 * Setup a post object and store the original loop item so we can reset it later
131 *
132 * @param obj $post_to_setup The post that we want to use from our custom loop
133 */
134 public static function setup_admin_postdata( $post_to_setup ) {
135 //only on the admin side
136 if ( is_admin() ) {
137
138 //get the post for both setup_postdata() and to be cached
139 global $post;
140
141 //only cache $post the first time through the loop
142 if ( ! isset( $GLOBALS['post_cache'] ) ) {
143 $GLOBALS['post_cache'] = $post; //phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
144 }
145
146 //setup the post data as usual
147 $post = $post_to_setup;
148 setup_postdata( $post );
149 }
150 }//end setup_admin_postdata
151
152 /**
153 * Reset $post back to the original item
154 *
155 */
156 public static function wp_reset_admin_postdata() {
157 //only on the admin and if post_cache is set
158 if ( is_admin() && ! empty( $GLOBALS['post_cache'] ) ) {
159
160 //globalize post as usual
161 global $post;
162
163 //set $post back to the cached version and set it up
164 $post = $GLOBALS['post_cache'];
165 setup_postdata( $post );
166
167 //cleanup
168 unset( $GLOBALS['post_cache'] );
169 }
170 }//end wp_reset_admin_postdata
171
172 public static function supported_post_types() {
173 $allowed_post_types = [ 'cbxgooglemap' ];
174 return apply_filters( 'cbxgooglemap_post_types_support', $allowed_post_types );
175 }//end supported_post_types
176
177 /**
178 * Returns all post types that has public view and visually accessible
179 *
180 * @return array
181 */
182 public static function post_types() {
183 $post_type_args = [
184 'builtin' => [
185 'options' => [
186 'public' => true,
187 '_builtin' => true,
188 'show_ui' => true,
189 ],
190 'label' => esc_html__( 'Built in post types', 'cbxgooglemap' ),
191 ]
192 ];
193
194 $post_type_args = apply_filters( 'cbxgooglemap_post_types', $post_type_args );
195
196 $output = 'objects'; // names or objects, note names is the default
197 $operator = 'and'; // 'and' or 'or'
198 $postTypes = [];
199
200 foreach ( $post_type_args as $postArgType => $postArgTypeArr ) {
201 $types = get_post_types( $postArgTypeArr['options'], $output, $operator );
202
203 if ( ! empty( $types ) ) {
204 foreach ( $types as $type ) {
205 $postTypes[ $postArgType ]['label'] = $postArgTypeArr['label'];
206 $postTypes[ $postArgType ]['data'][ $type->name ] = $type->labels->name;
207 }
208 }
209 }
210
211 return $postTypes;
212
213 }//end post_types
214
215 /**
216 * Shortcode builder for display and copy paste purpose
217 *
218 * @param $general_settings
219 *
220 * @return string
221 */
222 public static function shortcode_builder( $general_settings = [] ) {
223 $settings = new CBXGooglemapSettings();
224 $zoom_default = $settings->get_field( 'zoom', 'cbxgooglemap_general', '8' );
225 if ( $zoom_default == 0 ) {
226 $zoom_default = 8;
227 }
228
229 $width_default = $settings->get_field( 'width', 'cbxgooglemap_general', '100%' );
230 if ( $width_default == '' || $width_default == 0 ) {
231 $width_default = '100%';
232 }
233
234 $height_default = intval( $settings->get_field( 'height', 'cbxgooglemap_general', '300' ) );
235 if ( $height_default == 0 ) {
236 $height_default = 300;
237 }
238
239 $scrollwheel_default = intval( $settings->get_field( 'scrollwheel', 'cbxgooglemap_general', 1 ) );
240 $showinfo_default = intval( $settings->get_field( 'showinfo', 'cbxgooglemap_general', 1 ) );
241 $infow_open_default = intval( $settings->get_field( 'infow_open', 'cbxgooglemap_general', 1 ) );
242 $maptype_default = esc_attr( $settings->get_field( 'maptype', 'cbxgooglemap_general', 'roadmap' ) );
243 $mapicon_default = esc_url( $settings->get_field( 'mapicon', 'cbxgooglemap_general', '' ) );
244
245 $attr = [
246 'width' => $width_default,
247 'height' => $height_default,
248 'zoom' => $zoom_default,
249 'scrollwheel' => $scrollwheel_default,
250 'showinfo' => $showinfo_default,
251 'infow_open' => $infow_open_default,
252 'maptype' => $maptype_default,
253 'heading' => 'Codeboxr(Sample)',
254 'address' => '6H, Dilara Tower, 77 Bir Uttam C.R. Dutta Road, Dhaka 1205(Sample)',
255 'website' => 'https://codeboxr.com/',
256 'mapicon' => $mapicon_default,
257 'lat' => '23.744825100000003',
258 'lng' => '90.39219739999999'
259 ];
260
261 $attr = apply_filters( 'cbxgooglemap_builder_attr', $attr );
262
263 $attr_html = '';
264
265 foreach ( $attr as $key => $value ) {
266 $attr_html .= ' ' . $key . '="' . $value . '" ';
267 }
268
269 return '[cbxgooglemap ' . $attr_html . ']';
270 }//end method shortcode_builder
271
272 /**
273 * Map type block compatible options
274 *
275 * @return mixed|void
276 */
277 public static function maptype_block_options() {
278 $maptypes = [
279 'roadmap' => esc_html__( 'Road Map', 'cbxgooglemap' ),
280 'satellite' => esc_html__( 'Satellite Map', 'cbxgooglemap' ),
281 'hybrid' => esc_html__( 'Hybrid Map', 'cbxgooglemap' ),
282 'terrain' => esc_html__( 'Terrain Map', 'cbxgooglemap' ),
283 ];
284
285 $maptype_arr = [];
286
287 foreach ( $maptypes as $key => $value ) {
288 $maptype_arr[] = [
289 'label' => $value,
290 'value' => $key
291 ];
292 }
293
294 return apply_filters( 'cbxgooglemap_maptype_block_options', $maptype_arr );
295 }//end maptype_block_options
296
297
298 /**
299 * @return mixed|void
300 */
301 public static function get_maptype() {
302 $maptype = [
303 'roadmap' => esc_html__( 'Road Map', 'cbxgooglemap' ),
304 'satellite' => esc_html__( 'Satellite Map', 'cbxgooglemap' ),
305 'hybrid' => esc_html__( 'Hybrid Map', 'cbxgooglemap' ),
306 'terrain' => esc_html__( 'Terrain Map', 'cbxgooglemap' ),
307 ];
308
309 return apply_filters( 'cbxgooglemap_maptype', $maptype );
310 }// end get_maptype
311
312 /**
313 * Get available map type reverser
314 *
315 * @return mixed|void
316 */
317 public static function get_maptype_r() {
318 $maptype = CBXGooglemapHelper::get_maptype();
319 $maptype_r = [];
320
321 foreach ( $maptype as $key => $value ) {
322 $maptype_r[ $value ] = $key;
323 }
324
325 return apply_filters( 'cbxgooglemap_maptype_r', $maptype_r );
326 }//end get_maptype_r
327
328 /**
329 * Add utm params to any url
330 *
331 * @param string $url
332 *
333 * @return string
334 */
335 public static function url_utmy( $url = '' ) {
336 if ( $url == '' ) {
337 return $url;
338 }
339
340 $url = add_query_arg( [
341 'utm_source' => 'plgsidebarinfo',
342 'utm_medium' => 'plgsidebar',
343 'utm_campaign' => 'wpfreemium',
344 ], $url );
345
346 return $url;
347 }//end url_utmy
348
349 /**
350 * Most needed common strings needed in js throughout the plugin
351 *
352 * @return array
353 */
354 public static function global_translation_strings() {
355 $global_translation = [
356 'is_user_logged_in' => is_user_logged_in() ? 1 : 0,
357 'ajax' => [
358 'ajax_url' => admin_url( 'admin-ajax.php' ),
359 'rest_url' => esc_url_raw( rest_url() ),
360 'ajax_fail' => esc_html__( 'Request failed, please reload the page.', 'cbxgooglemap' ),
361 'ajax_nonce' => wp_create_nonce( 'cbxgooglemap_nonce' ),
362 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
363 ],
364 'teeny_setting' => [
365 'teeny' => true,
366 'media_buttons' => true,
367 'editor_class' => '',
368 'textarea_rows' => 5,
369 'quicktags' => false,
370 'menubar' => false,
371 ],
372 'copycmds' => [
373 'copy' => esc_html__( 'Copy', 'cbxgooglemap' ),
374 'copied' => esc_html__( 'Copied', 'cbxgooglemap' ),
375 'copy_tip' => esc_html__( 'Click to copy', 'cbxgooglemap' ),
376 'copied_tip' => esc_html__( 'Copied to clipboard', 'cbxgooglemap' ),
377 ],
378 'delete_dialog' => [
379 'ok' => esc_attr_x( 'Ok', 'cbxgooglemap-dialog', 'cbxgooglemap' ),
380 'cancel' => esc_attr_x( 'Cancel', 'cbxgooglemap-dialog', 'cbxgooglemap' ),
381 'delete' => esc_attr_x( 'Delete', 'cbxgooglemap-dialog', 'cbxgooglemap' ),
382 'are_you_sure_global' => esc_html__( 'Are you sure?', 'cbxgooglemap' ),
383 'are_you_sure_delete_desc' => esc_html__( 'Once you delete, it\'s gone forever. You can not revert it back.', 'cbxgooglemap' ),
384 ],
385 'pickr_i18n' => [
386 // Strings visible in the UI
387 'ui:dialog' => esc_html__( 'color picker dialog', 'cbxgooglemap' ),
388 'btn:toggle' => esc_html__( 'toggle color picker dialog', 'cbxgooglemap' ),
389 'btn:swatch' => esc_html__( 'color swatch', 'cbxgooglemap' ),
390 'btn:last-color' => esc_html__( 'use previous color', 'cbxgooglemap' ),
391 'btn:save' => esc_html__( 'Save', 'cbxgooglemap' ),
392 'btn:cancel' => esc_html__( 'Cancel', 'cbxgooglemap' ),
393 'btn:clear' => esc_html__( 'Clear', 'cbxgooglemap' ),
394
395 // Strings used for aria-labels
396 'aria:btn:save' => esc_html__( 'save and close', 'cbxgooglemap' ),
397 'aria:btn:cancel' => esc_html__( 'cancel and close', 'cbxgooglemap' ),
398 'aria:btn:clear' => esc_html__( 'clear and close', 'cbxgooglemap' ),
399 'aria:input' => esc_html__( 'color input field', 'cbxgooglemap' ),
400 'aria:palette' => esc_html__( 'color selection area', 'cbxgooglemap' ),
401 'aria:hue' => esc_html__( 'hue selection slider', 'cbxgooglemap' ),
402 'aria:opacity' => esc_html__( 'selection slider', 'cbxgooglemap' ),
403 ],
404 'awn_options' => [
405 'tip' => esc_html__( 'Tip', 'cbxgooglemap' ),
406 'info' => esc_html__( 'Info', 'cbxgooglemap' ),
407 'success' => esc_html__( 'Success', 'cbxgooglemap' ),
408 'warning' => esc_html__( 'Attention', 'cbxgooglemap' ),
409 'alert' => esc_html__( 'Error', 'cbxgooglemap' ),
410 'async' => esc_html__( 'Loading', 'cbxgooglemap' ),
411 'confirm' => esc_html__( 'Confirmation', 'cbxgooglemap' ),
412 'confirmOk' => esc_html__( 'OK', 'cbxgooglemap' ),
413 'confirmCancel' => esc_html__( 'Cancel', 'cbxgooglemap' )
414 ],
415 'validation' => [
416 'required' => esc_html__( 'This field is required.', 'cbxgooglemap' ),
417 'remote' => esc_html__( 'Please fix this field.', 'cbxgooglemap' ),
418 'email' => esc_html__( 'Please enter a valid email address.', 'cbxgooglemap' ),
419 'url' => esc_html__( 'Please enter a valid URL.', 'cbxgooglemap' ),
420 'date' => esc_html__( 'Please enter a valid date.', 'cbxgooglemap' ),
421 'dateISO' => esc_html__( 'Please enter a valid date ( ISO ).', 'cbxgooglemap' ),
422 'number' => esc_html__( 'Please enter a valid number.', 'cbxgooglemap' ),
423 'digits' => esc_html__( 'Please enter only digits.', 'cbxgooglemap' ),
424 'equalTo' => esc_html__( 'Please enter the same value again.', 'cbxgooglemap' ),
425 'maxlength' => esc_html__( 'Please enter no more than {0} characters.', 'cbxgooglemap' ),
426 'minlength' => esc_html__( 'Please enter at least {0} characters.', 'cbxgooglemap' ),
427 'rangelength' => esc_html__( 'Please enter a value between {0} and {1} characters long.', 'cbxgooglemap' ),
428 'range' => esc_html__( 'Please enter a value between {0} and {1}.', 'cbxgooglemap' ),
429 'max' => esc_html__( 'Please enter a value less than or equal to {0}.', 'cbxgooglemap' ),
430 'min' => esc_html__( 'Please enter a value greater than or equal to {0}.', 'cbxgooglemap' ),
431 'recaptcha' => esc_html__( 'Please check the captcha.', 'cbxgooglemap' ),
432 ],
433 'placeholder' => [
434 'select' => esc_html__( 'Please Select', 'cbxgooglemap' ),
435 'search' => esc_html__( 'Search...', 'cbxgooglemap' ),
436 ],
437 'upload' => [
438 'upload_btn' => esc_html__( 'Upload', 'cbxgooglemap' ),
439 'upload_title' => esc_html__( 'Select Media', 'cbxgooglemap' ),
440 ],
441 'lang' => get_user_locale(),
442 'file_preview' => [
443 'browse' => esc_attr__( 'Choose', 'cbxgooglemap' ),
444 'chooseFile' => esc_attr__( 'Take your pick...', 'cbxgooglemap' ),
445 'label' => esc_attr__( 'Choose Files to Upload', 'cbxgooglemap' ),
446 'selectedCount' => esc_attr__( 'files selected', 'cbxgooglemap' )
447 ]
448 ];
449
450 return apply_filters( 'cbxgooglemap_global_translation', $global_translation );
451 }//end method global_translation_strings
452
453 /**
454 * Returns codeboxr news feeds using transient cache
455 *
456 * @return false|mixed|\SimplePie\Item[]|null
457 */
458 public static function codeboxr_news_feed() {
459 $cache_key = 'codeboxr_news_feed_cache';
460 $cached_feed = get_transient( $cache_key );
461
462 $news = false;
463
464 if ( false === $cached_feed ) {
465 include_once ABSPATH . WPINC . '/feed.php'; // Ensure feed functions are available
466 $feed = fetch_feed( 'https://codeboxr.com/feed?post_type=post' );
467
468 if ( is_wp_error( $feed ) ) {
469 return false; // Return false if there's an error
470 }
471
472 $feed->init();
473
474 $feed->set_output_encoding( 'UTF-8' );
475 // this is the encoding parameter, and can be left unchanged in almost every case
476 $feed->handle_content_type();
477 // this double-checks the encoding type
478 $feed->set_cache_duration( 21600 );
479 // 21,600 seconds is six hours
480 $limit = $feed->get_item_quantity( 10 );
481 // fetches the 18 most recent RSS feed stories
482 $items = $feed->get_items( 0, $limit );
483 $blocks = array_slice( $items, 0, 10 );
484
485 $news = [];
486 foreach ( $blocks as $block ) {
487 $url = $block->get_permalink();
488 $url = CBXGooglemapHelper::url_utmy( esc_url( $url ) );
489 $title = $block->get_title();
490
491 $news[] = [ 'url' => $url, 'title' => $title ];
492 }
493
494 set_transient( $cache_key, $news, HOUR_IN_SECONDS * 6 ); // Cache for 6 hours
495 } else {
496 $news = $cached_feed;
497 }
498
499 return $news;
500 }//end method codeboxr_news_feed
501
502 /**
503 * Short Description. (use period)
504 *
505 * Long Description.
506 *
507 * @since 1.0.0
508 */
509 public static function activate() {
510 CBXGooglemapHelper::create_googlemap_post_type();
511
512 add_option( 'cbxgooglemap_flush_rewrite_rules', 'true' );
513 }//end activate
514
515 /**
516 * Short Description. (use period)
517 *
518 * Long Description.
519 *
520 * @since 1.0.0
521 */
522 public static function deactivate() {
523 delete_option( 'cbxgooglemap_flush_rewrite_rules' );
524 }//end deactivate
525
526 /**
527 * Load reset option table html
528 *
529 * @return string
530 */
531 public static function setting_reset_html_table() {
532 $option_values = self::getAllOptionNames();
533
534 $table_html = '<p style="margin-bottom: 10px;" class="grouped gapless grouped_buttons" id="cbxgooglemap_setting_options_check_actions"><a href="#" class="button primary cbxgooglemap_setting_options_check_action_call">' . esc_html__( 'Check All',
535 'cbxgooglemap' ) . '</a><a href="#" class="button outline cbxgooglemap_setting_options_check_action_ucall">' . esc_html__( 'Uncheck All',
536 'cbxgooglemap' ) . '</a></p>';
537 $table_html .= '<table class="widefat widethin cbxgooglemap_table_data" id="cbxgooglemap_setting_options_table">
538 <thead>
539 <tr>
540 <th class="row-title">' . esc_attr__( 'Option Name', 'cbxgooglemap' ) . '</th>
541 <th>' . esc_attr__( 'Option ID', 'cbxgooglemap' ) . '</th>
542 </tr>
543 </thead>';
544
545 $table_html .= '<tbody>';
546
547 $i = 0;
548 foreach ( $option_values as $key => $value ) {
549 $alternate_class = ( $i % 2 == 0 ) ? 'alternate' : '';
550 $i ++;
551 $table_html .= '<tr class="' . esc_attr( $alternate_class ) . '">
552 <td class="row-title"><input checked class="magic-checkbox reset_options" type="checkbox" name="reset_options[' . $value['option_name'] . ']" id="reset_options_' . esc_attr( $value['option_name'] ) . '" value="' . $value['option_name'] . '" />
553 <label for="reset_options_' . esc_attr( $value['option_name'] ) . '">' . esc_attr( $value['option_name'] ) . '</td>
554 <td>' . esc_attr( $value['option_id'] ) . '</td>
555 </tr>';
556 }
557
558 $table_html .= '</tbody>';
559 $table_html .= '<tfoot>
560 <tr>
561 <th class="row-title">' . esc_attr__( 'Option Name', 'cbxgooglemap' ) . '</th>
562 <th>' . esc_attr__( 'Option ID', 'cbxgooglemap' ) . '</th>
563 </tr>
564 </tfoot>
565 </table>';
566
567 return $table_html;
568 } //end method setting_reset_html_table
569
570 /**
571 * List all global option name with prefix cbxgooglemap_
572 * @since 1.0.0
573 */
574 public static function getAllOptionNames() {
575 global $wpdb;
576
577 $prefix = 'cbxgooglemap_';
578
579 $wild = '%';
580 $like = $wpdb->esc_like( $prefix ) . $wild;
581
582 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
583 $option_names = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->options} WHERE option_name LIKE %s", $like ), ARRAY_A );
584
585 return apply_filters( 'cbxgooglemap_option_names', $option_names );
586 }//end method getAllOptionNames
587
588 /**
589 * Get any plugin version number
590 *
591 * @param $plugin_slug
592 *
593 * @return mixed|string
594 * @since 2.0.0
595 */
596 public static function get_any_plugin_version( $plugin_slug = '' ) {
597 if ( $plugin_slug == '' ) {
598 return '';
599 }
600
601 // Ensure the required file is loaded
602 if ( ! function_exists( 'get_plugins' ) ) {
603 require_once ABSPATH . 'wp-admin/includes/plugin.php';
604 }
605
606 // Get all installed plugins
607 $all_plugins = get_plugins();
608
609 // Check if the plugin exists
610 if ( isset( $all_plugins[ $plugin_slug ] ) ) {
611 return $all_plugins[ $plugin_slug ]['Version'];
612 }
613
614 // Return false if the plugin is not found
615 return '';
616 }//end method get_pro_addon_version
617 }//end class CBXGooglemapHelper