-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.php
More file actions
420 lines (378 loc) · 17.7 KB
/
loader.php
File metadata and controls
420 lines (378 loc) · 17.7 KB
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* EvolveWP Core load order — EvolveWPCore main class.
*
* GROUP 1 — Composer PSR-4 autoloader (loaded in evolvewp-core.php before this file)
* vendor/autoload.php — resolves all EvolveWP\Core\ namespaced classes automatically.
* No include_once needed for any class under includes/Core/, includes/Ecosystem/,
* includes/Admin/, includes/Utilities/, includes/API/, includes/CLI/.
*
* GROUP 2 — Core functions (always loaded, no class dependencies)
* includes/functions/core.php — global helper functions
* includes/functions/validate.php — input validation helpers
* includes/logging-helper.php — logging convenience functions
* includes/api-logging.php — API call logging functions
* includes/functions/database.php — database helper functions
*
* GROUP 3 — Core classes (loaded on every request)
* includes/classes/debug.php — debug utilities
* includes/classes/autoloader.php — legacy SPL autoloader (to be removed in Task 0.5)
* includes/classes/install.php — activation, DB tables, roles
* includes/classes/ajax.php — AJAX endpoint registration
* includes/classes/object-registry.php — generic object registry
* includes/classes/data-freshness-manager.php — cache freshness tracking
* includes/classes/developer-flow-logger.php — dev-mode flow logging
* includes/classes/developer-mode.php — developer mode detection
* includes/classes/i18n.php — internationalisation
* includes/classes/dependencies.php — plugin dependency checker
* includes/classes/listener.php — request listener
* includes/classes/unified-logger.php — structured trace logger
* includes/classes/enhanced-logger.php — Query Monitor-style logger
*
* GROUP 4 — Optional libraries (guarded by file_exists)
* includes/libraries/action-scheduler/ — background job processing
* includes/libraries/carbon-fields/ — settings framework
* includes/classes/task-scheduler.php — Action Scheduler wrapper (loaded with library)
* includes/classes/carbon-fields-integration.php (loaded with library)
*
* GROUP 5 — Ecosystem framework (always loaded)
* EvolveWP\Core\Ecosystem\Registry — autoloaded via Composer
* includes/classes/ecosystem-menu-manager.php — shared menu placement
* includes/classes/ecosystem-installer.php — one-click plugin installer
*
* GROUP 6 — Feature classes (always loaded, safe to remove when cloning if unused)
* includes/classes/multisite.php — multisite support
* includes/classes/github-sync.php — GitHub sync
* includes/classes/settings-import-export.php
* includes/classes/extension-installer.php
* includes/classes/library-manager.php
* includes/classes/library-update-monitor.php
* includes/classes/rest-controller.php — abstract REST base
* includes/classes/rest-example.php — EXAMPLE: delete when cloning
* includes/classes/unified-feature.php — EXAMPLE: delete when cloning
*
* GROUP 7 — WP-CLI (loaded only when WP_CLI is defined)
* includes/classes/cli-commands.php
*
* GROUP 8 — API system (always loaded)
* EvolveWP\Core\API\Connector_Interface — autoloaded via Composer
* EvolveWP\Core\API\Base_API — autoloaded via Composer
* EvolveWP\Core\API\REST_Bridge — autoloaded via Composer
* EvolveWP\Core\API\REST_Controller — autoloaded via Composer
* api/api-directory.php — provider registry (static + runtime)
* api/api-factory.php — connector instance factory
*
* GROUP 9 — Admin only (guarded by is_request('admin'), loaded on init priority 1)
* includes/admin/admin.php and all admin sub-files
* admin/config/admin-menus.php
* admin/notifications/notifications.php
* includes/classes/notification-bell.php
* toolbars/toolbars.php
* includes/classes/uninstall-feedback.php
*
* GROUP 10 — Frontend only (guarded by is_request('frontend'))
* includes/classes/frontend-scripts.php
*
* GROUP 11 — Shortcodes (always loaded)
* shortcodes/shortcodes.php
*/
final class EvolveWPCore {
/**
* EvolveWP Core version.
*
* @var string
*/
public $version = '1.0.0';
/**
* Minimum WP version.
*
* @var string
*/
public $min_wp_version = '4.4';
/**
* The single instance of the class.
*
* @var EvolveWPCore
* @since 1.0.0
*/
protected static $_instance = null;
/**
* Session instance.
*
* @var EvolveWP_Core_Session
*/
public $session = null;
/**
* Main EvolveWP Core instance.
*
* Ensures only one instance is loaded.
*
* @since 1.0.0
* @static
* @return EvolveWPCore Main instance.
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Cloning is forbidden.
*
* @since 1.0.0
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Your not allowed to do that!', 'evolvewp-core' ), '1.0' );
}
/**
* Unserialising instances of this class is forbidden.
*
* @since 1.0.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Your not allowed to do that!', 'evolvewp-core' ), '1.0' );
}
/**
* Auto-load in-accessible properties on demand.
* @param mixed $key
* @return mixed
*/
public function __get( $key ) {
if ( in_array( $key, array( 'mailer' ) ) ) {
return $this->$key();
}
}
/**
* EvolveWP Core constructor.
*
* @since 1.0.0
*/
public function __construct() {
$this->define_constants();
$this->includes();
$this->init_hooks();
do_action( 'evolvewp_core_loaded' );
}
/**
* Hook into actions and filters.
* @since 1.0
*/
private function init_hooks() {
register_activation_hook( EVOLVEWP_CORE_PLUGIN_FILE, array( '\EvolveWP\Core\Core\Install', 'install' ) );
register_deactivation_hook( EVOLVEWP_CORE_PLUGIN_FILE, array( '\EvolveWP\Core\Core\Install', 'deactivate' ) );
\EvolveWP\Core\Core\Install::init();
\EvolveWP\Core\Core\AJAX_Handler::init();
\EvolveWP\Core\Core\Audit_Hooks::init();
add_action( 'init', array( $this, 'init' ), 0 );
}
/**
* Define EvolveWP Core constants.
*
* @since 1.0.0
*/
private function define_constants() {
if ( ! defined( 'EVOLVEWP_CORE_LOG_DIR' ) ) {
$upload_dir = wp_upload_dir();
define( 'EVOLVEWP_CORE_LOG_DIR', $upload_dir['basedir'] . '/evolvewp-core-logs/' );
}
if ( ! defined( 'EVOLVEWP_CORE_MIN_WP_VERSION' ) ) { define( 'EVOLVEWP_CORE_MIN_WP_VERSION', $this->min_wp_version ); }
// Main (package) constants.
if ( ! defined( 'EVOLVEWP_CORE_SESSION_CACHE_GROUP' ) ) { define( 'EVOLVEWP_CORE_SESSION_CACHE_GROUP', 'evolvewp_core_session_id' ); }
if ( ! defined( 'EVOLVEWP_CORE_DEV_MODE' ) ) { define( 'EVOLVEWP_CORE_DEV_MODE', false ); }
if ( ! defined( 'EVOLVEWP_CORE_WORDPRESSORG_SLUG' ) ) { define( 'EVOLVEWP_CORE_WORDPRESSORG_SLUG', false ); }
if ( ! defined( 'EVOLVEWP_CORE_MARKETPLACE' ) ) { define( 'EVOLVEWP_CORE_MARKETPLACE', false ); }
if ( ! defined( 'EVOLVEWP_CORE_MARKETPLACE_ID' ) ) { define( 'EVOLVEWP_CORE_MARKETPLACE_ID', false ); }
// Project constants.
if ( ! defined( 'EVOLVEWP_CORE_HOME' ) ) { define( 'EVOLVEWP_CORE_HOME', 'https://evolvewp.dev' ); }
if ( ! defined( 'EVOLVEWP_CORE_GITHUB' ) ) { define( 'EVOLVEWP_CORE_GITHUB', 'https://github.com/FifeCIC/EvolveWP.Core' ); }
if ( ! defined( 'EVOLVEWP_CORE_DOCS' ) ) { define( 'EVOLVEWP_CORE_DOCS', 'https://evolvewp.dev/docs' ); }
}
/**
* Include required core files used in admin and on the frontend.
*/
public function includes() {
// -------------------------------------------------------------------------
// GROUP 2 — Core functions (always loaded, no class dependencies)
// -------------------------------------------------------------------------
include_once( 'includes/functions/core.php' );
include_once( 'includes/functions/validate.php' );
include_once( 'includes/logging-helper.php' );
include_once( 'includes/api-logging.php' );
include_once( 'includes/functions/database.php' );
// -------------------------------------------------------------------------
// GROUP 3 — Core classes (loaded on every request)
// -------------------------------------------------------------------------
include_once( 'includes/classes/debug.php' );
// Composer PSR-4 autoloader handles all namespaced classes (loaded in evolvewp-core.php).
// EvolveWP\Core\Core\Install is autoloaded via Composer — no include needed.
// EvolveWP\Core\Core\AJAX_Handler is autoloaded via Composer — no include needed.
include_once( 'includes/classes/object-registry.php' );
include_once( 'includes/classes/data-freshness-manager.php' );
include_once( 'includes/classes/developer-flow-logger.php' );
include_once( 'includes/classes/developer-mode.php' );
include_once( 'includes/classes/i18n.php' );
include_once( 'includes/classes/dependencies.php' );
include_once( 'includes/classes/listener.php' );
// EvolveWP\Core\Core\Logger is autoloaded via Composer — no include needed.
// EvolveWP\Core\Core\Enhanced_Logger is autoloaded via Composer — no include needed.
// -------------------------------------------------------------------------
// GROUP 3b — Assets (always loaded, procedural — to be replaced by Asset_Manager in Task 3.1)
// -------------------------------------------------------------------------
include_once( 'assets/manage-assets.php' );
include_once( 'assets/queue-assets.php' );
// -------------------------------------------------------------------------
// GROUP 4 — Optional libraries (guarded by file_exists)
// -------------------------------------------------------------------------
if ( file_exists( plugin_dir_path( __FILE__ ) . 'includes/libraries/action-scheduler/action-scheduler.php' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'includes/libraries/action-scheduler/action-scheduler.php';
// EvolveWP\Core\Core\Task_Scheduler is autoloaded via Composer.
\EvolveWP\Core\Core\Task_Scheduler::instance();
}
if ( file_exists( plugin_dir_path( __FILE__ ) . 'includes/libraries/carbon-fields/vendor/autoload.php' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'includes/libraries/carbon-fields/vendor/autoload.php';
include_once( 'includes/classes/carbon-fields-integration.php' );
}
// -------------------------------------------------------------------------
// GROUP 5 — Ecosystem framework (always loaded)
// All three Ecosystem classes autoloaded via Composer — no includes needed.
// -------------------------------------------------------------------------
evolvewp_core_ecosystem(); // boot Registry singleton
new \EvolveWP\Core\Ecosystem\Menu_Manager(); // boot menu manager
new \EvolveWP\Core\Ecosystem\Installer(); // boot plugin installer
add_action( 'evolvewp_core_ecosystem_register', function() {
evolvewp_core_ecosystem()->register_plugin( 'evolvewp-core', array(
'name' => 'EvolveWP Core',
'version' => EVOLVEWP_CORE_VERSION,
'path' => EVOLVEWP_CORE_PLUGIN_DIR_PATH,
'url' => plugins_url( '/', EVOLVEWP_CORE_PLUGIN_FILE ),
'has_logging' => true,
'has_cron' => true,
'has_background_tasks' => true,
'shared_settings' => array( 'logging', 'cron', 'background_tasks' ),
) );
} );
// -------------------------------------------------------------------------
// GROUP 6 — Feature classes (remove unused ones when cloning)
// -------------------------------------------------------------------------
include_once( 'includes/classes/multisite.php' );
include_once( 'includes/classes/settings-import-export.php' );
include_once( 'includes/classes/extension-installer.php' );
include_once( 'includes/classes/library-manager.php' );
include_once( 'includes/classes/library-update-monitor.php' );
// EvolveWP\Core\Admin\Dashboard_Widgets is autoloaded via Composer.
new \EvolveWP\Core\Admin\Dashboard_Widgets();
// -------------------------------------------------------------------------
// GROUP 7 — WP-CLI (loaded only when WP_CLI is defined)
// -------------------------------------------------------------------------
if ( defined( 'WP_CLI' ) && WP_CLI ) {
include_once( 'includes/classes/cli-commands.php' );
}
// -------------------------------------------------------------------------
// GROUP 8 — API system (always loaded)
// EvolveWP\Core\API\Base_API and EvolveWP\Core\API\REST_Controller autoloaded via Composer.
// -------------------------------------------------------------------------
include_once( 'api/api-directory.php' );
include_once( 'api/api-factory.php' );
// -------------------------------------------------------------------------
// GROUP 9 — Admin only (deferred to init priority 1)
// -------------------------------------------------------------------------
if ( $this->is_request( 'admin' ) ) {
add_action( 'init', array( $this, 'load_admin_files' ), 1 );
}
// -------------------------------------------------------------------------
// GROUP 10 — Frontend only
// -------------------------------------------------------------------------
if ( $this->is_request( 'frontend' ) ) {
$this->frontend_includes();
}
// -------------------------------------------------------------------------
// GROUP 11 — Shortcodes (always loaded)
// -------------------------------------------------------------------------
include_once( 'shortcodes/shortcodes.php' );
}
/**
* Include required frontend files.
*/
public function frontend_includes() {
include_once( 'includes/classes/frontend-scripts.php' );
}
/**
* Load admin files after WordPress init.
*/
public function load_admin_files() {
include_once( 'includes/admin/admin.php' );
include_once( 'includes/admin/admin-main-views.php' );
include_once( 'admin/config/admin-menus.php' );
include_once( 'admin/notifications/notifications.php' );
// EvolveWP\Core\Admin\Notification_Bell autoloaded via Composer.
\EvolveWP\Core\Admin\Notification_Bell::init();
include_once( 'templates/tabs/development/tab-credits.php' );
include_once( 'toolbars/toolbars.php' );
// EvolveWP\Core\Admin\Uninstall_Feedback autoloaded via Composer.
new \EvolveWP\Core\Admin\Uninstall_Feedback();
}
/**
* Initialise EvolveWP Core when WordPress initialises.
*
* @since 1.0.0
*/
public function init() {
// Register Core's typed settings.
\EvolveWP\Core\Core\Settings::register( 'evolvewp-core', array(
'currency' => array( 'type' => 'string', 'default' => 'GBP' ),
'currency_position' => array( 'type' => 'string', 'default' => 'before' ),
'thousand_separator' => array( 'type' => 'string', 'default' => ',' ),
'decimal_separator' => array( 'type' => 'string', 'default' => '.' ),
) );
do_action( 'before_evolvewp_core_init' );
do_action( 'evolvewp_core_init' );
}
/**
* Get the plugin url.
* @return string
*/
public function plugin_url() {
return untrailingslashit( plugins_url( '/', __FILE__ ) );
}
/**
* Get the plugin path.
* @return string
*/
public function plugin_path() {
return untrailingslashit( plugin_dir_path( __FILE__ ) );
}
/**
* Get Ajax URL (this is the URL to WordPress core ajax file).
* @return string
*/
public function ajax_url() {
return admin_url( 'admin-ajax.php', 'relative' );
}
/**
* What type of request is this?
*
* Functions and constants are WordPress core. This function will allow
* you to avoid large operations or output at the wrong time.
*
* @param string $type admin, ajax, cron or frontend.
* @return bool
*/
private function is_request( $type ) {
switch ( $type ) {
case 'admin' :
return is_admin();
case 'ajax' :
return defined( 'DOING_AJAX' );
case 'cron' :
return defined( 'DOING_CRON' );
case 'frontend' :
return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
}
}
}
// Boot the main plugin instance.
$GLOBALS['evolvewp_core'] = EvolveWPCore();