Changeset 56556 for trunk/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-script-loader.php
- Timestamp:
- 09/12/2023 12:04:15 AM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-script-loader.php
r56547 r56556 21 21 22 22 /** 23 * Migrates legacy async/defer script data which might be used by child themes. 24 * 25 * This method is used on the `print_scripts_array` filter. 26 * 27 * @since Twenty Twenty 2.0 28 * 29 * @param string[] $to_do An array of script dependency handles. 30 * @return string[] Unchanged array of script dependency handles. 31 */ 32 public function migrate_legacy_strategy_script_data( $to_do ) { 33 foreach ( $to_do as $handle ) { 34 foreach ( array( 'async', 'defer' ) as $strategy ) { 35 if ( wp_scripts()->get_data( $handle, $strategy ) ) { 36 wp_script_add_data( $handle, 'strategy', $strategy ); 37 } 38 } 39 } 40 return $to_do; 41 } 42 43 /** 23 44 * Adds async/defer attributes to enqueued / registered scripts. 24 45 * 25 * If #12009 lands in WordPress, this function can no-op since it would be handled in core. 46 * Now that #12009 has landed in WordPress 6.3, this method is only used for older versions of WordPress. 47 * This method is used on the `script_loader_tag` filter. 26 48 * 27 49 * @since Twenty Twenty 1.0 … … 34 56 */ 35 57 public function filter_script_loader_tag( $tag, $handle ) { 36 foreach ( array( 'async', 'defer' ) as $attr ) { 37 if ( ! wp_scripts()->get_data( $handle, $attr ) ) { 38 continue; 39 } 58 $strategies = array( 59 'async' => (bool) wp_scripts()->get_data( $handle, 'async' ), 60 'defer' => (bool) wp_scripts()->get_data( $handle, 'defer' ), 61 ); 62 $strategy = wp_scripts()->get_data( $handle, 'strategy' ); 63 if ( $strategy && isset( $strategies[ $strategy ] ) ) { 64 $strategies[ $strategy ] = true; 65 } 66 67 foreach ( array_keys( array_filter( $strategies ) ) as $attr ) { 68 40 69 // Prevent adding attribute when already added in #12009. 41 70 if ( ! preg_match( ":\s$attr(=|>|\s):", $tag ) ) {
Note: See TracChangeset
for help on using the changeset viewer.