PluginProbe
Gutenberg / 22.3.0
Gutenberg v22.3.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / scripts.php

scripts.php in Gutenberg 22.3.0, at build/scripts.php

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