Skip to content

Commit 5fb72b7

Browse files
committed
Unset dependencies for conditional scripts.
Prevent dependencies from being added when only required by a conditional script or style.
1 parent e4d1717 commit 5fb72b7

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/wp-includes/class-wp-scripts.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,10 @@ public function add_data( $handle, $key, $value ) {
792792
return false;
793793
}
794794

795+
if ( 'conditional' === $key ) {
796+
$this->registered[ $handle ]->deps = array();
797+
}
798+
795799
if ( 'strategy' === $key ) {
796800
if ( ! empty( $value ) && ! $this->is_delayed_strategy( $value ) ) {
797801
_doing_it_wrong(

src/wp-includes/class-wp-styles.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,28 @@ public function print_inline_style( $handle, $display = true ) {
346346
return true;
347347
}
348348

349+
/**
350+
* Overrides the add_data method from WP_Dependencies, to allow unsetting dependencies for conditional styles.
351+
*
352+
* @since 6.9.0
353+
*
354+
* @param string $handle Name of the item. Should be unique.
355+
* @param string $key The data key.
356+
* @param mixed $value The data value.
357+
* @return bool True on success, false on failure.
358+
*/
359+
public function add_data( $handle, $key, $value ) {
360+
if ( ! isset( $this->registered[ $handle ] ) ) {
361+
return false;
362+
}
363+
364+
if ( 'conditional' === $key ) {
365+
$this->registered[ $handle ]->deps = array();
366+
}
367+
368+
return $this->registered[ $handle ]->add_data( $key, $value );
369+
}
370+
349371
/**
350372
* Determines style dependencies.
351373
*

0 commit comments

Comments
 (0)