Completed
Pull Request — master (#208)
by Devin
20:05
created

Google_Maps_Builder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 3
b 1
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 27 and the first side effect is on line 53.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Maps Builder
4
 *
5
 * Plugin Name:       Maps Builder
6
 * Plugin URI:        http://wordimpress.com/
7
 * Description:       Create stylish and powerful Google Maps quickly and easily.
8
 * Version:           2.1
9
 * Author:            WordImpress
10
 * Author URI:        http://wordimpress.com/
11
 * Text Domain:       google-maps-builder
12
 * License:           GPL-2.0+
13
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
14
 * Domain Path:       /languages
15
 */
16
17
// If this file is called directly, abort.
18
if ( ! defined( 'ABSPATH' ) ) {
19
	exit;
20
}
21
22
/**
23
 * Define Constants
24
 */
25
// Plugin Folder Path
26
if ( ! defined( 'GMB_PLUGIN_PATH' ) ) {
27
	define( 'GMB_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
28
}
29
// Plugin Folder URL
30
if ( ! defined( 'GMB_PLUGIN_URL' ) ) {
31
	define( 'GMB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
32
}
33
// Plugin base
34
if ( ! defined( 'GMB_PLUGIN_BASE' ) ) {
35
	define( 'GMB_PLUGIN_BASE', plugin_basename( __FILE__ ) );
36
}
37
// Plugin version
38
if ( ! defined( 'GMB_VERSION' ) ) {
39
	define( 'GMB_VERSION', '2.1' );
40
}
41
// Plugin Root File
42
if ( ! defined( 'GMB_PLUGIN_FILE' ) ) {
43
	define( 'GMB_PLUGIN_FILE', __FILE__ );
44
}
45
46
47
if ( ! class_exists( 'Google_Maps_Builder' ) ) :
48
49
	/**
50
	 * Load plugin if core lib is present
51
	 */
52
	if ( ! file_exists( GMB_PLUGIN_PATH . 'vendor/wordimpress/maps-builder-core/core.php' ) ) {
53
		add_action( 'admin_notices', 'gmb_no_core_lib' );
54
55
		/**
56
		 * Print admin notice if no dependencies
57
		 *
58
		 * @uses "admin_notice" hook
59
		 */
60
		function gmb_no_core_lib() {
61
			printf( '<div class="notice notice-error"><p>%s</p></div>', esc_html__( 'Your install of Maps Builder is missing its Composer dependencies and can not load.', 'maps-builder-pro' ) );
62
		}
63
	} else {
64
		require_once GMB_PLUGIN_PATH . 'vendor/wordimpress/maps-builder-core/core.php';
65
66
		/**
67
		 * Main Maps Builder Class
68
		 *
69
		 * @since 2.0
70
		 */
71
		final class Google_Maps_Builder extends Google_Maps_Builder_Core {
72
73
74
			/**
75
			 * @var Google_Maps_Builder The one true Google Maps Builder instance
76
			 * @since 2.0
77
			 */
78
			private static $instance;
79
80
			/**
81
			 * Prevent new instances
82
			 */
83
			private function __construct() {
84
				//you can not haz instance
85
			}
86
87
			/**
88
			 * User meta key for marking welcome message as dismissed
89
			 *
90
			 * @since 2.1.0
91
			 *
92
			 * @var string
93
			 */
94
			protected $hide_welcome_key = 'gmb_hide_welcome';
95
96
			/**
97
			 * Main Google_Maps_Builder Instance
98
			 *
99
			 * Insures that only one instance of Google_Maps_Builder exists in memory at any one
100
			 * time. Also prevents needing to define globals all over the place.
101
			 *
102
			 * @since     2.0
103
			 * @static
104
			 * @static    var array $instance
105
			 * @uses      Google_Maps_Builder::setup_constants() Setup the constants needed
106
			 * @uses      Google_Maps_Builder::includes() Include the required files
107
			 * @uses      Google_Maps_Builder::load_textdomain() load the language files
108
			 * @see       Google_Maps_Builder()
109
			 * @return    Google_Maps_Builder
110
			 */
111
			public static function instance() {
112
				if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Google_Maps_Builder ) ) {
113
114
					self::$instance = new Google_Maps_Builder();
115
116
					add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) );
117
118
					self::$instance->includes();
119
					self::$instance->activate = new Google_Maps_Builder_Activate();
120
					self::$instance->scripts  = new Google_Maps_Builder_Scripts();
121
					self::$instance->settings = new Google_Maps_Builder_Settings();
122
					self::$instance->engine   = new Google_Maps_Builder_Engine();
123
124
					register_activation_hook( __FILE__, array(
125
						self::$instance->activate,
126
						'activation_flush_rewrites'
127
					) );
128
129
					// Read plugin meta
130
					// Check that function get_plugin_data exists
131
					if ( ! function_exists( 'get_plugin_data' ) ) {
132
						require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
133
					}
134
					self::$instance->meta = get_plugin_data( GMB_PLUGIN_FILE, false );
135
136
				}
137
138
				return self::$instance;
139
			}
140
141
142
			/**
143
			 * Include required files
144
			 *
145
			 * @access protected
146
			 * @since  2.0
147
			 * @return void
148
			 */
149
			protected function includes() {
150
				$this->include_core_classes();
151
				$this->load_activate();
152
153
				$this->cmb2_load();
154
				$this->load_files();
155
				require_once GMB_PLUGIN_PATH . 'includes/class-gmb-scripts.php';
156
157
				if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
158
159
					$this->load_admin();
160
					//Admin
161
162
					//@TODO only load when needed
163
					$this->init_map_editor_admin();
164
165
				}
166
167
			}
168
169
		}
170
171
	}
172
173
endif; // End if class_exists check
174
175