Make WordPress Core

Ticket #59599: 58599.diff

File 58599.diff, 1.1 KB (added by adamsilverstein, 12 months ago)
  • src/wp-includes/class-wp-scripts.php

    diff --git src/wp-includes/class-wp-scripts.php src/wp-includes/class-wp-scripts.php
    index a6a283f953..612ac7d06f 100644
    class WP_Scripts extends WP_Dependencies { 
    281281                        $intended_strategy = '';
    282282                }
    283283
     284                // If the script is in the header group, current output is the header, the intended strategy is `defer`, the
     285                // actual strategy is not defer and all dependent scripts are in the footer - move this script to the footer.
     286                if ( 'defer' === $intended_strategy && 'defer' !== $strategy && 0 === $this->groups[ $handle ] && 0 === $group ) {
     287                        // Check that all depedencies are in the footer.
     288                        $all_deps_in_footer = true;
     289                        foreach ( $this->get_dependents( $handle ) as $dep ) {
     290                                if ( isset( $this->groups[ $dep ] ) && 1 !== $this->groups[ $dep ] ) {
     291                                        $all_deps_in_footer = false;
     292                                        break;
     293                                }
     294                        }
     295                        if ( $all_deps_in_footer ) {
     296                                $this->in_footer[] = $handle;
     297                                $this->groups[ $handle ] = 1;
     298                                return;
     299                        }
     300                }
     301
    284302                if ( $conditional ) {
    285303                        $cond_before = "<!--[if {$conditional}]>\n";
    286304                        $cond_after  = "<![endif]-->\n";