Changeset 60930 for trunk/src/wp-includes/class-wp-script-modules.php
- Timestamp:
- 10/14/2025 12:10:31 AM (4 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-wp-script-modules.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-script-modules.php
r60704 r60930 24 24 25 25 /** 26 * Holds the script module identifiers that were enqueued before registered.27 * 28 * @since 6. 5.029 * @var array<string, true>30 */ 31 p rivate $enqueued_before_registered= array();26 * An array of IDs for queued script modules. 27 * 28 * @since 6.9.0 29 * @var string[] 30 */ 31 public $queue = array(); 32 32 33 33 /** … … 123 123 'src' => $src, 124 124 'version' => $version, 125 'enqueue' => isset( $this->enqueued_before_registered[ $id ] ),126 125 'dependencies' => $dependencies, 127 126 'fetchpriority' => $fetchpriority, … … 214 213 */ 215 214 public function enqueue( string $id, string $src = '', array $deps = array(), $version = false, array $args = array() ) { 216 if ( isset( $this->registered[ $id ] ) ) { 217 $this->registered[ $id ]['enqueue'] = true; 218 } elseif ( $src ) { 215 if ( ! in_array( $id, $this->queue, true ) ) { 216 $this->queue[] = $id; 217 } 218 if ( ! isset( $this->registered[ $id ] ) && $src ) { 219 219 $this->register( $id, $src, $deps, $version, $args ); 220 $this->registered[ $id ]['enqueue'] = true;221 } else {222 $this->enqueued_before_registered[ $id ] = true;223 220 } 224 221 } … … 232 229 */ 233 230 public function dequeue( string $id ) { 234 if ( isset( $this->registered[ $id ] ) ) { 235 $this->registered[ $id ]['enqueue'] = false; 236 } 237 unset( $this->enqueued_before_registered[ $id ] ); 231 $this->queue = array_diff( $this->queue, array( $id ) ); 238 232 } 239 233 … … 246 240 */ 247 241 public function deregister( string $id ) { 242 $this->dequeue( $id ); 248 243 unset( $this->registered[ $id ] ); 249 unset( $this->enqueued_before_registered[ $id ] );250 244 } 251 245 … … 305 299 */ 306 300 public function print_script_module_preloads() { 307 foreach ( $this->get_dependencies( array_ keys( $this->get_marked_for_enqueue()), array( 'static' ) ) as $id => $script_module ) {301 foreach ( $this->get_dependencies( array_unique( $this->queue ), array( 'static' ) ) as $id => $script_module ) { 308 302 // Don't preload if it's marked for enqueue. 309 if ( true !== $script_module['enqueue']) {303 if ( ! in_array( $id, $this->queue, true ) ) { 310 304 echo sprintf( 311 305 '<link rel="modulepreload" href="%s" id="%s"%s>', … … 346 340 private function get_import_map(): array { 347 341 $imports = array(); 348 foreach ( $this->get_dependencies( array_ keys( $this->get_marked_for_enqueue()) ) as $id => $script_module ) {342 foreach ( $this->get_dependencies( array_unique( $this->queue ) ) as $id => $script_module ) { 349 343 $imports[ $id ] = $this->get_src( $id ); 350 344 } … … 360 354 */ 361 355 private function get_marked_for_enqueue(): array { 362 $enqueued = array(); 363 foreach ( $this->registered as $id => $script_module ) { 364 if ( true === $script_module['enqueue'] ) { 365 $enqueued[ $id ] = $script_module; 366 } 367 } 368 return $enqueued; 356 return wp_array_slice_assoc( 357 $this->registered, 358 $this->queue 359 ); 369 360 } 370 361 … … 458 449 public function print_script_module_data(): void { 459 450 $modules = array(); 460 foreach ( array_ keys( $this->get_marked_for_enqueue()) as $id ) {451 foreach ( array_unique( $this->queue ) as $id ) { 461 452 if ( '@wordpress/a11y' === $id ) { 462 453 $this->a11y_available = true;
Note: See TracChangeset
for help on using the changeset viewer.