-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
152 lines (142 loc) · 5.17 KB
/
Copy pathbootstrap.php
File metadata and controls
152 lines (142 loc) · 5.17 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
<?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
* - Lifecycle → handles plugin lifecycle events
* - Hooks → attaches runtime hooks
*
* @var array $bootstrap_classes
*/
$bootstrap_classes = [
\BitskiWPPluginBoilerplate\core\Config::class,
\BitskiWPPluginBoilerplate\core\Options::class,
\BitskiWPPluginBoilerplate\core\Setup::class,
\BitskiWPPluginBoilerplate\core\Lifecycle::class,
\BitskiWPPluginBoilerplate\core\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/assets/load' => \BitskiWPPluginBoilerplate\assets\AssetsLoader::class,
'bitski-wp-plugin-boilerplate/option/rest/api/load' => \BitskiWPPluginBoilerplate\rest\Api::class,
];
/**
* Array of conditional integration 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 $integration_class_map
*/
$integration_class_map = [
//'bitski-wp-plugin-boilerplate/option/integration/example-adapter/load' => \BitskiWPPluginBoilerplate\integration\ExampleAdapter::class, // Replace with existing vendor adapter class option and name if needed.
];
/**
* 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\admin\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\core\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 integration classes based on plugin option filters.
*/
add_action('plugins_loaded', static function () use ($integration_class_map) {
foreach ($integration_class_map as $option_key => $class) {
if (\BitskiWPPluginBoilerplate\core\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\core\Options::get($option_key)) {
try {
$instance = new $class();
if (method_exists($instance, 'init')) {
$instance->init();
}
} catch (\Throwable $error) {
error_log($class . ' Error: ' . $error->getMessage());
}
}
}
}