PluginProbe
CBX Map for Google Map & OpenStreetMap / 1.1.12
CBX Map for Google Map & OpenStreetMap v1.1.12
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 / class-cbxgooglemap.php

class-cbxgooglemap.php in CBX Map for Google Map & OpenStreetMap 1.1.12, at includes/class-cbxgooglemap.php

449 lines 16.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The file that defines the core plugin class
5 *
6 * A class definition that includes attributes and functions used across both the
7 * public-facing side of the site and the admin area.
8 *
9 * @link https://codeboxr.com
10 * @since 1.0.0
11 *
12 * @package Cbxgooglemap
13 * @subpackage Cbxgooglemap/includes
14 */
15
16 /**
17 * The core plugin class.
18 *
19 * This is used to define internationalization, admin-specific hooks, and
20 * public-facing site hooks.
21 *
22 * Also maintains the unique identifier of this plugin as well as the current
23 * version of the plugin.
24 *
25 * @since 1.0.0
26 * @package Cbxgooglemap
27 * @subpackage Cbxgooglemap/includes
28 * @author Codeboxr <info@codeboxr.com>
29 */
30 class CBXGoogleMap {
31 /**
32 * The single instance of the class.
33 *
34 * @var self
35 * @since 1.1.12
36 */
37 private static $instance = null;
38
39 /**
40 * The unique identifier of this plugin.
41 *
42 * @since 1.0.0
43 * @access protected
44 * @var string $plugin_name The string used to uniquely identify this plugin.
45 */
46 protected $plugin_name;
47
48 /**
49 * The current version of the plugin.
50 *
51 * @since 1.0.0
52 * @access protected
53 * @var string $version The current version of the plugin.
54 */
55 protected $version;
56
57 /**
58 * The ID of this plugin.
59 *
60 * @since 1.1.12
61 * @access private
62 * @var string $settings The ID of this plugin.
63 */
64 private $settings;
65
66 /**
67 * Define the core functionality of the plugin.
68 *
69 * Set the plugin name and the plugin version that can be used throughout the plugin.
70 * Load the dependencies, define the locale, and set the hooks for the admin area and
71 * the public-facing side of the site.
72 *
73 * @since 1.0.0
74 */
75 public function __construct() {
76
77 $this->plugin_name = CBXGOOGLEMAP_PLUGIN_NAME;
78 $this->version = CBXGOOGLEMAP_PLUGIN_VERSION;
79
80 $this->load_dependencies();
81
82
83
84 $this->define_common_hooks();
85 $this->define_admin_hooks();
86 $this->define_public_hooks();
87 }
88
89 /**
90 * Singleton Instance.
91 *
92 * Ensures only one instance of cbxgooglemap is loaded or can be loaded.
93 *
94 * @return self Main instance.
95 * @see run_cbxgooglemap()
96 * @since 1.1.12
97 * @static
98 */
99 public static function instance() {
100 if ( is_null( self::$instance ) ) {
101 self::$instance = new self();
102 }
103
104 return self::$instance;
105 }//end method instance
106
107 /**
108 * Load the required dependencies for this plugin.
109 *
110 * Include the following files that make up the plugin:
111 *
112 * - CBXGoogleMap_Loader. Orchestrates the hooks of the plugin.
113 * - CBXGoogleMap_i18n. Defines internationalization functionality.
114 * - CBXGoogleMap_Admin. Defines all hooks for the admin area.
115 * - CBXGoogleMap_Public. Defines all hooks for the public side of the site.
116 *
117 * Create an instance of the loader which will be used to register the hooks
118 * with WordPress.
119 *
120 * @since 1.0.0
121 * @access private
122 */
123 private function load_dependencies() {
124 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/cbxgooglemap-tpl-loader.php';
125 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-cbxgooglemap-settings.php';
126 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-cbxgooglemap-helper.php';
127 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-cbxgooglemap-admin.php';
128 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-cbxgooglemap-public.php';
129 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/cbxgooglemap-functions.php';
130 }
131
132
133 private function define_common_hooks() {
134 add_action( 'plugins_loaded', [ $this, 'load_plugin_textdomain' ] );
135 add_action( 'plugins_loaded', [ $this, 'house_keepings' ] );
136
137 //upgrade process
138 //add_action('admin_init', [$this, 'admin_init_upgrader_process']);
139 //add_action( 'upgrader_process_complete', [ $this, 'plugin_upgrader_process_complete' ], 10, 2 );
140 add_action( 'admin_notices', [ $this, 'plugin_activate_upgrade_notices' ] );
141
142 //update manager
143 add_filter( 'pre_set_site_transient_update_plugins', [ $this, 'pre_set_site_transient_update_plugins_pro_addon' ] );
144 add_action( 'in_plugin_update_message-' . 'cbxgooglemappro/cbxgooglemappro.php', [ $this, 'plugin_update_message_pro_addon' ] );
145 }//end method define_common_hooks
146
147 /**
148 * Load the plugin text domain for translation.
149 *
150 * @since 1.0.0
151 */
152 public function load_plugin_textdomain() {
153 load_plugin_textdomain(
154 'cbxgooglemap',
155 false,
156 CBXGOOGLEMAP_ROOT_PATH . 'languages/'
157 );
158 }//end method load_plugin_textdomain
159
160 /**
161 * Register all of the hooks related to the admin area functionality
162 * of the plugin.
163 *
164 * @since 1.0.0
165 * @access private
166 */
167 private function define_admin_hooks() {
168 global $wp_version;
169
170 $plugin_admin = new CBXGoogleMap_Admin();
171
172 //adding the setting action
173 add_action( 'admin_init', [ $plugin_admin, 'setting_init' ] );
174
175
176 //add new post type
177 add_action( 'init', [ $plugin_admin, 'create_post_type' ], 0 );
178
179
180 //create opverview menu page
181 add_action( 'admin_menu', [ $plugin_admin, 'menu_pages' ] );
182
183
184 //display meta fields
185 add_action( 'add_meta_boxes', [ $plugin_admin, 'add_meta_boxes' ] );
186
187
188 //save meta fields
189 add_action( 'save_post', [ $plugin_admin, 'metabox_save' ], 10, 3 ); //save meta
190
191
192 add_filter( 'manage_edit-cbxgooglemap_columns', [ $plugin_admin, 'cbxgooglemap_add_new_columns' ] );
193 add_action( 'manage_cbxgooglemap_posts_custom_column', [ $plugin_admin, 'cbxgooglemap_manage_columns' ] );
194
195 //js and css
196 add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueue_styles' ] );
197 add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueue_scripts' ] );
198
199
200 //add plugin row meta and actions links
201 add_filter( 'plugin_action_links_' . CBXGOOGLEMAP_BASE_NAME, [ $plugin_admin, 'plugin_listing_setting_link' ] );
202 add_filter( 'plugin_row_meta', [ $plugin_admin, 'custom_plugin_row_meta' ], 10, 2 );
203
204 //gutenberg
205 add_action( 'init', [ $plugin_admin, 'gutenberg_blocks' ] );
206
207 //gutenberg blocks
208 if ( version_compare( $wp_version, '5.8' ) >= 0 ) {
209 add_filter( 'block_categories_all', [ $plugin_admin, 'gutenberg_block_categories' ], 10, 2 );
210 } else {
211 add_filter( 'block_categories', [ $plugin_admin, 'gutenberg_block_categories' ], 10, 2 );
212 }
213
214 //add_filter( 'block_categories', $plugin_admin, 'gutenberg_block_categories', 10, 2 );
215 add_action( 'enqueue_block_editor_assets', [ $plugin_admin, 'enqueue_block_editor_assets' ] );
216 }//end define_admin_hooks
217
218 /**
219 * Register all of the hooks related to the public-facing functionality
220 * of the plugin.
221 *
222 * @since 1.0.0
223 * @access private
224 */
225 private function define_public_hooks() {
226 global $wp_version;
227
228 $plugin_public = new CBXGoogleMap_Public();
229
230 add_action( 'init', [ $plugin_public, 'init_shortcodes' ] );
231 add_action( 'widgets_init', [ $plugin_public, 'register_widget' ] );
232
233 //elementor
234 //add_action( 'elementor/init', [$plugin_public, 'init_elementor_widgets'] );
235 add_action( 'elementor/widgets/widgets_registered', [ $plugin_public, 'init_elementor_widgets' ] );
236 add_action( 'elementor/elements/categories_registered', [ $plugin_public, 'add_elementor_widget_categories' ] );
237 add_action( 'elementor/editor/before_enqueue_scripts', [ $plugin_public, 'elementor_icon_loader' ], 99999 );
238
239 add_action( 'wp_enqueue_scripts', [ $plugin_public, 'enqueue_styles' ] );
240 add_action( 'wp_enqueue_scripts', [ $plugin_public, 'enqueue_scripts' ] );
241
242 add_action( 'vc_before_init', [ $plugin_public, 'vc_before_init_actions' ] );
243 }//end method define_public_hooks
244
245
246 /**
247 * The name of the plugin used to uniquely identify it within the context of
248 * WordPress and to define internationalization functionality.
249 *
250 * @return string The name of the plugin.
251 * @since 1.0.0
252 */
253 public function get_plugin_name() {
254 return $this->plugin_name;
255 }//end method get_plugin_name
256
257 /**
258 * Retrieve the version number of the plugin.
259 *
260 * @return string The version number of the plugin.
261 * @since 1.0.0
262 */
263 public function get_version() {
264 return $this->version;
265 }//end method get_version
266
267
268 public function admin_init_upgrader_process(){
269 //add_action( 'upgrader_process_complete', [ $this, 'plugin_upgrader_process_complete' ], 10, 2 );
270 }//end method admin_init_upgrader_process
271
272 /**
273 * If we need to do something in upgrader process is completed for map plugin
274 *
275 * @param $upgrader_object
276 * @param $options
277 */
278 /*public function plugin_upgrader_process_complete( $upgrader_object, $options ) {
279 if ( isset( $options['plugins'] ) && $options['action'] == 'update' && $options['type'] == 'plugin' ) {
280 foreach ( $options['plugins'] as $each_plugin ) {
281 if ( $each_plugin == CBXGOOGLEMAP_BASE_NAME ) {
282
283
284 add_option( 'cbxgooglemap_flush_rewrite_rules', 'true' );
285 set_transient( 'cbxgooglemap_upgraded_notice', 1 );
286
287 if ( in_array( 'cbxgooglemappro/cbxgooglemappro.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) || defined( 'CBXGOOGLEMAPPRO_PLUGIN_NAME' ) ) {
288 //plugin is activated
289
290 $plugin_version = CBXGOOGLEMAPPRO_PLUGIN_VERSION;
291
292 if ( version_compare( CBXGOOGLEMAPPRO_PLUGIN_VERSION, '1.0.5', '<=' ) ) {
293 deactivate_plugins( 'cbxgooglemappro/cbxgooglemappro.php' );
294 set_transient( 'cbxgooglemappro_deactivated_notice', 1 );
295 }
296 }
297 break;
298 }
299 }
300 }
301 }//end plugin_upgrader_process_complete*/
302
303 /**
304 * Show a notice to anyone who has just installed the plugin for the first time
305 * This notice shouldn't display to anyone who has just updated this plugin
306 */
307 public function plugin_activate_upgrade_notices() {
308 if ( get_option( 'cbxgooglemap_flush_rewrite_rules' ) == 'true' ) {
309 flush_rewrite_rules();
310 delete_option( 'cbxgooglemap_flush_rewrite_rules' );
311 }
312
313 // Check the transient to see if we've just activated the plugin
314 if ( get_transient( 'cbxgooglemap_activated_notice' ) ) {
315 echo '<div class="notice notice-success is-dismissible" style="border-color: #2153cc !important;">';
316 echo '<p>' . sprintf( __( 'Thanks for installing/deactivating <strong>CBX Map for Google Map & OpenStreetMap</strong> V%s - Codeboxr Team',
317 'cbxgooglemap' ),
318 CBXGOOGLEMAP_PLUGIN_VERSION ) . '</p>';
319 echo '<p>' . sprintf( __( 'Check <a style="color: #6648fe !important; font-weight: bold;" href="%s" target="_blank">Documentation</a> | Create <a style="color: #6648fe !important; font-weight: bold;" href="%s" target="_blank">Map</a>',
320 'cbxgooglemap' ),
321 'https://codeboxr.com/product/cbx-google-map-for-wordpress/',
322 admin_url( 'post-new.php?post_type=cbxgooglemap' ) ) . '</p>';
323 echo '</div>';
324
325 // Delete the transient so we don't keep displaying the activation message
326 delete_transient( 'cbxgooglemap_activated_notice' );
327
328 $this->pro_addon_compatibility_campaign();
329 }
330
331 // Check the transient to see if we've just activated the plugin
332 if ( get_transient( 'cbxgooglemap_upgraded_notice' ) ) {
333 echo '<div class="notice notice-success is-dismissible" style="border-color: #2153cc !important;">';
334 echo '<p>' . sprintf( __( 'Thanks for upgrading <strong>CBX Map for Google Map & OpenStreetMap</strong> V%s , enjoy the new features and bug fixes - Codeboxr Team',
335 'cbxgooglemap' ),
336 CBXGOOGLEMAP_PLUGIN_VERSION ) . '</p>';
337 echo '<p>' . sprintf( __( 'Check <a style="color: #6648fe !important; font-weight: bold;" href="%s" target="_blank">Documentation</a> | Create <a style="color: #6648fe !important; font-weight: bold;" href="%s" target="_blank">Map</a>', 'cbxgooglemap' ),
338 'https://codeboxr.com/product/cbx-google-map-for-wordpress/',
339 admin_url( 'post-new.php?post_type=cbxgooglemap' ) ) . '</p>';
340 echo '</div>';
341
342 // Delete the transient so we don't keep displaying the activation message
343 delete_transient( 'cbxgooglemap_upgraded_notice' );
344
345 $this->pro_addon_compatibility_campaign();
346 }
347
348 if(get_transient('cbxgooglemappro_deactivated_notice')){
349 echo '<div class="notice notice-error is-dismissible" style="border-color: red !important;">';
350 echo '<p>' . __( 'Currently installed <strong>CBX Map for Google Map & OpenStreetMap Pro Addon</strong> version 1.0.5(or earlier) is not compatible with the latest version of core plugin CBX Map for Google Map & OpenStreetMap V1.1.12 or later. - Codeboxr Team',
351 'cbxgooglemap' ). '</p>';
352 echo '</div>';
353
354 delete_transient('cbxgooglemappro_deactivated_notice');
355 }
356 }//end plugin_activate_upgrade_notices
357
358 /**
359 * Check plugin compatibility and pro addon install campaign
360 */
361 public function pro_addon_compatibility_campaign() {
362 if ( ! function_exists( 'is_plugin_active' ) ) {
363 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
364 }
365
366 //if the pro addon is active or installed
367 if (defined( 'CBXGOOGLEMAPPRO_PLUGIN_NAME' ) || in_array( 'cbxgooglemappro/cbxgooglemappro.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) {
368 //plugin is activated
369
370 $plugin_version = CBXGOOGLEMAPPRO_PLUGIN_VERSION;
371
372 } else {
373 echo '<div class="notice notice-success is-dismissible" style="border-color: #2153cc !important;"><p>' . sprintf( __( 'CBX Map for Google Map & OpenStreetMap Pro has extended features and more controls, <a style="color: #6648fe !important; font-weight: bold;" target="_blank" href="%s">try it</a> - Codeboxr Team',
374 'cbxgooglemap' ), 'https://codeboxr.com/product/cbx-google-map-for-wordpress/#downloadarea/' ) . '</p></div>';
375 }
376 }//end pro_addon_compatibility_campaign
377
378 /**
379 * Add our self-hosted autoupdate plugin to the filter transient
380 *
381 * @param $transient
382 *
383 * @return object $ transient
384 */
385 public function pre_set_site_transient_update_plugins_pro_addon( $transient ) {
386 // Extra check for 3rd plugins
387 if ( isset( $transient->response['cbxgooglemappro/cbxgooglemappro.php'] ) ) {
388 return $transient;
389 }
390
391 if ( ! function_exists( 'get_plugins' ) ) {
392 require_once ABSPATH . 'wp-admin/includes/plugin.php';
393 }
394
395 $plugin_info = [];
396 $all_plugins = get_plugins();
397 if ( ! isset( $all_plugins['cbxgooglemappro/cbxgooglemappro.php'] ) ) {
398 return $transient;
399 } else {
400 $plugin_info = $all_plugins['cbxgooglemappro/cbxgooglemappro.php'];
401 }
402
403
404 $remote_version = '1.0.6';
405
406 if ( version_compare( $plugin_info['Version'], $remote_version, '<' ) ) {
407 $obj = new stdClass();
408 $obj->slug = 'cbxgooglemappro';
409 $obj->new_version = $remote_version;
410 $obj->plugin = 'cbxgooglemappro/cbxgooglemappro.php';
411 $obj->url = '';
412 $obj->package = false;
413 $obj->name = 'CBX Map for Google Map & OpenStreetMap Pro Addon';
414 $transient->response['cbxgooglemappro/cbxgooglemappro.php'] = $obj;
415 }
416
417 return $transient;
418 }//end pre_set_site_transient_update_plugins_pro_addon
419
420 /**
421 * Pro Addon update message
422 */
423 public function plugin_update_message_pro_addon() {
424 echo ' ' . sprintf( __( 'Check how to <a style="color:#9c27b0 !important; font-weight: bold;" href="%s"><strong>Update manually</strong></a> , download the latest version from <a style="color:#9c27b0 !important; font-weight: bold;" href="%s"><strong>My Account</strong></a> section of Codeboxr.com', 'cbxgooglemap' ), 'https://codeboxr.com/manual-update-pro-addon/', 'https://codeboxr.com/my-account/' );
425 }//end plugin_update_message_pro_addon
426
427
428 /**
429 * Do some housekeeping
430 *
431 * @return void
432 */
433 public function house_keepings(){
434 if ( ! function_exists( 'is_plugin_active' ) ) {
435 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
436 }
437
438 if (defined( 'CBXGOOGLEMAPPRO_PLUGIN_NAME' ) || in_array( 'cbxgooglemappro/cbxgooglemappro.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
439 //plugin is activated
440
441 $plugin_version = CBXGOOGLEMAPPRO_PLUGIN_VERSION;
442
443 if ( version_compare( $plugin_version, '1.0.5', '<=' ) ) {
444 deactivate_plugins( 'cbxgooglemappro/cbxgooglemappro.php' );
445 set_transient( 'cbxgooglemappro_deactivated_notice', 1 );
446 }
447 }
448 }//end method house_keepings
449 }//end class CBXGoogleMap