-
Notifications
You must be signed in to change notification settings - Fork 1
/
wppedia.php
323 lines (265 loc) · 6.88 KB
/
wppedia.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<?php
/**
* WPPedia - The most advanced Glossary solution for WordPress!
*
* @wordpress-plugin
*
* Plugin Name: WPPedia
* Description: The most advanced Glossary solution for WordPress!
* Author: Bastian Fießinger & WPPedia Glossary Team
* AuthorURI: https://github.com/bfiessinger/
* Version: 1.3.0
* Text Domain: wppedia
*/
// Make sure this file runs only from within WordPress.
defined( 'ABSPATH' ) or die();
/**
* Core WPPedia functions
*/
require_once plugin_dir_path(__FILE__) . 'core/inc/core-functions.php';
// Core Classes
use WPPedia\Template;
use WPPedia\Rest_Controller;
use WPPedia\WP_Query_Setup;
use WPPedia\Admin;
use WPPedia\Notification_Center;
use WPPedia\Options;
use WPPedia\Post_Meta;
use WPPedia\Customizer;
use WPPedia\Post_Type;
use WPPedia\DB_Upgrade;
// Modules
use WPPedia\Modules\Cross_Link_Content;
use WPPedia\Modules\Tooltip;
// Compatibility
use WPPedia\Compatibilities\Compatibility_Collection;
class WPPedia {
/**
* Static variable for instanciation
*
* @var WPPedia
*/
protected static $instance = null;
/**
* Container that holds various class instances
*
* @var array
*/
private $container = [];
/**
* Magic isset to bypass referencing plugin.
*
* @param string $prop Property to check.
*
* @return bool
*
* @since 1.3.0
*/
public function __isset( $prop ) {
return isset( $this->{$prop} ) || isset( $this->container[ $prop ] );
}
/**
* Magic getter method.
*
* @param string $prop Property to get.
*
* @return mixed Property value or NULL if it does not exists.
*
* @since 1.3.0
*/
public function __get( $prop ) {
if ( array_key_exists( $prop, $this->container ) ) {
return $this->container[ $prop ];
}
if ( isset( $this->{$prop} ) ) {
return $this->{$prop};
}
return null;
}
/**
* Magic setter method.
*
* @param mixed $prop Property to set.
* @param mixed $value Value to set.
*
* @since 1.3.0
*/
public function __set( $prop, $value ) {
if ( property_exists( $this, $prop ) ) {
$this->$prop = $value;
return;
}
$this->container[ $prop ] = $value;
}
/**
* Magic call method.
*
* @param string $name Method to call.
* @param array $arguments Arguments to pass when calling.
*
* @return mixed Return value of the callback.
*
* @since 1.3.0
*/
public function __call( $name, $arguments ) {
return call_user_func_array( $name, $arguments );
}
/**
* Get current Instance
*/
public static function getInstance() {
if ( null === self::$instance ) {
self::$instance = new self;
self::$instance->init();
}
return self::$instance;
}
protected function __clone() {}
protected function __construct() {}
/**
* Define Plugin Constants
*
* @since 1.2.0
*/
private function define_constants() {
if (!function_exists('get_plugins')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$pluginData = array_values(array_filter(get_plugins(), function ($plugins) {
return ('WPPedia' === $plugins['Name']);
}))[0];
wppedia_maybe_define_constant('WPPediaPluginVersion', $pluginData['Version']);
// Path Constants
wppedia_maybe_define_constant('WPPediaPluginDir', plugin_dir_path(__FILE__));
wppedia_maybe_define_constant('WPPediaPluginUrl', plugin_dir_url(__FILE__));
wppedia_maybe_define_constant('WPPediaPluginBaseName', plugin_basename( __FILE__ ));
// Env Constants
wppedia_maybe_define_constant('WPPedia_TEMPLATE_DEBUG_MODE', false);
}
public function setup() {
load_plugin_textdomain( 'wppedia', false, dirname( WPPediaPluginBaseName ) . '/languages' );
}
private function init() {
require "vendor-prefixed/vendor/autoload.php";
$this->define_constants();
add_action( 'after_setup_theme', [ $this, 'setup' ] );
$this->container['version'] = WPPediaPluginVersion;
$this->container['template_debug_mode'] = WPPedia_TEMPLATE_DEBUG_MODE;
$this->container['plugin_dir'] = WPPediaPluginDir;
$this->container['plugin_url'] = WPPediaPluginUrl;
$this->container['notifications'] = new Notification_Center( 'wppedia_notifications' );
/**
* Instantiate Template Utils
*/
$template = new Template();
$template->_init();
$this->container['template'] = $template;
/**
* Theme and Plugin compatibility
*/
(new Compatibility_Collection())->_init();
/**
* Instantiate REST API Controller Class
*/
(new Rest_Controller())->_init();
/**
* Instantiate Query Controller
*/
(new WP_Query_Setup())->_init();
/**
* Instatiate Admin View
* Used to edit post or edit views in wp_admin
*/
(new Admin())->_init();
/**
* Options
* Setup options and settings pages
*/
$options = new Options();
$options->_init();
$this->container['options'] = $options;
/**
* Post meta
* Setup custom postmeta for WPPedia articles
*/
(new Post_Meta())->_init();
/**
* Setup Customizer Controls
*/
(new Customizer())->_init();
/**
* Instantiate Post Type
* Generates the WPPedia Post type and related taxonomies
*/
(new Post_Type())->_init();
/**
* Instantiate Crosslink Module
*/
(new Cross_Link_Content(
!!options::get_option('crosslinks', 'active'),
!!options::get_option('crosslinks', 'prefer_single_words')
))->_init();
/**
* Tooltips
*/
(new Tooltip())->_init();
/**
* Upgrade the WPPedia Database if needed
*/
(new DB_Upgrade())->_init();
}
/**
* Get default path for templates in themes.
* By default the template path is yourtheme/wppedia
*
* If you want to override the default behaviour in your theme use
* the filter "wppedia_template_path" and return your preferred folder name
* in the callback.
*
* @since 1.1.3
*/
public function template_path() {
return trailingslashit(apply_filters( 'wppedia_template_path', 'wppedia' ));
}
/**
* Get default plugin path
*
* @since 1.2.0
*/
public function plugin_path() {
return (defined('WPPediaPluginDir')) ? WPPediaPluginDir : plugin_dir_path(__FILE__);
}
}
WPPedia::getInstance();
/**
* Template Hooks
*/
require_once WPPediaPluginDir . 'template-hooks/hooks.php';
/**
* Enqueue Assets
*/
require_once WPPediaPluginDir . 'core/inc/assets.php';
/**
* Shortcodes
*/
require_once WPPediaPluginDir . 'core/inc/shortcodes.php';
/**
* The code that runs during plugin activation.
*/
require_once WPPediaPluginDir . 'core/inc/class-activation.php';
register_activation_hook( __FILE__, [ 'WPPedia\\activation', 'activate' ] );
/**
* Flush rewrite rules if the previously added flag exists,
* and then remove the flag.
*/
add_action('init', function() {
if ( get_option( 'wppedia_flush_rewrite_rules_flag' ) ) {
flush_rewrite_rules();
delete_option( 'wppedia_flush_rewrite_rules_flag' );
}
}, 20);
/**
* The code that runs during plugin deactivation.
*/
require_once WPPediaPluginDir . 'core/inc/class-deactivation.php';
register_deactivation_hook( __FILE__, [ 'WPPedia\\deactivation', 'deactivate' ] );