PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / 2.6.1
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More v2.6.1
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 47 releases
← All changes | classes/Plugin/Core.php +157 -56 2.0.122.6.1 View file →
@@ -18,8 +18,10 @@
18 18 /**
19 19 * Class Plugin
20 20 *
21 21 * @package ContentControl\Plugin
22 + *
23 + * @version 2.0.0
22 24 */
23 25 class Core {
24 26
25 27 /**
@@ -47,8 +49,9 @@
47 49 $this->container = new Container( $config );
48 50 $this->controllers = new Container();
49 51
50 52 $this->register_services();
53 + $this->define_paths();
51 54 $this->initiate_controllers();
52 55
53 56 $this->check_version();
54 57
@@ -59,11 +62,11 @@
59 62 * Update & track version info.
60 63 *
61 64 * @return void
62 65 */
63 - private function check_version() {
66 + protected function check_version() {
64 67 $version = $this->get( 'version' );
65 - $option_key = 'content_control_version';
68 + $option_key = "{$this->get( 'option_prefix' )}_version";
66 69
67 70 $current_data = \get_option( $option_key, false );
68 71
69 72 $data = wp_parse_args(
@@ -88,11 +91,12 @@
88 91 * Fires when the plugin version is updated.
89 92 *
90 93 * Note: Old version is still available in options.
91 94 *
92 - * @param string $version The new version.
95 + * @param string $old_version The old version.
96 + * @param string $new_version The new version.
93 97 */
94 - do_action( 'content_control/update_version', $data['version'] );
98 + do_action( "{$this->get( 'option_prefix' )}/update_version", $data['version'], $version );
95 99
96 100 // Save Upgraded From option.
97 101 $data['upgraded_from'] = $data['version'];
98 102 $data['version'] = $version;
@@ -108,19 +112,35 @@
108 112 *
109 113 * @param array<string,string|null> $data Array of data.
110 114 * @return array<string,string|null>
111 115 */
112 - private function process_version_data_migration( $data ) {
113 - $has_old_settings_data = \get_option( 'jp_cc_settings', false );
114 - $has_old_install_date = \get_option( 'jp_cc_reviews_installed_on', false );
116 + protected function process_version_data_migration( $data ) {
117 + // This class can be extended for addons, only do the following if this is core and not an extended class.
118 + // If the current instance is not an extended class, check if old settings exist.
119 + if ( get_called_class() === __CLASS__ ) {
120 + // Check if old settings exist.
121 + $has_old_settings_data = \get_option( 'content_control_settings', false );
122 + $has_old_install_date = \get_option( 'content_control_installed_on', false );
115 123
116 - // Check if old settings exist.
117 - if ( false !== $has_old_settings_data || false !== $has_old_install_date ) {
118 - $data = [
119 - 'version' => '1.1.9',
120 - 'upgraded_from' => null,
121 - 'initial_version' => '1.1.9',
122 - ];
124 + if ( false !== $has_old_settings_data || false !== $has_old_install_date ) {
125 + $data = [
126 + 'version' => '1.1.9',
127 + 'upgraded_from' => null,
128 + 'initial_version' => '1.1.9',
129 + ];
130 + }
131 +
132 + $has_old_settings_data = \get_option( 'jp_cc_settings', false );
133 + $has_old_install_date = \get_option( 'jp_cc_reviews_installed_on', false );
134 +
135 + // Check if old settings exist.
136 + if ( false !== $has_old_settings_data || false !== $has_old_install_date ) {
137 + $data = [
138 + 'version' => '1.1.9',
139 + 'upgraded_from' => null,
140 + 'initial_version' => '1.1.9',
141 + ];
142 + }
123 143 }
124 144
125 145 if ( empty( $data['initial_version'] ) ) {
126 146 $oldest_known = $data['version'];
@@ -157,60 +177,121 @@
157 177
158 178 /**
159 179 * Attach our container to the global.
160 180 */
161 - $GLOBALS['content_control'] = $this->container;
181 + $GLOBALS[ $this->get( 'option_prefix' ) ] = $this->container;
162 182
163 - $this->container['options'] = function ( $c ) {
164 - return new Options( $c->get( 'option_prefix' ) );
165 - };
183 + if ( get_called_class() === __CLASS__ ) {
184 + $this->container['options'] =
185 + /**
186 + * Get plugin options.
187 + *
188 + * @return Options
189 + */
190 + function ( $c ) {
191 + return new Options( $c->get( 'option_prefix' ) );
192 + };
166 193
167 - $this->container['connect'] = function ( $c ) {
168 - return new \ContentControl\Plugin\Connect( $c );
169 - };
194 + $this->container['connect'] =
195 + /**
196 + * Get plugin connect.
197 + *
198 + * @return Connect
199 + */
200 + function ( $c ) {
201 + return new \ContentControl\Plugin\Connect( $c );
202 + };
170 203
171 - $this->container['license'] = function () {
172 - return new \ContentControl\Plugin\License();
173 - };
204 + $this->container['license'] =
205 + /**
206 + * Get plugin license.
207 + *
208 + * @return License
209 + */
210 + function () {
211 + return new \ContentControl\Plugin\License();
212 + };
174 213
175 - $this->container['logging'] = function () {
176 - return new \ContentControl\Plugin\Logging();
177 - };
214 + $this->container['logging'] =
215 + /**
216 + * Get plugin logging.
217 + *
218 + * @return Logging
219 + */
220 + function () {
221 + return new \ContentControl\Plugin\Logging();
222 + };
178 223
179 - $this->container['upgrader'] = function ( $c ) {
180 - return new \ContentControl\Plugin\Upgrader( $c );
181 - };
224 + $this->container['upgrader'] =
225 + /**
226 + * Get plugin upgrader.
227 + *
228 + * @return Upgrader
229 + */
230 + function ( $c ) {
231 + return new \ContentControl\Plugin\Upgrader( $c );
232 + };
182 233
183 - $this->container['rules'] = function () {
184 - return new \ContentControl\RuleEngine\Rules();
185 - };
234 + $this->container['rules'] =
235 + /**
236 + * Get plugin rules.
237 + *
238 + * @return \ContentControl\RuleEngine\Rules
239 + */
240 + function () {
241 + return new \ContentControl\RuleEngine\Rules();
242 + };
186 243
187 - $this->container['restrictions'] = function () {
188 - return new \ContentControl\Services\Restrictions();
189 - };
244 + $this->container['restrictions'] =
245 + /**
246 + * Get plugin restrictions.
247 + *
248 + * @return \ContentControl\Services\Restrictions
249 + */
250 + function () {
251 + return new \ContentControl\Services\Restrictions();
252 + };
190 253
191 - apply_filters( 'content_control/register_services', $this->container, $this );
254 + $this->container['globals'] =
255 + /**
256 + * Get plugin global manager.
257 + *
258 + * @return \ContentControl\Services\Globals
259 + */
260 + function () {
261 + return new \ContentControl\Services\Globals();
262 + };
263 + }
264 +
265 + apply_filters( "{$this->get( 'option_prefix' )}/register_services", $this->container, $this );
192 266 }
193 267
194 268 /**
269 + * Update & track version info.
270 + *
271 + * @return array<string,\ContentControl\Base\Controller>
272 + */
273 + protected function registered_controllers() {
274 + return [
275 + 'PostTypes' => new \ContentControl\Controllers\PostTypes( $this ),
276 + 'Assets' => new \ContentControl\Controllers\Assets( $this ),
277 + 'Admin' => new \ContentControl\Controllers\Admin( $this ),
278 + 'Compatibility' => new \ContentControl\Controllers\Compatibility( $this ),
279 + 'RestAPI' => new \ContentControl\Controllers\RestAPI( $this ),
280 + 'BlockEditor' => new \ContentControl\Controllers\BlockEditor( $this ),
281 + 'Frontend' => new \ContentControl\Controllers\Frontend( $this ),
282 + 'Shortcodes' => new \ContentControl\Controllers\Shortcodes( $this ),
283 + 'TrustedLoginController' => new \ContentControl\Controllers\TrustedLogin( $this ),
284 + ];
285 + }
286 +
287 + /**
195 288 * Initiate internal components.
196 289 *
197 290 * @return void
198 291 */
199 - private function initiate_controllers() {
200 - $this->define_paths();
201 -
202 - $this->register_controllers( [
203 - 'PostTypes' => new \ContentControl\Controllers\PostTypes( $this ),
204 - 'Assets' => new \ContentControl\Controllers\Assets( $this ),
205 - 'Admin' => new \ContentControl\Controllers\Admin( $this ),
206 - 'Compatibility' => new \ContentControl\Controllers\Compatibility( $this ),
207 - 'RestAPI' => new \ContentControl\Controllers\RestAPI( $this ),
208 - 'BlockEditor' => new \ContentControl\Controllers\BlockEditor( $this ),
209 - 'Frontend' => new \ContentControl\Controllers\Frontend( $this ),
210 - 'Shortcodes' => new \ContentControl\Controllers\Shortcodes( $this ),
211 - 'TrustedLogin' => new \ContentControl\Controllers\TrustedLogin( $this ),
212 - ] );
292 + protected function initiate_controllers() {
293 + $this->register_controllers( $this->registered_controllers() );
213 294 }
214 295
215 296 /**
216 297 * Register controllers.
@@ -220,9 +301,11 @@
220 301 */
221 302 public function register_controllers( $controllers = [] ) {
222 303 foreach ( $controllers as $name => $controller ) {
223 304 if ( $controller instanceof Controller ) {
224 - $controller->init();
305 + if ( $controller->controller_enabled() ) {
306 + $controller->init();
307 + }
225 308 $this->controllers->set( $name, $controller );
226 309 }
227 310 }
228 311 }
@@ -248,9 +331,9 @@
248 331 * Initiate internal paths.
249 332 *
250 333 * @return void
251 334 */
252 - private function define_paths() {
335 + protected function define_paths() {
253 336 /**
254 337 * Attach utility functions.
255 338 */
256 339 $this->container['get_path'] = [ $this, 'get_path' ];
@@ -287,13 +370,31 @@
287 370 *
288 371 * @return mixed Current value of the item.
289 372 */
290 373 public function get( $id ) {
291 - if ( ! $this->container->offsetExists( $id ) ) {
374 + // 1. Check if the item exists in the container.
375 + if ( $this->container->offsetExists( $id ) ) {
376 + return $this->container->get( $id );
377 + }
378 +
379 + // 2. Check if the item exists in the controllers container.
380 + if ( $this->controllers->offsetExists( $id ) ) {
292 381 return $this->controllers->get( $id );
293 382 }
294 383
295 - return $this->container->get( $id );
384 + // 3. Check if the item exists in the global space.
385 + if ( get_called_class() !== __CLASS__ ) {
386 + // If this is an addon, check if the service exists in the core plugin.
387 + // Get core plugin container and see if the service exists there.
388 + $plugin_service = \ContentControl\plugin( $id );
389 +
390 + if ( $plugin_service ) {
391 + return $plugin_service;
392 + }
393 + }
394 +
395 + // 5. Return null, item not found.
396 + return null;
296 397 }
297 398
298 399 /**
299 400 * Set item in container
@@ -366,9 +467,9 @@
366 467 *
367 468 * @return boolean
368 469 */
369 470 public function is_pro_active() {
370 - return $this->is_pro_installed() && class_exists( '\ContentControlPro\Plugin\Core' );
471 + return $this->is_pro_installed() && function_exists( '\ContentControl\Pro\plugin' );
371 472 }
372 473
373 474 /**
374 475 * Check if license is active.