PluginProbe
GeoDirectory – WP Business Directory Plugin and Classified Listings Directory / 2.8.172
GeoDirectory – WP Business Directory Plugin and Classified Listings Directory v2.8.172
2.8.179 2.8.178 2.8.176 2.8.177 2.8.175 2.8.173 2.8.174 2.8.172 2.8.171 2.8.170 2.8.169 2.8.168 2.8.167 2.8.166 2.8.165 2.8.164 2.8.163 2.8.162 2.8.161 2.8.160 2.8.159 2.1.0.14 2.1.0.15 2.1.0.16 2.1.0.17 All 383 releases
geodirectory / geodirectory.php

geodirectory.php in GeoDirectory – WP Business Directory Plugin and Classified Listings Directory 2.8.172, at geodirectory.php

560 lines 16.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This is the main GeoDirectory plugin file, here we declare and call the important stuff
4 *
5 * @package GeoDirectory
6 * @copyright 2019 AyeCode Ltd
7 * @license GPL-2.0+
8 * @since 1.0.0
9 *
10 * @wordpress-plugin
11 * Plugin Name: GeoDirectory
12 * Plugin URI: https://wpgeodirectory.com/
13 * Description: GeoDirectory - Business Directory Plugin for WordPress.
14 * Version: 2.8.172
15 * Author: AyeCode - WP Business Directory Plugins
16 * Author URI: https://wpgeodirectory.com
17 * Text Domain: geodirectory
18 * Domain Path: /languages
19 * Requires at least: 6.0
20 * Tested up to: 7.0
21 */
22
23 if ( ! class_exists( 'GeoDirectory' ) ) :
24
25 /**
26 * Main GeoDirectory Class.
27 *
28 * @class GeoDirectory
29 * @version 2.0.0
30 */
31 final class GeoDirectory {
32 /**
33 * GeoDirectory version.
34 *
35 * @var string
36 */
37 public $version = '2.8.172';
38
39 /**
40 * GeoDirectory instance.
41 *
42 * @access private
43 * @since 2.0.0
44 * @var GeoDirectory The one true GeoDirectory
45 */
46 private static $instance = null;
47
48 /**
49 * The settings instance variable
50 *
51 * @access public
52 * @since 2.0.0
53 * @var GeoDirectory_Settings
54 */
55 public $settings;
56
57 /**
58 * Query instance.
59 *
60 * @var GeoDir_Query
61 */
62 public $query = null;
63
64 /**
65 * API instance
66 *
67 * @var GeoDir_API
68 */
69 public $api;
70
71 /**
72 * API instance
73 *
74 * @var GeoDir_Location
75 */
76 public $location;
77
78 /**
79 * API instance
80 *
81 * @var GeoDir_Permalinks
82 */
83 public $permalinks;
84
85 /**
86 * API instance
87 *
88 * @var GeoDir_Taxonomies
89 */
90 public $taxonomies;
91
92 /**
93 * API instance
94 *
95 * @var GeoDir_Notifications
96 */
97 public $notifications = null;
98
99 /**
100 * Main GeoDirectory Instance.
101 *
102 * Ensures only one instance of GeoDirectory is loaded or can be loaded.
103 *
104 * @since 2.0.0
105 * @static
106 * @see GeoDir()
107 * @return GeoDirectory - Main instance.
108 */
109 public static function instance() {
110 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof GeoDirectory ) ) {
111 self::$instance = new GeoDirectory;
112 self::$instance->setup_constants();
113
114 add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) );
115
116 if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
117 add_action( 'admin_notices', array( self::$instance, 'php_version_notice' ) );
118
119 return self::$instance;
120 }
121
122 self::$instance->includes();
123 self::$instance->init_hooks();
124
125 do_action( 'geodirectory_loaded' );
126 }
127
128 return self::$instance;
129 }
130
131 /**
132 * Setup plugin constants.
133 *
134 * @access private
135 * @since 2.0.0
136 * @return void
137 */
138 private function setup_constants() {
139 global $wpdb, $plugin_prefix;
140
141 $upload_dir = wp_upload_dir( null, false );
142 $plugin_prefix = $wpdb->prefix . 'geodir_';
143
144 if ( $this->is_request( 'test' ) ) {
145 $plugin_path = dirname( __FILE__ );
146 } else {
147 $plugin_path = plugin_dir_path( __FILE__ );
148 }
149
150 $this->define( 'GEODIRECTORY_VERSION', $this->version );
151 $this->define( 'GEODIRECTORY_PLUGIN_FILE', __FILE__ );
152 $this->define( 'GEODIRECTORY_PLUGIN_DIR', $plugin_path );
153 $this->define( 'GEODIRECTORY_PLUGIN_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) );
154 $this->define( 'GEODIRECTORY_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
155 $this->define( 'GEODIRECTORY_TEXTDOMAIN', 'geodirectory' );
156
157 // Database tables
158 $this->define( 'GEODIR_API_KEYS_TABLE', $plugin_prefix . 'api_keys' ); // rest api keys table
159 $this->define( 'GEODIR_ATTACHMENT_TABLE', $plugin_prefix . 'attachments' ); // attachments table
160 $this->define( 'GEODIR_CUSTOM_FIELDS_TABLE', $plugin_prefix . 'custom_fields' ); // custom fields table
161 $this->define( 'GEODIR_TABS_LAYOUT_TABLE', $plugin_prefix . 'tabs_layout' ); // custom fields table
162 $this->define( 'GEODIR_CUSTOM_SORT_FIELDS_TABLE', $plugin_prefix . 'custom_sort_fields' ); // custom sort fields table
163 $this->define( 'GEODIR_REVIEW_TABLE', $plugin_prefix . 'post_review' ); // post review table
164 $this->define( 'GEODIR_POST_REPORTS_TABLE', $plugin_prefix . 'post_reports' ); // post reports table
165
166 $this->define( 'GEODIR_ROUNDING_PRECISION', 4 );
167
168 // Do not store any revisions (except the one autosave per post).
169 $this->define( 'WP_POST_REVISIONS', 0 );
170
171 $this->define( 'GEODIR_REST_SLUG', 'geodir' );
172 $this->define( 'GEODIR_REST_API_VERSION', '2' );
173 }
174
175 /**
176 * Loads the plugin language files
177 *
178 * @access public
179 * @since 2.0.0
180 * @return void
181 */
182 public function load_textdomain() {
183 $locale = determine_locale();
184
185 /**
186 * Filter the plugin locale.
187 *
188 * @since 1.4.2
189 * @package GeoDirectory
190 */
191 $locale = apply_filters( 'plugin_locale', $locale, 'geodirectory' );
192
193 unload_textdomain( 'geodirectory', true );
194 load_textdomain( 'geodirectory', WP_LANG_DIR . '/geodirectory/geodirectory-' . $locale . '.mo' );
195 load_plugin_textdomain( 'geodirectory', false, basename( dirname( GEODIRECTORY_PLUGIN_FILE ) ) . '/languages/' );
196 }
197
198 /**
199 * Show a warning to sites running PHP < 5.3
200 *
201 * @static
202 * @access private
203 * @since 2.0.0
204 * @return void
205 */
206 public static function php_version_notice() {
207 echo '<div class="error"><p>' . esc_html__( 'Your version of PHP is below the minimum version of PHP required by GeoDirectory. Please contact your host and request that your version be upgraded to 5.3 or later.', 'geodirectory' ) . '</p></div>';
208 }
209
210 /**
211 * Include required files.
212 *
213 * @access private
214 * @since 2.0.0
215 * @return void
216 */
217 private function includes() {
218 global $pagenow, $geodir_options, $wp_version;
219
220 // composer autoloader
221 require_once( GEODIRECTORY_PLUGIN_DIR . 'vendor/autoload.php' );
222
223 /**
224 * Class autoloader.
225 */
226 include_once( GEODIRECTORY_PLUGIN_DIR . 'includes/class-geodir-autoloader.php' );
227
228 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/formatting-functions.php' );
229 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/deprecated-functions.php' );
230 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/core-functions.php' );
231 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/class-geodir-datetime.php' );
232 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/admin/settings/functions.php' );
233 $this->settings = $geodir_options = geodir_get_settings();
234
235 include_once( GEODIRECTORY_PLUGIN_DIR . 'includes/class-geodir-post-types.php' ); // Registers post types
236
237 GeoDir_Email::init();// set up the email class
238 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/helper-functions.php' );
239 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/validation-functions.php' );
240 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/user-functions.php' );
241 GeoDir_AJAX::init();
242 GeoDir_Post_Data::init(); // post data
243 GeoDir_Post_Limit::init(); // Posts limit
244 //GeoDir_Post_Revision::init(); // post revisions @todo not implemented yet
245 GeoDir_Compatibility::init(); // plugin/theme comaptibility checks
246 GeoDir_Classifieds::init();
247
248 if( defined( 'ELEMENTOR_VERSION' ) ){
249 GeoDir_Elementor::init();
250 }
251
252 // Block Theme comaptibility
253 if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
254 GeoDir_Block_Theme::init();
255 }
256
257 GeoDir_SEO::init();
258
259 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/general-functions.php' );
260 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/template-functions.php' );
261 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/post-functions.php' );
262 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/image-functions.php' );
263 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/post-types-functions.php' );
264 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/taxonomy-functions.php' );
265 if ( geodir_design_style() ) {
266 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/custom-fields/input-functions-aui.php' );
267 } else {
268 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/custom-fields/input-functions.php' );
269 }
270 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/custom-fields/output-functions.php' );
271 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/custom-fields/output-filter-functions.php' );
272 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/custom-fields/functions.php' );
273 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/comments-functions.php' );
274 GeoDir_Comments::init();
275 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/location-functions.php' );
276 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/business-hours-functions.php' );
277 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/classifieds-functions.php' );
278 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/class-geodir-maps.php' );
279 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/class-geodir-frontend-scripts.php' );
280 //require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/class-geodir-permalinks.php' );
281
282 if ( geodir_design_style() ) {
283 GeoDir_Report_Post::init(); // Report Post
284 }
285
286 // BIG Data
287 if(!empty($this->settings['enable_big_data'])){
288 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/class-geodir-big-data.php' );
289 }
290
291
292 /**
293 * REST API.
294 */
295 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/class-geodir-api.php' );
296 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/class-geodir-auth.php' );
297 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/class-geodir-register-wp-admin-settings.php' );
298
299 if ( $this->is_request( 'admin' ) || $this->is_request( 'test' ) || $this->is_request( 'cli' ) ) {
300 if ( !empty( $_REQUEST['taxonomy'] ) ) {
301 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/admin/class-geodir-admin-taxonomies.php' );
302 }
303
304 new GeoDir_Admin(); // init the GD admin class
305
306 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/admin/admin-functions.php' );
307 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/admin/dashboard-functions.php' );
308 GeoDir_Admin_Install::init(); // init the install class
309 GeoDir_Admin_Upgrade::init(); // init the upgrade class
310 GeoDir_Admin_Tracker::init(); // tracking data
311 require_once( GEODIRECTORY_PLUGIN_DIR . 'upgrade.php' );
312
313 if( 'plugins.php' === $pagenow ) {
314 // Better update message
315 $file = basename( GEODIRECTORY_PLUGIN_FILE );
316 $folder = basename( dirname( GEODIRECTORY_PLUGIN_FILE ) );
317 $hook = "in_plugin_update_message-{$folder}/{$file}";
318 add_action( $hook, 'geodir_admin_upgrade_notice', 20, 2 );
319 }
320
321 if ( 'edit.php' === $pagenow || 'post.php' === $pagenow || 'post-new.php' == $pagenow || ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'inline-save' ) ) {
322 GeoDir_Admin_Post_View::init();
323 }
324 }
325
326 if ( $this->is_request( 'frontend' ) ) {
327 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/class-geodir-template-loader.php' ); // Template Loader
328 }
329
330 // If current WP Version >= 4.9.6.
331 if ( version_compare( $wp_version, '4.9.6', '>=' ) ) {
332 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/class-geodir-privacy.php' );
333 }
334
335 // @todo not ready for production yet
336 //require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/class-geodir-fse.php' );
337
338 $theme = wp_get_theme();
339
340 if ( 'blockstrap' === $theme->get_stylesheet() || 'blockstrap' === $theme->get_template() ) {
341 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/class-geodir-blockstrap.php' );
342 } else if ( 'Bricks' === $theme->get( 'Name' ) || 'bricks' === $theme->get( 'Template' ) ) {
343 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/integrations/bricks/class-geodir-bricks.php' );
344 require_once( GEODIRECTORY_PLUGIN_DIR . 'includes/integrations/bricks/class-geodir-bricks-query-filters.php' );
345 }
346
347 $this->query = new GeoDir_Query();
348 $this->api = new GeoDir_API();
349 }
350
351 /**
352 * Hook into actions and filters.
353 * @since 2.3
354 */
355 private function init_hooks() {
356 register_activation_hook( __FILE__, array( $this, 'on_activate' ) );
357 register_deactivation_hook( __FILE__, array( $this, 'on_deactivate' ) );
358
359 add_action( 'init', array( $this, 'init' ), 0 );
360 }
361
362 /**
363 * Handle plugin activate action.
364 *
365 * @since 2.2.7
366 *
367 * @param bool $network_wide Optional. Whether to enable the plugin for all sites in the network
368 * or just the current site. Multisite only. Default false.
369 */
370 public function on_activate( $network_wide = false ) {
371 if ( ! defined( 'GEODIR_ACTIVATING' ) ) {
372 define( 'GEODIR_ACTIVATING', true );
373 }
374
375 /**
376 * Fired on plugin activated.
377 *
378 * @param bool $network_wide Whether to enable the plugin for all sites in the network
379 * or just the current site. Multisite only. Default false.
380 */
381 do_action( 'geodir_on_activate_core_plugin', $network_wide );
382 }
383
384 /**
385 * Handle plugin deactivate action.
386 *
387 * @since 2.2.7
388 *
389 * @param bool $network_wide Optional. Whether to enable the plugin for all sites in the network
390 * or just the current site. Multisite only. Default false.
391 */
392 public function on_deactivate( $network_wide = false ) {
393 if ( ! defined( 'GEODIR_DEACTIVATING' ) ) {
394 define( 'GEODIR_DEACTIVATING', true );
395 }
396
397 // Delete Fast AJAX mu-plugin file.
398 if ( is_file( WPMU_PLUGIN_DIR . '/geodir-fast-ajax.php' ) && file_exists( WPMU_PLUGIN_DIR . '/geodir-fast-ajax.php' ) ) {
399 unlink( WPMU_PLUGIN_DIR . '/geodir-fast-ajax.php' );
400 }
401
402 /**
403 * Fired on plugin deactivated.
404 *
405 * @param bool $network_wide Whether to enable the plugin for all sites in the network
406 * or just the current site. Multisite only. Default false.
407 */
408 do_action( 'geodir_on_deactivate_core_plugin', $network_wide );
409 }
410
411 /**
412 * Init GeoDirectory when WordPress Initialises.
413 */
414 public function init() {
415 if ( ! defined( 'GEODIR_LATITUDE_ERROR_MSG' ) ) {
416 require_once( GEODIRECTORY_PLUGIN_DIR . 'language.php' ); // Define language constants.
417 }
418
419 // Before init action.
420 do_action( 'geodirectory_before_init' );
421
422 // locations
423 $location_class_name = apply_filters('geodir_class_location','GeoDir_Location');
424 $this->location = new $location_class_name;
425
426 // permalinks
427 $permalinks_class_name = apply_filters('geodir_class_permalinks','GeoDir_Permalinks');
428 $this->permalinks = new $permalinks_class_name;
429
430 // taxonomies
431 $taxonomies_class_name = apply_filters('geodir_class_taxonomies','GeoDir_Taxonomies');
432 $this->taxonomies = new $taxonomies_class_name;
433
434 // notifications
435 $notifications_class_name = apply_filters('geodir_class_notifications','GeoDir_Notifications');
436 $this->notifications = new $notifications_class_name;
437
438 // GD hints
439 if(geodir_get_option('enable_hints',1)){
440 if(current_user_can('administrator')) {
441 new GeoDir_Hints();
442 }
443 }
444
445 // Init action.
446 do_action( 'geodirectory_init' );
447 }
448
449 /**
450 * Define constant if not already set.
451 *
452 * @param string $name
453 * @param string|bool $value
454 */
455 private function define( $name, $value ) {
456 if ( ! defined( $name ) ) {
457 define( $name, $value );
458 }
459 }
460
461 /**
462 * Request type.
463 *
464 * @param string $type admin, frontend, ajax, cron, test or CLI.
465 * @return bool
466 */
467 private function is_request( $type ) {
468 switch ( $type ) {
469 case 'admin' :
470 return is_admin();
471 break;
472 case 'ajax' :
473 return defined( 'DOING_AJAX' );
474 break;
475 case 'cli' :
476 return ( defined( 'WP_CLI' ) && WP_CLI );
477 break;
478 case 'cron' :
479 return defined( 'DOING_CRON' );
480 break;
481 case 'frontend' :
482 return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
483 break;
484 case 'test' :
485 return defined( 'GD_TESTING_MODE' );
486 break;
487 }
488
489 return null;
490 }
491
492 /**
493 * Check the active theme.
494 *
495 * @since 2.0.0
496 * @param string $theme Theme slug to check.
497 * @return bool
498 */
499 private function is_active_theme( $theme ) {
500 return get_template() === $theme;
501 }
502
503 /**
504 * Get the plugin url.
505 *
506 * @return string
507 */
508 public function plugin_url() {
509 return untrailingslashit( plugins_url( '/', GEODIRECTORY_PLUGIN_FILE ) );
510 }
511
512 /**
513 * Get the plugin path.
514 *
515 * @return string
516 */
517 public function plugin_path() {
518 return untrailingslashit( plugin_dir_path( GEODIRECTORY_PLUGIN_FILE ) );
519 }
520
521 /**
522 * Get the template path.
523 *
524 * @return string
525 */
526 public function template_path() {
527 return trailingslashit( geodir_get_theme_template_dir_name() );
528 }
529
530 /**
531 * Get Ajax URL.
532 *
533 * @return string
534 */
535 public function ajax_url() {
536 return admin_url( 'admin-ajax.php', 'relative' );
537 }
538 }
539
540 endif;
541
542 /**
543 * The main function responsible for returning the one true GeoDirectory
544 * Instance to functions everywhere.
545 *
546 * Use this function like you would a global variable, except without needing
547 * to declare the global.
548 *
549 * Example: <?php $geodirectory = geodirectory(); ?>
550 *
551 * @since 2.0.0
552 * @return GeoDirectory The one true GeoDirectory Instance
553 */
554 function GeoDir() {
555 return GeoDirectory::instance();
556 }
557
558 // Global for backwards compatibility.
559 $GLOBALS['geodirectory'] = GeoDir();
560