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

147 lines 4.0 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.0.0
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 * Text Domain: content-control
11 *
12 * Minimum PHP: 5.6
13 * Minimum WP: 5.6
14 *
15 * @package Content Control
16 * @author Code Atlantic
17 * @copyright Copyright (c) 2023, Code Atlantic LLC.
18 */
19
20 namespace ContentControl;
21
22 defined( 'ABSPATH' ) || exit;
23
24 /**
25 * Define plugin's global configuration.
26 */
27 function get_plugin_config() {
28 return [
29 'name' => \__( 'Content Control', 'content-control' ),
30 'slug' => 'content-control',
31 'version' => '2.0.0',
32 'option_prefix' => 'content_control',
33 // Maybe remove this and simply prefix `name` with `'Popup Maker'`.
34 'text_domain' => 'content-control',
35 'fullname' => \__( 'Content Control', 'content-control' ),
36 'min_php_ver' => '5.6.0',
37 'min_wp_ver' => '5.6.0',
38 'file' => __FILE__,
39 'basename' => \plugin_basename( __FILE__ ),
40 'url' => \plugin_dir_url( __FILE__ ),
41 'path' => \realpath( \plugin_dir_path( __FILE__ ) ) . \DIRECTORY_SEPARATOR,
42 'api_url' => 'https://contentcontrolplugin.com/',
43 'is_pro' => class_exists( 'ContentControlPro\Plugin\Core' ),
44 ];
45 }
46
47 /**
48 * Get config or config property.
49 *
50 * @param string|null $key Key of config item to return.
51 *
52 * @return mixed
53 */
54 function config( $key = null ) {
55 $config = get_plugin_config();
56
57 if ( ! isset( $key ) ) {
58 return $config;
59 }
60
61 return isset( $config[ $key ] ) ? $config[ $key ] : false;
62 }
63
64 /**
65 * Register autoloader.
66 */
67 require_once __DIR__ . '/classes/Plugin/Autoloader.php';
68
69 if ( ! Plugin\Autoloader::init( config( 'name' ), config( 'path' ) ) ) {
70 return;
71 }
72
73 /**
74 * Check plugin prerequisites.
75 */
76 function check_prerequisites() {
77
78 // 1.a Check Prerequisites.
79 $prerequisites = new \ContentControl\Plugin\Prerequisites( [
80 [
81 // a. PHP Min Version.
82 'type' => 'php',
83 'version' => config( 'min_php_ver' ),
84 ],
85 // a. PHP Min Version.
86 [
87 'type' => 'wp',
88 'version' => config( 'min_wp_ver' ),
89 ],
90 ] );
91
92 /**
93 * 1.b If there are missing requirements, render error messaging and return.
94 */
95 if ( $prerequisites->check() === false ) {
96 $prerequisites->setup_notices();
97
98 return false;
99 }
100
101 return true;
102 }
103
104 add_action( 'plugins_loaded', function () {
105 if ( check_prerequisites() ) {
106 plugin_instance();
107 }
108 }, 11 );
109
110 /**
111 * Initiates and/or retrieves an encapsulated container for the plugin.
112 *
113 * This kicks it all off, loads functions and initiates the plugins main class.
114 *
115 * @return \ContentControl\Plugin\Core
116 */
117 function plugin_instance() {
118 static $plugin;
119
120 if ( ! $plugin instanceof \ContentControl\Plugin\Core ) {
121 require_once __DIR__ . '/inc/functions.php';
122 $plugin = new Plugin\Core( get_plugin_config() );
123 }
124
125 return $plugin;
126 }
127
128 /**
129 * Easy access to all plugin services from the container.
130 *
131 * @see \ContentControl\plugin_instance
132 *
133 * @param string|null $service_or_config Key of service or config to fetch.
134 * @return \ContentControl\Plugin\Core|mixed
135 */
136 function plugin( $service_or_config = null ) {
137 if ( ! isset( $service_or_config ) ) {
138 return plugin_instance();
139 }
140
141 return plugin_instance()->get( $service_or_config );
142 }
143
144 \register_activation_hook( __FILE__, '\ContentControl\Plugin\Install::activate_plugin' );
145 \register_deactivation_hook( __FILE__, '\ContentControl\Plugin\Install::deactivate_plugin' );
146 \register_uninstall_hook( __FILE__, '\ContentControl\Plugin\Install::uninstall_plugin' );
147