| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Assets package. |
| 5 |
* |
| 6 |
* (c) Inpsyde GmbH |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
declare(strict_types=1); |
| 13 |
|
| 14 |
namespace Inpsyde\Assets; |
| 15 |
|
| 16 |
// Exit early in case multiple Composer autoloaders try to include this file. |
| 17 |
if (defined(__NAMESPACE__.'\BOOTSTRAPPED')) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
const BOOTSTRAPPED = true; |
| 22 |
|
| 23 |
function bootstrap(): bool |
| 24 |
{ |
| 25 |
// Prevent function is called more than once with same path as argument (which would mean load same file again) |
| 26 |
static $done; |
| 27 |
if ($done) { |
| 28 |
return false; |
| 29 |
} |
| 30 |
$done = true; |
| 31 |
|
| 32 |
(new AssetManager())->setup(); |
| 33 |
|
| 34 |
return $done; |
| 35 |
} |
| 36 |
|
| 37 |
/* |
| 38 |
* This file is loaded by Composer autoload, and that may happen before `add_action` is available. |
| 39 |
* In that case, we first try to load `plugin.php` before calling `add_action`. |
| 40 |
*/ |
| 41 |
|
| 42 |
$addActionExists = function_exists('add_action'); |
| 43 |
if ( |
| 44 |
$addActionExists |
| 45 |
|| (defined('ABSPATH') && defined('WP_INC') && file_exists(ABSPATH . WP_INC . '/plugin.php')) |
| 46 |
) { |
| 47 |
if (!$addActionExists) { |
| 48 |
require_once ABSPATH . WP_INC . '/plugin.php'; |
| 49 |
} |
| 50 |
|
| 51 |
unset($addActionExists); |
| 52 |
add_action('wp_loaded', __NAMESPACE__ . '\\bootstrap', 99); |
| 53 |
|
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
unset($addActionExists); |
| 58 |
|
| 59 |
/** |
| 60 |
* If here, this file is loaded very early, probably too-much early, even before ABSPATH was defined |
| 61 |
* so only option we have is to "manually" write in global `$wp_filter` array. |
| 62 |
*/ |
| 63 |
|
| 64 |
global $wp_filter; |
| 65 |
is_array($wp_filter) or $wp_filter = []; |
| 66 |
isset($wp_filter['wp_loaded']) or $wp_filter['wp_loaded'] = []; |
| 67 |
isset($wp_filter['wp_loaded'][99]) or $wp_filter['wp_loaded'][99] = []; |
| 68 |
$wp_filter['wp_loaded'][99][__NAMESPACE__ . '\\bootstrap'] = [ |
| 69 |
'function' => __NAMESPACE__ . '\\bootstrap', |
| 70 |
'accepted_args' => 0, |
| 71 |
]; |
| 72 |
|