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

267 lines 5.7 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:
6 * Version: 1.1.2
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) 2019, 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.2';
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\Conditions::init();
162 \JP\CC\Shortcodes::init();
163 \JP\CC\Admin::init();
164 \JP\CC\Site::init();
165 }
166
167 /**
168 * Get the plugin path.
169 * @return string
170 */
171 public function plugin_path() {
172 return plugin_dir_path( __FILE__ );
173 }
174
175 /**
176 * Get the plugin url.
177 * @return string
178 */
179 public function plugin_url() {
180 return plugins_url( '/', __FILE__ );
181 }
182
183 /**
184 * Internationalization
185 *
186 * @access public
187 * @since 1.0.0
188 * @return void
189 */
190 public function load_textdomain() {
191 load_plugin_textdomain( 'content-control' );
192 }
193
194 /**
195 * Get the template path.
196 * @return string
197 */
198 public function template_path() {
199 return apply_filters( 'jp_cc_template_path', static::$TEMPLATE_PATH );
200 }
201
202 /**
203 * Get Ajax URL.
204 * @return string
205 */
206 public function ajax_url() {
207 return admin_url( 'admin-ajax.php', 'relative' );
208 }
209
210 }
211
212 /**
213 * The main function responsible for returning the one true JP_Content_Control
214 * Instance to functions everywhere.
215 *
216 * Use this function like you would a global variable, except without needing
217 * to declare the global.
218 *
219 * Example: <?php $jp_content_control = JP_Content_Control(); ?>
220 *
221 * @since 1.0.0
222 * @return object The one true JP_Content_Control Instance
223 */
224 function jp_content_control() {
225 return JP_Content_Control::instance();
226 }
227
228 // Get Recipe Manager Running
229 add_action( 'plugins_loaded', 'jp_content_control', 9 );
230
231 /**
232 * Plugin Activation hook function to check for Minimum PHP and WordPress versions
233 *
234 * Cannot use static:: in case php 5.2 is used.
235 */
236 function jp_content_control_activation_check() {
237 global $wp_version;
238
239 if ( version_compare( PHP_VERSION, JP_Content_Control::$MIN_PHP_VER, '<' ) ) {
240 $flag = 'PHP';
241 } elseif ( version_compare( $wp_version, JP_Content_Control::$MIN_WP_VER, '<' ) ) {
242 $flag = 'WordPress';
243 } else {
244 return;
245 }
246
247 $version = 'PHP' == $flag ? JP_Content_Control::$MIN_PHP_VER : JP_Content_Control::$MIN_WP_VER;
248
249 // Deactivate automatically due to insufficient PHP or WP Version.
250 deactivate_plugins( basename( __FILE__ ) );
251
252 $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>" );
253
254 wp_die( "<p>$notice</p>", __( 'Plugin Activation Error', 'content-control' ), array(
255 'response' => 200,
256 'back_link' => true,
257 ) );
258 }
259
260 // Ensure plugin & environment compatibility.
261 register_activation_hook( __FILE__, 'jp_content_control_activation_check' );
262
263 // Register activation, deactivation & uninstall hooks.
264 //register_activation_hook( __FILE__, array( '\\JP\CC\Activation', 'activate' ) );
265 //register_deactivation_hook( __FILE__, array( '\\JP\CC\Activation', 'deactivate' ) );
266 //register_uninstall_hook( __FILE__, array( '\\JP\CC\Activation', 'uninstall' ) );
267