PluginProbe
Gutenberg / 22.9.0
Gutenberg v22.9.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 / modules.php

modules.php in Gutenberg 22.9.0, at build/modules.php

62 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Script module registration - Auto-generated by build process.
4 * Do not edit this file manually.
5 *
6 * @package gutenberg
7 */
8
9 /**
10 * Register all script modules.
11 */
12 function gutenberg_register_script_modules() {
13 // Ensure this only runs once. wp_default_scripts can fire multiple times,
14 // and each wp_deregister_script_module() call also dequeues the module.
15 // If a module was enqueued between calls, repeated deregister/register
16 // cycles would lose the enqueue state.
17 static $already_registered = false;
18 if ( $already_registered ) {
19 return;
20 }
21 $already_registered = true;
22
23 // Load build constants
24 $build_constants = require __DIR__ . '/constants.php';
25 $modules_dir = __DIR__ . '/modules';
26 $modules_file = $modules_dir . '/registry.php';
27
28 if ( ! file_exists( $modules_file ) ) {
29 return;
30 }
31
32 $modules = require $modules_file;
33 $base_url = $build_constants['build_url'] . 'modules/';
34
35 foreach ( $modules as $module ) {
36 // WASM-only modules (e.g., vips worker) only have .min.js; use it even when SCRIPT_DEBUG is `true`.
37 $extension = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && empty( $module['min_only'] ) )
38 ? '.js'
39 : '.min.js';
40
41 $asset_path = $modules_dir . '/' . $module['asset'];
42 $asset = file_exists( $asset_path ) ? require $asset_path : array();
43
44 // Deregister first to override any previously registered version
45 // (e.g., Core's default modules when running as a plugin).
46 wp_deregister_script_module( $module['id'] );
47
48 wp_register_script_module(
49 $module['id'],
50 $base_url . $module['path'] . $extension,
51 $asset['module_dependencies'] ?? array(),
52 $asset['version'] ?? false,
53 array(
54 'fetchpriority' => 'low',
55 'in_footer' => true,
56 )
57 );
58 }
59 }
60
61 add_action( 'wp_default_scripts', 'gutenberg_register_script_modules' );
62