-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbootstrap.php
More file actions
152 lines (134 loc) · 5.52 KB
/
Copy pathbootstrap.php
File metadata and controls
152 lines (134 loc) · 5.52 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
declare(strict_types=1);
/**
* HyperPress plugin adapter bootstrap.
*
* Thin WordPress plugin concerns only. Loads the Composer autoloader (which
* pulls HyperPress-Core and its HyperFields/HyperBlocks dependencies and runs
* each library's bootstrap.php as a Composer autoload.files entry), then wires
* the adapter-level hooks the plugin owns: the HyperFields Data Tools page,
* activation/deactivation, and the About system-info rows.
*
* The libraries self-initialize: each one's bootstrap schedules its init at
* after_setup_theme behind a first-to-boot namespace-scoped LOADED guard. The
* adapter therefore no longer registers the old multi-instance election
* machinery (removed from the libraries) and no longer loads the bundled
* packages autoloader the stack previously depended on.
*
* Class references use ::class so a Mozart-prefixed build rewrites them to the
* prefixed namespace; the previous string literals ('HyperFields\\HyperFields')
* would have been missed by the prefixer and silently failed.
*/
if (!defined('ABSPATH') && !defined('HYPERPRESS_TESTING_MODE')) {
return;
}
if (defined('HYPERPRESS_PLUGIN_ADAPTER_BOOTSTRAPPED')) {
return;
}
define('HYPERPRESS_PLUGIN_ADAPTER_BOOTSTRAPPED', true);
if (!function_exists('hyperpress_adapter_require_once_path')) {
/**
* Require a file only once across this request, using normalized absolute paths.
*/
function hyperpress_adapter_require_once_path(string $path): bool
{
static $loaded = [];
$resolved = realpath($path) ?: $path;
$normalized = str_replace('\\', '/', $resolved);
if (isset($loaded[$normalized])) {
return true;
}
if (!file_exists($resolved)) {
return false;
}
require_once $resolved;
$loaded[$normalized] = true;
return true;
}
}
$adapter_main_file = file_exists(__DIR__ . '/hyperpress.php')
? __DIR__ . '/hyperpress.php'
: __DIR__ . '/api-for-htmx.php';
// Load the Composer autoloader. Plugin vendor first, local monorepo fallback
// second. This also runs every bundled library's bootstrap.php (Composer
// autoload.files), scheduling each library's init at after_setup_theme.
$autoload_candidates = [
__DIR__ . '/vendor/autoload.php',
dirname(__DIR__) . '/HyperPress-Core/vendor/autoload.php',
];
foreach ($autoload_candidates as $autoload) {
if (hyperpress_adapter_require_once_path($autoload)) {
break;
}
}
// Bail with an admin notice if HyperPress-Core is not autoloadable.
if (!class_exists(\HyperPress\Bootstrap::class)) {
if (function_exists('add_action')) {
add_action('admin_notices', static function (): void {
echo '<div class="error"><p>' . esc_html__('HyperPress: HyperPress Core not found. Please run "composer install" inside the plugin folder.', 'api-for-htmx') . '</p></div>';
});
}
return;
}
// Register HyperFields Export/Import UI under Tools.
if (class_exists(\HyperFields\HyperFields::class) && function_exists('add_action')) {
add_action('admin_menu', static function (): void {
\HyperFields\HyperFields::registerDataToolsPage(
parentSlug: 'tools.php',
pageSlug: 'hyperpress-data-tools',
options: [
'hyperpress_options' => __('HyperPress Settings', 'hyperpress'),
],
allowedImportOptions: ['hyperpress_options'],
prefix: '',
title: __('HyperPress Data Tools', 'hyperpress'),
capability: 'manage_options'
);
});
}
// Plugin lifecycle hooks remain in the adapter layer.
if (
class_exists(\HyperPress\Admin\Activation::class)
&& function_exists('register_activation_hook')
&& function_exists('register_deactivation_hook')
) {
register_activation_hook($adapter_main_file, [\HyperPress\Admin\Activation::class, 'activate']);
register_deactivation_hook($adapter_main_file, [\HyperPress\Admin\Activation::class, 'deactivate']);
}
// Enrich the About page system-info table with vendored library versions,
// sourced from each library's prefix-safe Config class (no global constants).
if (function_exists('add_filter')) {
add_filter('hyperpress/about/system_info', static function (array $info): array {
$library_versions = [];
if (class_exists(\HyperFields\Config::class)) {
$library_versions[__('HyperFields Library', 'api-for-htmx')] = \HyperFields\Config::VERSION;
}
if (class_exists(\HyperBlocks\Config::class)) {
$library_versions[__('HyperBlocks Library', 'api-for-htmx')] = \HyperBlocks\Config::VERSION;
}
if (class_exists(\HyperPress\Config::class)) {
$library_versions[__('HyperPress Core', 'api-for-htmx')] = \HyperPress\Config::VERSION;
}
if (empty($library_versions)) {
return $info;
}
// Insert library versions after the Plugin Version row.
$insert_after = __('Plugin Version', 'api-for-htmx');
$result = [];
$inserted = false;
foreach ($info as $key => $value) {
$result[$key] = $value;
if (!$inserted && $key === $insert_after) {
foreach ($library_versions as $lib_key => $lib_value) {
$result[$lib_key] = $lib_value;
}
$inserted = true;
}
}
// Fallback: append at the end if Plugin Version key was not found.
if (!$inserted) {
$result = array_merge($result, $library_versions);
}
return $result;
});
}