-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
71 lines (64 loc) · 2.97 KB
/
Copy pathbootstrap.php
File metadata and controls
71 lines (64 loc) · 2.97 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
<?php
declare(strict_types=1);
/**
* Core bootstrap for HyperBlocks.
*
* Dev-environment auto-init bridge: when HyperBlocks is loaded directly via
* Composer (unprefixed), this file schedules initialization at
* after_setup_theme by delegating to WordPress\Bootstrap::init(), which lives
* under the PSR-4 root and holds the first-to-boot LOADED guard. Duplicate-load
* protection is namespace-scoped and prefix-safe (see WordPress\Bootstrap::init());
* there is no candidate election, no version compare, and no jetpack dependency.
*
* Under namespace prefixing (Mozart) this file is not copied (it sits outside
* src/); prefixed consumers call HyperBlocks\WordPress\Bootstrap::init()
* explicitly, which is already prefixed.
*
* @since 1.0.0
*/
// Exit if accessed directly (but allow test environment to proceed).
if (!defined('ABSPATH') && !defined('HYPERBLOCKS_TESTING_MODE')) {
return;
}
// Composer autoloader. Skip the nested vendor/autoload.php when this file is
// itself inside another package's /vendor/ tree (would double-declare Composer
// autoloader classes). bootstrap.php runs once per process (Composer files
// autoload dedup + require_once), so no global reload guard is needed.
$normalizedDir = str_replace('\\', '/', __DIR__);
$loadedFromVendorTree = str_contains($normalizedDir, '/vendor/');
if (!$loadedFromVendorTree && file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
} elseif (!$loadedFromVendorTree) {
// No autoloader found: surface an admin notice but continue so tests can
// register hooks.
add_action('admin_notices', static function (): void {
echo '<div class="error"><p>' . esc_html__('HyperBlocks: Composer autoloader not found. Please run "composer install" inside the plugin folder.', 'hyperblocks') . '</p></div>';
});
}
// Bootstrap the HyperFields dependency. When HyperBlocks runs standalone
// (not alongside the HyperFields plugin), trigger HyperFields' bootstrap so its
// after_setup_theme initialization runs. The guard inside HyperFields'
// bootstrap.php (first-to-boot LOADED) prevents double-initialization.
if (!$loadedFromVendorTree) {
$hyperfieldsBootstrap = __DIR__ . '/vendor/estebanforge/hyperfields/bootstrap.php';
if (file_exists($hyperfieldsBootstrap)) {
require_once $hyperfieldsBootstrap;
}
}
// Schedule initialization at after_setup_theme (priority 0, original timing).
// Delegates to WordPress\Bootstrap::init(), which carries the prefix-safe
// first-to-boot guard and sets Config runtime identity.
if (!function_exists('hyperblocks_bootstrap_init')) {
/**
* Initialize HyperBlocks for this copy at after_setup_theme.
*
* @return void
*/
function hyperblocks_bootstrap_init(): void
{
\HyperBlocks\WordPress\Bootstrap::init();
}
}
if (function_exists('add_action') && !has_action('after_setup_theme', 'hyperblocks_bootstrap_init')) {
add_action('after_setup_theme', 'hyperblocks_bootstrap_init', 0);
}