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

266 lines 5.8 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://wordpress.org/plugins/content-control/
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: 1.1.6
7 * Author: Code Atlantic
8 * Author URI: https://code-atlantic.com/
9 * Text Domain: content-control
10 *
11 * Minimum PHP: 5.3
12 * Minimum WP: 3.5
13 *
14 * @author Daniel Iser
15 * @copyright Copyright (c) 2021, Code Atlantic LLC.
16 */
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22
23 /**
24 * @param $class
25 */
26 function jp_content_control_autoloader( $class ) {
27
28 // project-specific namespace prefix
29 $prefix = 'JP\\CC\\';
30
31 // base directory for the namespace prefix
32 $base_dir = __DIR__ . '/classes/';
33
34 // does the class use the namespace prefix?
35 $len = strlen( $prefix );
36 if ( strncmp( $prefix, $class, $len ) !== 0 ) {
37 // no, move to the next registered autoloader
38 return;
39 }
40
41 // get the relative class name
42 $relative_class = substr( $class, $len );
43
44 // replace the namespace prefix with the base directory, replace namespace
45 // separators with directory separators in the relative class name, append
46 // with .php
47 $file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';
48
49 // if the file exists, require it
50 if ( file_exists( $file ) ) {
51 require_once $file;
52 }
53
54 }
55
56 spl_autoload_register( 'jp_content_control_autoloader' ); // Register autoloader
57
58
59 /**
60 * Class JP_Content_Control
61 */
62 class JP_Content_Control {
63
64 /**
65 * @var string
66 */
67 public static $NAME = 'Content Control';
68
69 /**
70 * @var string
71 */
72 public static $VER = '1.1.6';
73
74 /**
75 * @var string
76 */
77 public static $MIN_PHP_VER = '5.3';
78
79 /**
80 * @var string
81 */
82 public static $MIN_WP_VER = '3.5';
83
84 /**
85 * @var string
86 */
87 public static $URL = '';
88 /**
89 * @var string
90 */
91 public static $DIR = '';
92 /**
93 * @var string
94 */
95 public static $FILE = '';
96
97 /**
98 * @var string
99 */
100 public static $TEMPLATE_PATH = 'jp/content-control/';
101
102
103 /**
104 * @var JP_Content_Control $instance The one true JP_Content_Control
105 * @since 1.0.0
106 */
107 private static $instance;
108
109 /**
110 * Get active instance
111 *
112 * @access public
113 * @since 1.0.0
114 * @return object self::$instance The one true JP_Content_Control
115 */
116 public static function instance() {
117 if ( ! self::$instance ) {
118 self::$instance = new static;
119 self::$instance->setup_constants();
120
121 self::$instance->load_textdomain();
122
123 self::$instance->includes();
124 self::$instance->init();
125 }
126
127 return self::$instance;
128 }
129
130 /**
131 * Setup plugin constants
132 *
133 * @access private
134 * @since 1.0.0
135 * @return void
136 */
137 private function setup_constants() {
138 static::$DIR = self::$instance->plugin_path();
139 static::$URL = self::$instance->plugin_url();
140 static::$FILE = __FILE__;
141 }
142
143 /**
144 * Include necessary files
145 *
146 * @access private
147 * @since 1.0.0
148 * @return void
149 */
150 private function includes() {}
151
152 /**
153 * Initialize everything
154 *
155 * @access private
156 * @since 1.0.0
157 * @return void
158 */
159 private function init() {
160 \JP\CC\Options::init( 'jp_cc' );
161 \JP\CC\Shortcodes::init();
162 \JP\CC\Admin::init();
163 \JP\CC\Site::init();
164 }
165
166 /**
167 * Get the plugin path.
168 * @return string
169 */
170 public function plugin_path() {
171 return plugin_dir_path( __FILE__ );
172 }
173
174 /**
175 * Get the plugin url.
176 * @return string
177 */
178 public function plugin_url() {
179 return plugins_url( '/', __FILE__ );
180 }
181
182 /**
183 * Internationalization
184 *
185 * @access public
186 * @since 1.0.0
187 * @return void
188 */
189 public function load_textdomain() {
190 load_plugin_textdomain( 'content-control' );
191 }
192
193 /**
194 * Get the template path.
195 * @return string
196 */
197 public function template_path() {
198 return apply_filters( 'jp_cc_template_path', static::$TEMPLATE_PATH );
199 }
200
201 /**
202 * Get Ajax URL.
203 * @return string
204 */
205 public function ajax_url() {
206 return admin_url( 'admin-ajax.php', 'relative' );
207 }
208
209 }
210
211 /**
212 * The main function responsible for returning the one true JP_Content_Control
213 * Instance to functions everywhere.
214 *
215 * Use this function like you would a global variable, except without needing
216 * to declare the global.
217 *
218 * Example: <?php $jp_content_control = JP_Content_Control(); ?>
219 *
220 * @since 1.0.0
221 * @return object The one true JP_Content_Control Instance
222 */
223 function jp_content_control() {
224 return JP_Content_Control::instance();
225 }
226
227 // Get Recipe Manager Running
228 add_action( 'plugins_loaded', 'jp_content_control', 9 );
229
230 /**
231 * Plugin Activation hook function to check for Minimum PHP and WordPress versions
232 *
233 * Cannot use static:: in case php 5.2 is used.
234 */
235 function jp_content_control_activation_check() {
236 global $wp_version;
237
238 if ( version_compare( PHP_VERSION, JP_Content_Control::$MIN_PHP_VER, '<' ) ) {
239 $flag = 'PHP';
240 } elseif ( version_compare( $wp_version, JP_Content_Control::$MIN_WP_VER, '<' ) ) {
241 $flag = 'WordPress';
242 } else {
243 return;
244 }
245
246 $version = 'PHP' == $flag ? JP_Content_Control::$MIN_PHP_VER : JP_Content_Control::$MIN_WP_VER;
247
248 // Deactivate automatically due to insufficient PHP or WP Version.
249 deactivate_plugins( basename( __FILE__ ) );
250
251 $notice = sprintf( __( 'The %4$s %1$s %5$s plugin requires %2$s version %3$s or greater.', 'content-control' ), JP_Content_Control::$NAME, $flag, $version, "<strong>", "</strong>" );
252
253 wp_die( "<p>$notice</p>", __( 'Plugin Activation Error', 'content-control' ), array(
254 'response' => 200,
255 'back_link' => true,
256 ) );
257 }
258
259 // Ensure plugin & environment compatibility.
260 register_activation_hook( __FILE__, 'jp_content_control_activation_check' );
261
262 // Register activation, deactivation & uninstall hooks.
263 //register_activation_hook( __FILE__, array( '\\JP\CC\Activation', 'activate' ) );
264 //register_deactivation_hook( __FILE__, array( '\\JP\CC\Activation', 'deactivate' ) );
265 //register_uninstall_hook( __FILE__, array( '\\JP\CC\Activation', 'uninstall' ) );
266