1: <?php
2:
3:
4: require_once __DIR__ . '/container/class-papi-container.php';
5:
6: 7: 8: 9:
10: final class Papi_Loader extends Papi_Container {
11:
12: 13: 14: 15: 16:
17: private static $instance;
18:
19: 20: 21: 22: 23:
24: public $name = 'Papi';
25:
26: 27: 28: 29: 30:
31: public static function instance() {
32: if ( ! isset( self::$instance ) ) {
33: self::$instance = new self;
34: }
35:
36: return self::$instance;
37: }
38:
39: 40: 41: 42: 43: 44: 45: 46:
47: public function __call( $name, $arguments ) {
48: return $this->make( $name, $arguments );
49: }
50:
51: 52: 53:
54: private function __construct() {
55: $this->constants();
56: $this->setup_actions();
57: $this->load_textdomain();
58: $this->require_files();
59: $this->setup_container();
60: papi_action_include();
61: }
62:
63: 64: 65: 66: 67:
68: public function __clone() {
69: _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'papi' ), '2.4.2' );
70: }
71:
72: 73: 74: 75: 76:
77: public function __wakeup() {
78: _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'papi' ), '2.4.2' );
79: }
80:
81: 82: 83:
84: private function constants() {
85:
86: if ( ! defined( 'PAPI_PLUGIN_DIR' ) ) {
87: $mu_dir = trailingslashit( sprintf( '%s/%s/src',
88: WPMU_PLUGIN_DIR,
89: basename( dirname( __DIR__ ) )
90: ) );
91:
92: if ( is_dir( $mu_dir ) ) {
93: define( 'PAPI_PLUGIN_DIR', $mu_dir );
94: } else {
95: define( 'PAPI_PLUGIN_DIR', trailingslashit( __DIR__ ) );
96: }
97: }
98:
99:
100: if ( ! defined( 'PAPI_PLUGIN_URL' ) ) {
101: $plugin_url = plugin_dir_url( __FILE__ );
102:
103: if ( is_ssl() ) {
104: $plugin_url = str_replace( 'http://', 'https://', $plugin_url );
105: }
106:
107: define( 'PAPI_PLUGIN_URL', $plugin_url );
108: }
109:
110:
111: if ( ! defined( 'PAPI_PAGE_TYPE_KEY' ) ) {
112: define( 'PAPI_PAGE_TYPE_KEY', '_papi_page_type' );
113: }
114: }
115:
116: 117: 118: 119: 120: 121: 122:
123: private function load_textdomain() {
124: $locale = apply_filters( 'plugin_locale', get_locale(), 'papi' );
125: load_textdomain( 'papi', WP_LANG_DIR . '/papi/papi-' . $locale . '.mo' );
126: load_textdomain( 'papi', PAPI_PLUGIN_DIR . '../languages/papi-' . $locale . '.mo' );
127: }
128:
129: 130: 131:
132: private function require_files() {
133:
134: require_once __DIR__ . '/core/class-papi-core-autoload.php';
135:
136: $lib_path = __DIR__ . '/lib/';
137: $lib_includes = [
138: 'utilities.php',
139: 'actions.php',
140: 'cache.php',
141: 'filters.php',
142: 'url.php',
143: 'post.php',
144: 'page.php',
145: 'property.php',
146: 'tabs.php',
147: 'io.php',
148: 'field.php',
149: 'template.php',
150: 'option.php',
151: 'deprecated.php',
152: 'conditional.php'
153: ];
154:
155:
156: foreach ( $lib_includes as $file ) {
157: if ( file_exists( $lib_path . $file ) ) {
158: require_once $lib_path . $file;
159: }
160: }
161:
162: unset( $file );
163:
164:
165: require_once __DIR__ . '/admin/class-papi-admin.php';
166: require_once __DIR__ . '/admin/class-papi-admin-assets.php';
167: require_once __DIR__ . '/admin/class-papi-admin-menu.php';
168:
169:
170: require_once __DIR__ . '/conditional/class-papi-conditional-rules.php';
171: }
172:
173: 174: 175:
176: public static function deactivate() {
177:
178: remove_action( 'plugins_loaded', 'papi' );
179:
180:
181: if ( ! function_exists( 'is_plugin_active' ) ) {
182: include_once ABSPATH . 'wp-admin/includes/plugin.php';
183: }
184:
185: $plugin_path = plugin_basename( __DIR__ . '/../' . basename( __FILE__ ) );
186:
187:
188: if ( is_plugin_active( $plugin_path ) ) {
189: deactivate_plugins( $plugin_path );
190: }
191:
192: wp_die( __( 'WordPress 4.0 and higher required to run Papi! The plugin has now disabled itself.', 'papi' ) );
193: }
194:
195: 196: 197:
198: private function setup_actions() {
199: add_action( 'after_setup_theme', 'papi_action_include' );
200: }
201:
202: 203: 204:
205: private function setup_container() {
206: $this->singleton( 'porter', new Papi_Porter );
207: }
208: }
209:
210: 211: 212: 213: 214:
215: function papi() {
216: if ( version_compare( get_bloginfo( 'version' ), '4.0', '<' ) ) {
217: Papi_Loader::deactivate();
218: }
219:
220: return Papi_Loader::instance();
221: }
222:
223: add_action( 'plugins_loaded', 'papi' );
224: