-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.php
More file actions
119 lines (111 loc) · 3.79 KB
/
init.php
File metadata and controls
119 lines (111 loc) · 3.79 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
<?php
// Exits if accessed directly.
if ( ! defined('ABSPATH')) {
exit;
}
/**
* Plugin bootstrap and class initialization.
*
* Loads the Composer autoloader if available.
* Instantiates and initializes all core and feature classes.
* Conditionally instantiates and initializes classes based on plugin options.
* Logs autoloader and class instantiation errors without breaking the plugin.
*
* @since 0.1.0
*/
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
} else {
error_log('Autoloader not found: ' . __DIR__ . '/vendor/autoload.php');
}
/**
* Array of core and feature plugin classes to be initialized automatically, can be extended or modified as needed.
*
* Core and feature classes that are initialized unconditionally.
*
* Note: The order of the classes in this array determines the initialization order.
* Classes earlier in the array will be initialized first.
* Initialization order:
* - Config → base configuration
* - Options → depends on Config
* - Setup → registers core WordPress features
* - Hooks → attaches runtime hooks
*
* @var array $bootstrap_classes
*/
$bootstrap_classes = [
\BitskiWPPluginBoilerplate\plugin\Config::class,
\BitskiWPPluginBoilerplate\plugin\Options::class,
\BitskiWPPluginBoilerplate\plugin\Setup::class,
\BitskiWPPluginBoilerplate\plugin\Hooks::class,
];
/**
* Array of conditional classes that are only initialized if the corresponding plugin option is enabled.
*
* Each entry maps a filter name to the class that should be instantiated.
* Filter keys enable/disable optional plugin features via plugin options.
*
* @var array $conditional_class_map
*/
$conditional_class_map = [
'bitski-wp-plugin-boilerplate/option/lifecycle/load' => \BitskiWPPluginBoilerplate\plugin\Lifecycle::class,
];
/**
* Array of admin-specific classes that are only initialized if the corresponding plugin option is enabled
* and the request is in the admin area.
*
* Each entry maps a filter name to the class that should be instantiated.
* Filter keys enable/disable optional plugin features via plugin options.
*
* @var array $admin_class_map
*/
$admin_class_map = [
'bitski-wp-plugin-boilerplate/option/admin/load' => \BitskiWPPluginBoilerplate\plugin\Admin::class,
];
/**
* Instantiates and initializes core and feature classes unconditionally.
*/
foreach ($bootstrap_classes as $class) {
try {
$instance = new $class();
if (method_exists($instance, 'init')) {
$instance->init();
}
} catch (\Throwable $error) {
error_log($class . ' Error: ' . $error->getMessage());
}
}
/**
* Instantiates and initializes conditional classes based on plugin option filters.
*/
foreach ($conditional_class_map as $option_key => $class) {
if (\BitskiWPPluginBoilerplate\plugin\Options::get($option_key)) {
try {
$instance = new $class();
if (method_exists($instance, 'init')) {
$instance->init();
}
} catch (\Throwable $error) {
error_log($class . ' Error: ' . $error->getMessage());
}
}
}
/**
* Instantiates and initializes conditional admin-specific classes based on plugin option filters.
*
* Only runs if the request is in the admin area and not an AJAX request.
*/
if (is_admin() && ! wp_doing_ajax()) {
foreach ($admin_class_map as $option_key => $class) {
if (\BitskiWPPluginBoilerplate\plugin\Options::get($option_key)) {
try {
$instance = new $class();
if (method_exists($instance, 'init')) {
$instance->init();
}
} catch (\Throwable $error) {
error_log($class . ' Error: ' . $error->getMessage());
}
}
}
}