PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / trunk
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More vtrunk
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
content-control / content-control.php

content-control.php in Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More trunk, at content-control.php

158 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Content Control
4 * Plugin URI: https://contentcontrolplugin.com/?utm_campaign=plugin-info&utm_source=php-file-header&utm_medium=plugin-ui&utm_content=plugin-uri
5 * Description: Restrict content to logged in/out users or specific user roles. Restrict access to certain parts of a page/post. Control the visibility of widgets.
6 * Version: 2.7.3
7 * Author: Code Atlantic
8 * Author URI: https://code-atlantic.com/?utm_campaign=plugin-info&utm_source=php-file-header&utm_medium=plugin-ui&utm_content=author-uri
9 * Donate link: https://code-atlantic.com/donate/?utm_campaign=donations&utm_source=php-file-header&utm_medium=plugin-ui&utm_content=donate-link
10 * License: GPL-2.0-or-later
11 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
12 * Text Domain: content-control
13 *
14 * Minimum PHP: 7.4
15 * Minimum WP: 6.2
16 *
17 * @package Content Control
18 * @author Code Atlantic
19 * @copyright Copyright (c) 2023, Code Atlantic LLC.
20 */
21
22 namespace ContentControl;
23
24 defined( 'ABSPATH' ) || exit;
25
26 /**
27 * Define plugin's global configuration.
28 *
29 * @return array<string,string|bool>
30 */
31 function get_plugin_config() {
32 return [
33 'name' => 'Content Control',
34 'slug' => 'content-control',
35 'version' => '2.7.3',
36 'option_prefix' => 'content_control',
37 // Maybe remove this and simply prefix `name` with `'Popup Maker'`.
38 'text_domain' => 'content-control',
39 'fullname' => 'Content Control',
40 'min_php_ver' => '7.4.0',
41 'min_wp_ver' => '6.2.0',
42 'file' => __FILE__,
43 'basename' => \plugin_basename( __FILE__ ),
44 'url' => \plugin_dir_url( __FILE__ ),
45 'path' => __DIR__ . \DIRECTORY_SEPARATOR,
46 'api_url' => 'https://contentcontrolplugin.com/',
47 ];
48 }
49
50 /**
51 * Get config or config property.
52 *
53 * @param string|null $key Key of config item to return.
54 *
55 * @return mixed
56 */
57 function config( $key = null ) {
58 $config = get_plugin_config();
59
60 if ( ! isset( $key ) ) {
61 return $config;
62 }
63
64 return isset( $config[ $key ] ) ? $config[ $key ] : false;
65 }
66
67 /**
68 * Register autoloader.
69 */
70 require_once __DIR__ . '/classes/Plugin/Autoloader.php';
71
72 if ( ! Plugin\Autoloader::init( config( 'name' ), config( 'path' ) ) ) {
73 return;
74 }
75
76 /**
77 * Check plugin prerequisites.
78 *
79 * @return bool
80 */
81 function check_prerequisites() {
82
83 // 1.a Check Prerequisites.
84 $prerequisites = new \ContentControl\Plugin\Prerequisites( [
85 [
86 // a. PHP Min Version.
87 'type' => 'php',
88 'version' => config( 'min_php_ver' ),
89 ],
90 // a. PHP Min Version.
91 [
92 'type' => 'wp',
93 'version' => config( 'min_wp_ver' ),
94 ],
95 ] );
96
97 /**
98 * 1.b If there are missing requirements, render error messaging and return.
99 */
100 if ( $prerequisites->check() === false ) {
101 $prerequisites->setup_notices();
102
103 return false;
104 }
105
106 return true;
107 }
108
109 add_action(
110 'plugins_loaded',
111 function () {
112 if ( check_prerequisites() ) {
113 plugin_instance();
114 }
115 },
116 // Core plugin loads at 11, Pro loads at 12 & addons load at 13.
117 11
118 );
119
120 /**
121 * Initiates and/or retrieves an encapsulated container for the plugin.
122 *
123 * This kicks it all off, loads functions and initiates the plugins main class.
124 *
125 * @return \ContentControl\Plugin\Core
126 */
127 function plugin_instance() {
128 static $plugin;
129
130 if ( ! $plugin instanceof \ContentControl\Plugin\Core ) {
131 require_once __DIR__ . '/inc/functions.php';
132 require_once __DIR__ . '/inc/deprecated.php';
133 $plugin = new Plugin\Core( get_plugin_config() );
134 }
135
136 return $plugin;
137 }
138
139 /**
140 * Easy access to all plugin services from the container.
141 *
142 * @see \ContentControl\plugin_instance
143 *
144 * @param string|null $service_or_config Key of service or config to fetch.
145 * @return \ContentControl\Plugin\Core|mixed
146 */
147 function plugin( $service_or_config = null ) {
148 if ( ! isset( $service_or_config ) ) {
149 return plugin_instance();
150 }
151
152 return plugin_instance()->get( $service_or_config );
153 }
154
155 \register_activation_hook( __FILE__, '\ContentControl\Plugin\Install::activate_plugin' );
156 \register_deactivation_hook( __FILE__, '\ContentControl\Plugin\Install::deactivate_plugin' );
157 \register_uninstall_hook( __FILE__, '\ContentControl\Plugin\Install::uninstall_plugin' );
158