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