-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
83 lines (74 loc) · 2.11 KB
/
functions.php
File metadata and controls
83 lines (74 loc) · 2.11 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
<?php
declare(strict_types=1);
namespace SpaghettiDojo\Burokku;
/**
* Boot the Burokku theme package.
*
* This function initializes the theme package and handles any boot errors
* by displaying an admin notice and firing an action for logging purposes.
*
* @private
* @internal
*/
function boot(): void
{
autoload();
try {
$package = package();
$package->boot();
} catch (\Throwable $exception) {
handleBootFailure($exception);
}
}
/**
* Load the Composer autoloader and ensure the package function is available.
* This function is called during the boot process to set up autoloading for the theme.
*
* @private
* @throws \RuntimeException if the autoload file is missing or the package function is not found
* after including it.
* @internal
*/
function autoload(): void
{
$autoloadFile = __DIR__ . '/vendor/autoload.php';
if (!file_exists($autoloadFile)) {
throw new \RuntimeException(
'Autoload file not found. Please run "composer install" to set up dependencies.'
);
}
if (!function_exists('\\SpaghettiDojo\\Burokku\\package')) {
require_once $autoloadFile;
}
if (!function_exists('\\SpaghettiDojo\\Burokku\\package')) {
throw new \RuntimeException(
'Package function not found after including autoload. Please check your setup.'
);
}
}
/**
* Handle boot failure by displaying an admin notice and firing an action.
*
* @private
*
* @param \Throwable $exception The exception that occurred during boot.
*
* @internal
*/
function handleBootFailure(\Throwable $exception): void
{
do_action('burokku.boot-failed', $exception);
// Display admin notice
add_action(
'admin_notices',
static function () use ($exception): void {
printf(
'<div class="notice notice-error"><p><strong>%s:</strong> %s</p></div>',
esc_html__('Burokku Theme Error', 'burokku'),
esc_html($exception->getMessage())
);
}
);
}
// Boot the package
add_action('after_setup_theme', __NAMESPACE__ . '\\boot');