WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/30/2019 05:40:14 PM (20 months ago)
Author:
desrosj
Message:

Bundled Themes: Update Twenty Twenty.

This brings trunk’s version of Twenty Twenty in-sync with GitHub.

For a complete list of changes since [46271], see https://github.com/WordPress/twentytwenty/compare/932b16248...dd7032f

Props anlino, ianbelanger, nielslange, acosmin, netweb, williampatton, adhitya03, phpdocs, acalfieri, itowhid06, littlebigthing, aristath, karmatosed, poena.
See #48110.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-script-loader.php

    r46271 r46357  
    11<?php
    22/**
    3  * Javsscript Loader Class
     3 * Javascript Loader Class
    44 *
    55 * Allow `async` and `defer` while enqueuing Javascript.
    66 *
    7  * Based on a soltion in WP Rig.
     7 * Based on a solution in WP Rig.
    88 *
    99 * @package WordPress
     
    1212 */
    1313
    14 /**
    15  * A class that provides a way to add `async` or `defer` attributes to scripts.
    16  */
    17 class TwentyTwenty_Script_Loader {
     14if ( ! class_exists( 'TwentyTwenty_Script_Loader' ) ) {
     15    /**
     16     * A class that provides a way to add `async` or `defer` attributes to scripts.
     17     */
     18    class TwentyTwenty_Script_Loader {
    1819
    19     /**
    20      * Adds async/defer attributes to enqueued / registered scripts.
    21      *
    22      * If #12009 lands in WordPress, this function can no-op since it would be handled in core.
    23      *
    24      * @link https://core.trac.wordpress.org/ticket/12009
    25      *
    26      * @param string $tag    The script tag.
    27      * @param string $handle The script handle.
    28      * @return string Script HTML string.
    29      */
    30     public function filter_script_loader_tag( $tag, $handle ) {
    31         foreach ( array( 'async', 'defer' ) as $attr ) {
    32             if ( ! wp_scripts()->get_data( $handle, $attr ) ) {
    33                 continue;
     20        /**
     21         * Adds async/defer attributes to enqueued / registered scripts.
     22         *
     23         * If #12009 lands in WordPress, this function can no-op since it would be handled in core.
     24         *
     25         * @link https://core.trac.wordpress.org/ticket/12009
     26         *
     27         * @param string $tag    The script tag.
     28         * @param string $handle The script handle.
     29         * @return string Script HTML string.
     30         */
     31        public function filter_script_loader_tag( $tag, $handle ) {
     32            foreach ( [ 'async', 'defer' ] as $attr ) {
     33                if ( ! wp_scripts()->get_data( $handle, $attr ) ) {
     34                    continue;
     35                }
     36                // Prevent adding attribute when already added in #12009.
     37                if ( ! preg_match( ":\s$attr(=|>|\s):", $tag ) ) {
     38                    $tag = preg_replace( ':(?=></script>):', " $attr", $tag, 1 );
     39                }
     40                // Only allow async or defer, not both.
     41                break;
    3442            }
    35             // Prevent adding attribute when already added in #12009.
    36             if ( ! preg_match( ":\s$attr(=|>|\s):", $tag ) ) {
    37                 $tag = preg_replace( ':(?=></script>):', " $attr", $tag, 1 );
    38             }
    39             // Only allow async or defer, not both.
    40             break;
     43            return $tag;
    4144        }
    42         return $tag;
     45
    4346    }
    44 
    4547}
Note: See TracChangeset for help on using the changeset viewer.