PluginProbe
CBX Map for Google Map & OpenStreetMap / 2.0.1
CBX Map for Google Map & OpenStreetMap v2.0.1
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.1, at includes/CBXGoogleMap.php

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