PluginProbe
CBX Map for Google Map & OpenStreetMap / 2.0.3
CBX Map for Google Map & OpenStreetMap v2.0.3
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.3, at includes/CBXGoogleMap.php

214 lines 6.8 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 add_action( 'plugins_loaded', [ $misc, 'plugin_upgrader_process_complete' ] );
120 add_action( 'admin_notices', [ $misc, 'plugin_activate_upgrade_notices' ] );
121 add_filter( 'plugin_action_links_' . CBXGOOGLEMAP_BASE_NAME, [ $misc, 'plugin_listing_setting_link' ] );
122 add_filter( 'plugin_row_meta', [ $misc, 'custom_plugin_row_meta' ], 10, 4 );
123
124 add_action( 'activated_plugin', [ $misc, 'check_pro_addon' ] );
125 add_action( 'init', [ $misc, 'check_pro_addon' ] );
126 add_action( 'after_plugin_row_cbxgooglemappro/cbxgooglemappro.php', [
127 $misc,
128 'custom_message_after_plugin_row_proaddon'
129 ], 10, 2 );
130
131 }//end method define_common_hooks
132
133 /**
134 * Register all of the hooks related to the admin area functionality
135 * of the plugin.
136 *
137 * @since 1.0.0
138 * @access private
139 */
140 private function define_admin_hooks() {
141 global $wp_version;
142 $plugin_admin = new CBXGoogleMapAdmin();
143
144 //adding the setting action
145 add_action( 'admin_init', [ $plugin_admin, 'setting_init' ] );
146 //add new post type
147 add_action( 'init', [ $plugin_admin, 'create_post_type' ], 0 );
148 //create opverview menu page
149 add_action( 'admin_menu', [ $plugin_admin, 'menu_pages' ] );
150 //display meta fields
151 add_action( 'add_meta_boxes', [ $plugin_admin, 'add_meta_boxes' ] );
152 //save meta fields
153 add_action( 'save_post', [ $plugin_admin, 'metabox_save' ], 10, 3 ); //save meta
154 add_action( 'wp_ajax_cbxgooglemap_settings_reset_load', [ $plugin_admin, 'settings_reset_load' ] );
155 add_action( 'wp_ajax_cbxgooglemap_settings_reset', [ $plugin_admin, 'plugin_options_reset' ] );
156 // Export/Import Settings Api
157 add_action( 'template_redirect', [ $plugin_admin, 'settings_export' ] );
158 add_action( 'wp_ajax_cbxgooglemap_settings_import', [ $plugin_admin, 'settings_import' ] );
159 add_action( 'wp_ajax_cbxgooglemap_settings_reset_section', [ $plugin_admin, 'plugin_reset_section' ] );
160
161 add_filter( 'manage_edit-cbxgooglemap_columns', [ $plugin_admin, 'cbxgooglemap_add_new_columns' ] );
162 add_action( 'manage_cbxgooglemap_posts_custom_column', [ $plugin_admin, 'cbxgooglemap_manage_columns' ] );
163 //js and css
164 add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueue_styles' ] );
165 add_action( 'admin_enqueue_scripts', [ $plugin_admin, 'enqueue_scripts' ] );
166
167 //gutenberg
168 add_action( 'init', [ $plugin_admin, 'gutenberg_blocks' ] );
169
170 //gutenberg blocks
171 if ( version_compare( $wp_version, '5.8' ) >= 0 ) {
172 add_filter( 'block_categories_all', [ $plugin_admin, 'gutenberg_block_categories' ], 10, 2 );
173 } else {
174 add_filter( 'block_categories', [ $plugin_admin, 'gutenberg_block_categories' ], 10, 2 );
175 }
176
177 //add_filter( 'block_categories', $plugin_admin, 'gutenberg_block_categories', 10, 2 );
178 add_action( 'enqueue_block_editor_assets', [ $plugin_admin, 'enqueue_block_editor_assets' ] );
179 }//end define_admin_hooks
180
181 /**
182 * Register all of the hooks related to the public-facing functionality
183 * of the plugin.
184 *
185 * @since 1.0.0
186 * @access private
187 */
188 private function define_public_hooks() {
189 $plugin_public = new CBXGoogleMapPublic();
190
191 add_action( 'init', [ $plugin_public, 'init_shortcodes' ] );
192 add_action( 'widgets_init', [ $plugin_public, 'register_widget' ] );
193
194 //elementor
195 add_action( 'elementor/widgets/widgets_registered', [ $plugin_public, 'init_elementor_widgets' ] );
196 add_action( 'elementor/elements/categories_registered', [ $plugin_public, 'add_elementor_widget_categories' ] );
197 add_action( 'elementor/editor/before_enqueue_scripts', [ $plugin_public, 'elementor_icon_loader' ], 99999 );
198
199 add_action( 'wp_enqueue_scripts', [ $plugin_public, 'enqueue_styles' ] );
200 add_action( 'wp_enqueue_scripts', [ $plugin_public, 'enqueue_scripts' ] );
201 }//end method define_public_hooks
202
203 /**
204 * Show php version notice in dashboard
205 *
206 * @return void
207 */
208 public function php_version_notice() {
209 echo '<div class="error"><p>';
210 /* Translators: PHP Version */
211 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));
212 echo '</p></div>';
213 }//end method php_version_notice
214 }//end class CBXGoogleMap