PluginProbe
CBX Map for Google Map & OpenStreetMap / 2.0.2
CBX Map for Google Map & OpenStreetMap v2.0.2
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 / CBXGoogleMap.php

CBXGoogleMap.php in CBX Map for Google Map & OpenStreetMap 2.0.2, at includes/CBXGoogleMap.php

217 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // If this file is called directly, abort.
3 if ( ! defined( 'WPINC' ) ) {
4 die;
5 }
6
7 use Cbx\Googlemap\CBXGoogleMapAdmin;
8 use Cbx\Googlemap\CBXGoogleMapMisc;
9 use Cbx\Googlemap\CBXGoogleMapPublic;
10
11 /**
12 * The core plugin class.
13 *
14 * This is used to define internationalization, admin-specific hooks, and
15 * public-facing site hooks.
16 *
17 * Also maintains the unique identifier of this plugin as well as the current
18 * version of the plugin.
19 *
20 * @since 1.0.0
21 * @package Cbxgooglemap
22 * @subpackage Cbxgooglemap/includes
23 * @author Codeboxr <info@codeboxr.com>
24 */
25 final class CBXGoogleMap {
26 /**
27 * The single instance of the class.
28 *
29 * @var self
30 * @since 1.1.12
31 */
32 private static $instance = null;
33
34 /**
35 * The unique identifier of this plugin.
36 *
37 * @since 1.0.0
38 * @access protected
39 * @var string $plugin_name The string used to uniquely identify this plugin.
40 */
41 protected $plugin_name;
42
43 /**
44 * The current version of the plugin.
45 *
46 * @since 1.0.0
47 * @access protected
48 * @var string $version The current version of the plugin.
49 */
50 protected $version;
51
52 /**
53 * The ID of this plugin.
54 *
55 * @since 1.1.12
56 * @access private
57 * @var string $settings The ID of this plugin.
58 */
59 private $settings;
60
61 /**
62 * Define the core functionality of the plugin.
63 *
64 * Set the plugin name and the plugin version that can be used throughout the plugin.
65 * Load the dependencies, define the locale, and set the hooks for the admin area and
66 * the public-facing side of the site.
67 *
68 * @since 1.0.0
69 */
70 public function __construct() {
71 $this->plugin_name = CBXGOOGLEMAP_PLUGIN_NAME;
72 $this->version = CBXGOOGLEMAP_PLUGIN_VERSION;
73
74 if ( cbxgooglemap_compatible_php_version() ) {
75 $GLOBALS['cbxgooglemap_loaded'] = true;
76 $this->include_files();
77
78
79
80 $this->define_common_hooks();
81 $this->define_admin_hooks();
82 $this->define_public_hooks();
83 }
84 else {
85 add_action( 'admin_notices', [ $this, 'php_version_notice' ] );
86 }
87 }//end method constructor
88
89 /**
90 * Include necessary files
91 *
92 * @return void
93 */
94 private function include_files() {
95 require_once __DIR__ . '/../vendor/autoload.php';
96 }//end method include_files
97
98 /**
99 * Singleton Instance.
100 *
101 * Ensures only one instance of cbxgooglemap is loaded or can be loaded.
102 *
103 * @return self Main instance.
104 * @see cbxgooglemap_run()
105 * @since 1.1.12
106 * @static
107 */
108 public static function instance() {
109 if ( is_null( self::$instance ) ) {
110 self::$instance = new self();
111 }
112
113 return self::$instance;
114 }//end method instance
115
116 private function define_common_hooks() {
117 $misc = new CBXGoogleMapMisc();
118
119 //upgrade process
120 //add_action('admin_init', [$misc, 'admin_init_upgrader_process']);
121 //add_action( 'upgrader_process_complete', [ $misc, 'plugin_upgrader_process_complete' ], 10, 2 );
122
123 add_action( 'plugins_loaded', [ $misc, 'plugin_upgrader_process_complete' ] );
124 add_action( 'admin_notices', [ $misc, 'plugin_activate_upgrade_notices' ] );
125 add_filter( 'plugin_action_links_' . CBXGOOGLEMAP_BASE_NAME, [ $misc, 'plugin_listing_setting_link' ] );
126 add_filter( 'plugin_row_meta', [ $misc, 'custom_plugin_row_meta' ], 10, 4 );
127
128 add_action( 'init', [ $misc, 'check_pro_addon' ] );
129 add_action( 'after_plugin_row_cbxgooglemappro/cbxgooglemappro.php', [
130 $misc,
131 'custom_message_after_plugin_row_proaddon'
132 ], 10, 2 );
133
134 }//end method define_common_hooks
135
136 /**
137 * Register all of the hooks related to the admin area functionality
138 * of the plugin.
139 *
140 * @since 1.0.0
141 * @access private
142 */
143 private function define_admin_hooks() {
144 global $wp_version;
145 $plugin_admin = new CBXGoogleMapAdmin();
146
147 //adding the setting action
148 add_action( 'admin_init', [ $plugin_admin, 'setting_init' ] );
149 //add new post type
150 add_action( 'init', [ $plugin_admin, 'create_post_type' ], 0 );
151 //create opverview menu page
152 add_action( 'admin_menu', [ $plugin_admin, 'menu_pages' ] );
153 //display meta fields
154 add_action( 'add_meta_boxes', [ $plugin_admin, 'add_meta_boxes' ] );
155 //save meta fields
156 add_action( 'save_post', [ $plugin_admin, 'metabox_save' ], 10, 3 ); //save meta
157 add_action( 'wp_ajax_cbxgooglemap_settings_reset_load', [ $plugin_admin, 'settings_reset_load' ] );
158 add_action( 'wp_ajax_cbxgooglemap_settings_reset', [ $plugin_admin, 'plugin_options_reset' ] );
159 // Export/Import Settings Api
160 add_action( 'template_redirect', [ $plugin_admin, 'settings_export' ] );
161 add_action( 'wp_ajax_cbxgooglemap_settings_import', [ $plugin_admin, 'settings_import' ] );
162 add_action( 'wp_ajax_cbxgooglemap_settings_reset_section', [ $plugin_admin, 'plugin_reset_section' ] );
163
164 add_filter( 'manage_edit-cbxgooglemap_columns', [ $plugin_admin, 'cbxgooglemap_add_new_columns' ] );
165 add_action( 'manage_cbxgooglemap_posts_custom_column', [ $plugin_admin, 'cbxgooglemap_manage_columns' ] );
166 //js and css
167 add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueue_styles' ] );
168 add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueue_scripts' ] );
169
170 //gutenberg
171 add_action( 'init', [ $plugin_admin, 'gutenberg_blocks' ] );
172
173 //gutenberg blocks
174 if ( version_compare( $wp_version, '5.8' ) >= 0 ) {
175 add_filter( 'block_categories_all', [ $plugin_admin, 'gutenberg_block_categories' ], 10, 2 );
176 } else {
177 add_filter( 'block_categories', [ $plugin_admin, 'gutenberg_block_categories' ], 10, 2 );
178 }
179
180 //add_filter( 'block_categories', $plugin_admin, 'gutenberg_block_categories', 10, 2 );
181 add_action( 'enqueue_block_editor_assets', [ $plugin_admin, 'enqueue_block_editor_assets' ] );
182 }//end define_admin_hooks
183
184 /**
185 * Register all of the hooks related to the public-facing functionality
186 * of the plugin.
187 *
188 * @since 1.0.0
189 * @access private
190 */
191 private function define_public_hooks() {
192 $plugin_public = new CBXGoogleMapPublic();
193
194 add_action( 'init', [ $plugin_public, 'init_shortcodes' ] );
195 add_action( 'widgets_init', [ $plugin_public, 'register_widget' ] );
196
197 //elementor
198 add_action( 'elementor/widgets/widgets_registered', [ $plugin_public, 'init_elementor_widgets' ] );
199 add_action( 'elementor/elements/categories_registered', [ $plugin_public, 'add_elementor_widget_categories' ] );
200 add_action( 'elementor/editor/before_enqueue_scripts', [ $plugin_public, 'elementor_icon_loader' ], 99999 );
201
202 add_action( 'wp_enqueue_scripts', [ $plugin_public, 'enqueue_styles' ] );
203 add_action( 'wp_enqueue_scripts', [ $plugin_public, 'enqueue_scripts' ] );
204 }//end method define_public_hooks
205
206 /**
207 * Show php version notice in dashboard
208 *
209 * @return void
210 */
211 public function php_version_notice() {
212 echo '<div class="error"><p>';
213 /* Translators: PHP Version */
214 echo sprintf(esc_html__( 'CBX Map requires at least PHP %s. Please upgrade PHP to run CBX Map.', 'cbxgooglemap' ), esc_attr(CBXGOOGLEMAP_PHP_MIN_VERSION));
215 echo '</p></div>';
216 }//end method php_version_notice
217 }//end class CBXGoogleMap