| 1 |
<?php |
| 2 |
/** |
| 3 |
* Script registration - Auto-generated by build process. |
| 4 |
* Do not edit this file manually. |
| 5 |
* |
| 6 |
* @package ai |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Registers a script according to `wp_register_script`. Honors this request by |
| 11 |
* reassigning internal dependency properties of any script handle already |
| 12 |
* registered by that name. It does not deregister the original script, to |
| 13 |
* avoid losing inline scripts which may have been attached. |
| 14 |
* |
| 15 |
* @param WP_Scripts $scripts WP_Scripts instance. |
| 16 |
* @param string $handle Name of the script. Should be unique. |
| 17 |
* @param string $src Full URL of the script, or path of the script relative to the WordPress root directory. |
| 18 |
* @param array $deps Optional. An array of registered script handles this script depends on. Default empty array. |
| 19 |
* @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL |
| 20 |
* as a query string for cache busting purposes. If version is set to false, a version |
| 21 |
* number is automatically added equal to current installed WordPress version. |
| 22 |
* If set to null, no version is added. |
| 23 |
* @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>. |
| 24 |
* Default 'false'. |
| 25 |
*/ |
| 26 |
function ai_override_script( $scripts, $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { |
| 27 |
$script = $scripts->query( $handle, 'registered' ); |
| 28 |
if ( $script ) { |
| 29 |
/* |
| 30 |
* In many ways, this is a reimplementation of `wp_register_script` but |
| 31 |
* bypassing consideration of whether a script by the given handle had |
| 32 |
* already been registered. |
| 33 |
*/ |
| 34 |
|
| 35 |
// See: `_WP_Dependency::__construct` . |
| 36 |
$script->src = $src; |
| 37 |
$script->deps = $deps; |
| 38 |
$script->ver = $ver; |
| 39 |
$script->args = $in_footer ? 1 : null; |
| 40 |
} else { |
| 41 |
$scripts->add( $handle, $src, $deps, $ver, ( $in_footer ? 1 : null ) ); |
| 42 |
} |
| 43 |
|
| 44 |
if ( in_array( 'wp-i18n', $deps, true ) ) { |
| 45 |
$scripts->set_translations( $handle ); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Register all package scripts. |
| 51 |
*/ |
| 52 |
function ai_register_package_scripts( $scripts ) { |
| 53 |
// Load build constants |
| 54 |
$build_constants = require __DIR__ . '/constants.php'; |
| 55 |
$default_version = ! SCRIPT_DEBUG ? $build_constants['version'] : time(); |
| 56 |
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js'; |
| 57 |
|
| 58 |
$scripts_dir = __DIR__ . '/scripts'; |
| 59 |
$scripts_file = $scripts_dir . '/registry.php'; |
| 60 |
|
| 61 |
if ( ! file_exists( $scripts_file ) ) { |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
$scripts_data = require $scripts_file; |
| 66 |
$plugin_dir = dirname( __FILE__ ); |
| 67 |
|
| 68 |
foreach ( $scripts_data as $script_data ) { |
| 69 |
$asset_file = $scripts_dir . '/' . $script_data['asset']; |
| 70 |
$asset = file_exists( $asset_file ) ? require $asset_file : array(); |
| 71 |
$dependencies = $asset['dependencies'] ?? array(); |
| 72 |
$version = $asset['version'] ?? $default_version; |
| 73 |
|
| 74 |
ai_override_script( |
| 75 |
$scripts, |
| 76 |
$script_data['handle'], |
| 77 |
$build_constants['build_url'] . 'scripts/' . $script_data['path'] . $extension, |
| 78 |
$dependencies, |
| 79 |
$version, |
| 80 |
true |
| 81 |
); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
add_action( 'wp_default_scripts', 'ai_register_package_scripts' ); |
| 86 |
|