From 2fc3745f6c9063845f03e933d8b53369f64a304b Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 22 Nov 2023 08:30:32 -0700 Subject: [PATCH 01/28] Missing file doc comment (Squiz.Commenting.FileComment.Missing) --- composer.lock | 96 +++++++++--------- .../js-and-css/optimize-oembeds/helper.php | 11 +++ modules/js-and-css/optimize-oembeds/hooks.php | 97 +++++++++++++++++++ modules/js-and-css/optimize-oembeds/load.php | 12 +++ 4 files changed, 171 insertions(+), 45 deletions(-) create mode 100644 modules/js-and-css/optimize-oembeds/helper.php create mode 100644 modules/js-and-css/optimize-oembeds/hooks.php create mode 100644 modules/js-and-css/optimize-oembeds/load.php diff --git a/composer.lock b/composer.lock index 59e7347f0..5b7c7867b 100644 --- a/composer.lock +++ b/composer.lock @@ -236,30 +236,30 @@ }, { "name": "doctrine/instantiator", - "version": "2.0.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0" + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", - "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", "shasum": "" }, "require": { - "php": "^8.1" + "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^11", + "doctrine/coding-standard": "^9 || ^11", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^1.2", - "phpstan/phpstan": "^1.9.4", - "phpstan/phpstan-phpunit": "^1.3", - "phpunit/phpunit": "^9.5.27", - "vimeo/psalm": "^5.4" + "phpbench/phpbench": "^0.16 || ^1", + "phpstan/phpstan": "^1.4", + "phpstan/phpstan-phpunit": "^1", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "vimeo/psalm": "^4.30 || ^5.4" }, "type": "library", "autoload": { @@ -286,7 +286,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/2.0.0" + "source": "https://github.com/doctrine/instantiator/tree/1.5.0" }, "funding": [ { @@ -302,7 +302,7 @@ "type": "tidelift" } ], - "time": "2022-12-30T00:23:10+00:00" + "time": "2022-12-30T00:15:36+00:00" }, { "name": "myclabs/deep-copy", @@ -532,28 +532,31 @@ }, { "name": "php-stubs/wordpress-stubs", - "version": "v6.3.0", + "version": "v6.4.1", "source": { "type": "git", "url": "https://github.com/php-stubs/wordpress-stubs.git", - "reference": "adda7609e71d5f4dc7b87c74f8ec9e3437d2e92c" + "reference": "6d6063cf9464a306ca2a0529705d41312b08500b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/adda7609e71d5f4dc7b87c74f8ec9e3437d2e92c", - "reference": "adda7609e71d5f4dc7b87c74f8ec9e3437d2e92c", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/6d6063cf9464a306ca2a0529705d41312b08500b", + "reference": "6d6063cf9464a306ca2a0529705d41312b08500b", "shasum": "" }, "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "nikic/php-parser": "^4.13", "php": "^7.4 || ~8.0.0", "php-stubs/generator": "^0.8.3", "phpdocumentor/reflection-docblock": "^5.3", "phpstan/phpstan": "^1.10.12", - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5", + "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.8" }, "suggest": { "paragonie/sodium_compat": "Pure PHP implementation of libsodium", + "symfony/polyfill-php80": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" }, "type": "library", @@ -570,9 +573,9 @@ ], "support": { "issues": "https://github.com/php-stubs/wordpress-stubs/issues", - "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.3.0" + "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.4.1" }, - "time": "2023-08-10T16:34:11+00:00" + "time": "2023-11-10T00:33:47+00:00" }, { "name": "phpcompatibility/php-compatibility", @@ -818,16 +821,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.2", + "version": "1.24.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "bcad8d995980440892759db0c32acae7c8e79442" + "reference": "12f01d214f1c73b9c91fdb3b1c415e4c70652083" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bcad8d995980440892759db0c32acae7c8e79442", - "reference": "bcad8d995980440892759db0c32acae7c8e79442", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/12f01d214f1c73b9c91fdb3b1c415e4c70652083", + "reference": "12f01d214f1c73b9c91fdb3b1c415e4c70652083", "shasum": "" }, "require": { @@ -859,22 +862,22 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.2" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.3" }, - "time": "2023-09-26T12:28:12+00:00" + "time": "2023-11-18T20:15:32+00:00" }, { "name": "phpstan/phpstan", - "version": "1.10.38", + "version": "1.10.44", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "5302bb402c57f00fb3c2c015bac86e0827e4b691" + "reference": "bf84367c53a23f759513985c54ffe0d0c249825b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/5302bb402c57f00fb3c2c015bac86e0827e4b691", - "reference": "5302bb402c57f00fb3c2c015bac86e0827e4b691", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/bf84367c53a23f759513985c54ffe0d0c249825b", + "reference": "bf84367c53a23f759513985c54ffe0d0c249825b", "shasum": "" }, "require": { @@ -923,7 +926,7 @@ "type": "tidelift" } ], - "time": "2023-10-06T14:19:14+00:00" + "time": "2023-11-21T16:30:46+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", @@ -2614,22 +2617,22 @@ }, { "name": "szepeviktor/phpstan-wordpress", - "version": "v1.3.0", + "version": "v1.3.2", "source": { "type": "git", "url": "https://github.com/szepeviktor/phpstan-wordpress.git", - "reference": "5b5cc77ed51fdaf64efe3f00b5aae4b709d2cfa9" + "reference": "b8516ed6bab7ec50aae981698ce3f67f1be2e45a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/5b5cc77ed51fdaf64efe3f00b5aae4b709d2cfa9", - "reference": "5b5cc77ed51fdaf64efe3f00b5aae4b709d2cfa9", + "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/b8516ed6bab7ec50aae981698ce3f67f1be2e45a", + "reference": "b8516ed6bab7ec50aae981698ce3f67f1be2e45a", "shasum": "" }, "require": { "php": "^7.2 || ^8.0", "php-stubs/wordpress-stubs": "^4.7 || ^5.0 || ^6.0", - "phpstan/phpstan": "^1.10.0", + "phpstan/phpstan": "^1.10.30", "symfony/polyfill-php73": "^1.12.0" }, "require-dev": { @@ -2640,6 +2643,9 @@ "phpunit/phpunit": "^8.0 || ^9.0", "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.8" }, + "suggest": { + "swissspidy/phpstan-no-private": "Detect usage of internal core functions, classes and methods" + }, "type": "phpstan-extension", "extra": { "phpstan": { @@ -2667,22 +2673,22 @@ ], "support": { "issues": "https://github.com/szepeviktor/phpstan-wordpress/issues", - "source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v1.3.0" + "source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v1.3.2" }, - "time": "2023-04-23T06:15:06+00:00" + "time": "2023-10-16T17:23:56+00:00" }, { "name": "theseer/tokenizer", - "version": "1.2.1", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" + "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", - "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/b2ad5003ca10d4ee50a12da31de12a5774ba6b96", + "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96", "shasum": "" }, "require": { @@ -2711,7 +2717,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/1.2.1" + "source": "https://github.com/theseer/tokenizer/tree/1.2.2" }, "funding": [ { @@ -2719,7 +2725,7 @@ "type": "github" } ], - "time": "2021-07-28T10:34:58+00:00" + "time": "2023-11-20T00:12:19+00:00" }, { "name": "wp-coding-standards/wpcs", @@ -2905,5 +2911,5 @@ "php": ">=7|^8" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.0.0" } diff --git a/modules/js-and-css/optimize-oembeds/helper.php b/modules/js-and-css/optimize-oembeds/helper.php new file mode 100644 index 000000000..464e8e440 --- /dev/null +++ b/modules/js-and-css/optimize-oembeds/helper.php @@ -0,0 +1,11 @@ +]*>([\s\S]*?)<\/script>/mi', $html, $matches ); + + if ( ! empty( $matches[0][0] ) ) { + + $found_tag = $matches[0][0]; + + // Remove the src attribute from the first script tag, transforming it into data-lazy-src. + $script_tag = str_replace( 'src=', 'data-lazy-embed-src=', $matches[0][0] ); + + ++$oembed_lazy_load_scripts; + + // Replace the script tag with the new one. + $html = str_replace( $found_tag, $script_tag, $html ); + + } + + // Bail early if the tag already has a loading attribute. + if ( false !== strpos( $html, 'loading=' ) ) { + return $html; + } + + // Add loading="lazy" to iframe tags. + $html = str_replace( ' + + Date: Wed, 22 Nov 2023 12:26:35 -0700 Subject: [PATCH 02/28] Add oEmbed Optimize module --- modules/js-and-css/optimize-oembeds/helper.php | 11 ----------- modules/js-and-css/optimize-oembeds/load.php | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 modules/js-and-css/optimize-oembeds/helper.php diff --git a/modules/js-and-css/optimize-oembeds/helper.php b/modules/js-and-css/optimize-oembeds/helper.php deleted file mode 100644 index 464e8e440..000000000 --- a/modules/js-and-css/optimize-oembeds/helper.php +++ /dev/null @@ -1,11 +0,0 @@ - Date: Wed, 22 Nov 2023 12:44:36 -0700 Subject: [PATCH 03/28] resore composer.lock --- composer.lock | 96 ++++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 51 deletions(-) diff --git a/composer.lock b/composer.lock index 5b7c7867b..59e7347f0 100644 --- a/composer.lock +++ b/composer.lock @@ -236,30 +236,30 @@ }, { "name": "doctrine/instantiator", - "version": "1.5.0", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", - "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0" + "php": "^8.1" }, "require-dev": { - "doctrine/coding-standard": "^9 || ^11", + "doctrine/coding-standard": "^11", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^0.16 || ^1", - "phpstan/phpstan": "^1.4", - "phpstan/phpstan-phpunit": "^1", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.30 || ^5.4" + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.9.4", + "phpstan/phpstan-phpunit": "^1.3", + "phpunit/phpunit": "^9.5.27", + "vimeo/psalm": "^5.4" }, "type": "library", "autoload": { @@ -286,7 +286,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.5.0" + "source": "https://github.com/doctrine/instantiator/tree/2.0.0" }, "funding": [ { @@ -302,7 +302,7 @@ "type": "tidelift" } ], - "time": "2022-12-30T00:15:36+00:00" + "time": "2022-12-30T00:23:10+00:00" }, { "name": "myclabs/deep-copy", @@ -532,31 +532,28 @@ }, { "name": "php-stubs/wordpress-stubs", - "version": "v6.4.1", + "version": "v6.3.0", "source": { "type": "git", "url": "https://github.com/php-stubs/wordpress-stubs.git", - "reference": "6d6063cf9464a306ca2a0529705d41312b08500b" + "reference": "adda7609e71d5f4dc7b87c74f8ec9e3437d2e92c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/6d6063cf9464a306ca2a0529705d41312b08500b", - "reference": "6d6063cf9464a306ca2a0529705d41312b08500b", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/adda7609e71d5f4dc7b87c74f8ec9e3437d2e92c", + "reference": "adda7609e71d5f4dc7b87c74f8ec9e3437d2e92c", "shasum": "" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "nikic/php-parser": "^4.13", "php": "^7.4 || ~8.0.0", "php-stubs/generator": "^0.8.3", "phpdocumentor/reflection-docblock": "^5.3", "phpstan/phpstan": "^1.10.12", - "phpunit/phpunit": "^9.5", - "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.8" + "phpunit/phpunit": "^9.5" }, "suggest": { "paragonie/sodium_compat": "Pure PHP implementation of libsodium", - "symfony/polyfill-php80": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" }, "type": "library", @@ -573,9 +570,9 @@ ], "support": { "issues": "https://github.com/php-stubs/wordpress-stubs/issues", - "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.4.1" + "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.3.0" }, - "time": "2023-11-10T00:33:47+00:00" + "time": "2023-08-10T16:34:11+00:00" }, { "name": "phpcompatibility/php-compatibility", @@ -821,16 +818,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.3", + "version": "1.24.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "12f01d214f1c73b9c91fdb3b1c415e4c70652083" + "reference": "bcad8d995980440892759db0c32acae7c8e79442" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/12f01d214f1c73b9c91fdb3b1c415e4c70652083", - "reference": "12f01d214f1c73b9c91fdb3b1c415e4c70652083", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bcad8d995980440892759db0c32acae7c8e79442", + "reference": "bcad8d995980440892759db0c32acae7c8e79442", "shasum": "" }, "require": { @@ -862,22 +859,22 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.3" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.2" }, - "time": "2023-11-18T20:15:32+00:00" + "time": "2023-09-26T12:28:12+00:00" }, { "name": "phpstan/phpstan", - "version": "1.10.44", + "version": "1.10.38", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "bf84367c53a23f759513985c54ffe0d0c249825b" + "reference": "5302bb402c57f00fb3c2c015bac86e0827e4b691" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/bf84367c53a23f759513985c54ffe0d0c249825b", - "reference": "bf84367c53a23f759513985c54ffe0d0c249825b", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/5302bb402c57f00fb3c2c015bac86e0827e4b691", + "reference": "5302bb402c57f00fb3c2c015bac86e0827e4b691", "shasum": "" }, "require": { @@ -926,7 +923,7 @@ "type": "tidelift" } ], - "time": "2023-11-21T16:30:46+00:00" + "time": "2023-10-06T14:19:14+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", @@ -2617,22 +2614,22 @@ }, { "name": "szepeviktor/phpstan-wordpress", - "version": "v1.3.2", + "version": "v1.3.0", "source": { "type": "git", "url": "https://github.com/szepeviktor/phpstan-wordpress.git", - "reference": "b8516ed6bab7ec50aae981698ce3f67f1be2e45a" + "reference": "5b5cc77ed51fdaf64efe3f00b5aae4b709d2cfa9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/b8516ed6bab7ec50aae981698ce3f67f1be2e45a", - "reference": "b8516ed6bab7ec50aae981698ce3f67f1be2e45a", + "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/5b5cc77ed51fdaf64efe3f00b5aae4b709d2cfa9", + "reference": "5b5cc77ed51fdaf64efe3f00b5aae4b709d2cfa9", "shasum": "" }, "require": { "php": "^7.2 || ^8.0", "php-stubs/wordpress-stubs": "^4.7 || ^5.0 || ^6.0", - "phpstan/phpstan": "^1.10.30", + "phpstan/phpstan": "^1.10.0", "symfony/polyfill-php73": "^1.12.0" }, "require-dev": { @@ -2643,9 +2640,6 @@ "phpunit/phpunit": "^8.0 || ^9.0", "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.8" }, - "suggest": { - "swissspidy/phpstan-no-private": "Detect usage of internal core functions, classes and methods" - }, "type": "phpstan-extension", "extra": { "phpstan": { @@ -2673,22 +2667,22 @@ ], "support": { "issues": "https://github.com/szepeviktor/phpstan-wordpress/issues", - "source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v1.3.2" + "source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v1.3.0" }, - "time": "2023-10-16T17:23:56+00:00" + "time": "2023-04-23T06:15:06+00:00" }, { "name": "theseer/tokenizer", - "version": "1.2.2", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96" + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/b2ad5003ca10d4ee50a12da31de12a5774ba6b96", - "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", "shasum": "" }, "require": { @@ -2717,7 +2711,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/1.2.2" + "source": "https://github.com/theseer/tokenizer/tree/1.2.1" }, "funding": [ { @@ -2725,7 +2719,7 @@ "type": "github" } ], - "time": "2023-11-20T00:12:19+00:00" + "time": "2021-07-28T10:34:58+00:00" }, { "name": "wp-coding-standards/wpcs", @@ -2911,5 +2905,5 @@ "php": ">=7|^8" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.6.0" } From d65e17034d5a575d4e878b708618651744d69395 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 22 Nov 2023 12:51:41 -0700 Subject: [PATCH 04/28] cleanup --- modules/js-and-css/optimize-oembeds/hooks.php | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index 2866b356f..0b26c3ba5 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -10,7 +10,7 @@ exit; // Exit if accessed directly. } -$oembed_lazy_load_scripts = 0; +$oembed_lazy_load_scripts = false; /** * Filter the oEmbed HTML. @@ -25,31 +25,32 @@ function plab_optimize_oembed_html( $html ) { global $oembed_lazy_load_scripts; - // Locate script tags using regex. + // Find script tags in the oembed using regex. preg_match_all( '/]*>([\s\S]*?)<\/script>/mi', $html, $matches ); if ( ! empty( $matches[0][0] ) ) { - - $found_tag = $matches[0][0]; + $found_tag = $matches[0][0]; + $oembed_lazy_load_scripts = true; // Remove the src attribute from the first script tag, transforming it into data-lazy-src. $script_tag = str_replace( 'src=', 'data-lazy-embed-src=', $matches[0][0] ); - ++$oembed_lazy_load_scripts; - // Replace the script tag with the new one. $html = str_replace( $found_tag, $script_tag, $html ); - } - // Bail early if the tag already has a loading attribute. - if ( false !== strpos( $html, 'loading=' ) ) { - return $html; - } - - // Add loading="lazy" to iframe tags. - $html = str_replace( ']*>([\s\S]*?)<\/iframe>/mi', $html, $matches ); + // Add loading="lazy" to iframes that don't have a loading attribute. + if ( ! empty( $matches[0][0] ) ) { + foreach ( $matches[0] as $match ) { + if ( false === strpos( $match, 'loading=' ) ) { + $iframe_tag = str_replace( ' From aaeb1be3ced0c37873638f85baaef75cae9ae742 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 22 Nov 2023 12:53:56 -0700 Subject: [PATCH 05/28] improve docblocks --- modules/js-and-css/optimize-oembeds/hooks.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index 0b26c3ba5..378caff94 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -15,7 +15,8 @@ /** * Filter the oEmbed HTML. * - * Always add loading="lazy" to any iframe tags. + * Add loading="lazy" to any iframe tags. + * Lazy load any script tags. * * @since n.e.x.t * @@ -57,7 +58,7 @@ function plab_optimize_oembed_html( $html ) { /** * Add a script to the footer if there are lazy loaded embeds. - * This script will load the embeds when they approach the viewport. + * Load the embed's scripts when they approach the viewport using an IntersectionObserver. * * @since n.e.x.t */ From 4001a0a5fb80e3e25fd352c43a89641f3d6731a8 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 22 Nov 2023 13:00:32 -0700 Subject: [PATCH 06/28] improve docblocks 2 --- modules/js-and-css/optimize-oembeds/hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index 378caff94..f4a2e466e 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -20,7 +20,7 @@ * * @since n.e.x.t * - * @param string $html The cached HTML result, stored in post meta. + * @param string $html The oEmbed HTML. * @return string */ function plab_optimize_oembed_html( $html ) { From 21f29082121061704e84d58a185b79d60b7198c8 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 24 Nov 2023 12:57:53 -0700 Subject: [PATCH 07/28] Process oEmbeds with WP_HTML_Tag_Processor --- modules/js-and-css/optimize-oembeds/hooks.php | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index f4a2e466e..b5d04f8d6 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -26,32 +26,22 @@ function plab_optimize_oembed_html( $html ) { global $oembed_lazy_load_scripts; - // Find script tags in the oembed using regex. - preg_match_all( '/]*>([\s\S]*?)<\/script>/mi', $html, $matches ); - - if ( ! empty( $matches[0][0] ) ) { - $found_tag = $matches[0][0]; + // Find iframes and script tags in the oEmbed using the WP_HTML_Tag_Processor. + $p = new WP_HTML_Tag_Processor( $html ); + if ( $p->next_tag( 'iframe' ) ) { + if ( empty( $p->get_attribute( 'loading' ) ) ) { + $p->set_attribute( 'loading', 'lazy' ); + $html = $p->get_updated_html(); + } + } + $p = new WP_HTML_Tag_Processor( $html ); + if ( $p->next_tag( 'script' ) ) { $oembed_lazy_load_scripts = true; - - // Remove the src attribute from the first script tag, transforming it into data-lazy-src. - $script_tag = str_replace( 'src=', 'data-lazy-embed-src=', $matches[0][0] ); - - // Replace the script tag with the new one. - $html = str_replace( $found_tag, $script_tag, $html ); + $p->set_attribute( 'data-lazy-embed-src', $p->get_attribute( 'src' ) ); + $p->set_attribute( 'src', '' ); + $html = $p->get_updated_html(); } - // Find iframes in the oEmbed using a regex. - preg_match_all( '/]*>([\s\S]*?)<\/iframe>/mi', $html, $matches ); - - // Add loading="lazy" to iframes that don't have a loading attribute. - if ( ! empty( $matches[0][0] ) ) { - foreach ( $matches[0] as $match ) { - if ( false === strpos( $match, 'loading=' ) ) { - $iframe_tag = str_replace( ' Date: Fri, 24 Nov 2023 13:00:49 -0700 Subject: [PATCH 08/28] Correct namespace prefix --- modules/js-and-css/optimize-oembeds/hooks.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index b5d04f8d6..a674356d5 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -23,7 +23,7 @@ * @param string $html The oEmbed HTML. * @return string */ -function plab_optimize_oembed_html( $html ) { +function perflab_optimize_oembed_html( $html ) { global $oembed_lazy_load_scripts; // Find iframes and script tags in the oEmbed using the WP_HTML_Tag_Processor. @@ -44,7 +44,7 @@ function plab_optimize_oembed_html( $html ) { return $html; } -add_filter( 'embed_oembed_html', 'plab_optimize_oembed_html', 10 ); +add_filter( 'embed_oembed_html', 'perflab_optimize_oembed_html', 10 ); /** * Add a script to the footer if there are lazy loaded embeds. @@ -52,7 +52,7 @@ function plab_optimize_oembed_html( $html ) { * * @since n.e.x.t */ -function plab_optimize_oembed_lazy_load_scripts() { +function perflab_optimize_oembed_lazy_load_scripts() { global $oembed_lazy_load_scripts; if ( ! $oembed_lazy_load_scripts ) { @@ -86,4 +86,4 @@ function plab_optimize_oembed_lazy_load_scripts() { Date: Fri, 24 Nov 2023 13:02:45 -0700 Subject: [PATCH 09/28] remove unused observer parameter --- modules/js-and-css/optimize-oembeds/hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index a674356d5..187a79bc3 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -66,7 +66,7 @@ function perflab_optimize_oembed_lazy_load_scripts() { lazyEmbeds.forEach( function( lazyEmbed ) { parents.push( lazyEmbed.parentNode ); } ); - var lazyEmbedObserver = new IntersectionObserver( function( entries, observer ) { + var lazyEmbedObserver = new IntersectionObserver( function( entries ) { entries.forEach( function( entry ) { if ( entry.isIntersecting ) { var lazyDiv = entry.target; From 9eab381384c362638f70e76d8b702863d17ef43d Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Mon, 27 Nov 2023 16:23:23 -0700 Subject: [PATCH 10/28] single WP_HTML_Tag_Processor loop --- modules/js-and-css/optimize-oembeds/hooks.php | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index 187a79bc3..6a6d8a302 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -26,21 +26,24 @@ function perflab_optimize_oembed_html( $html ) { global $oembed_lazy_load_scripts; - // Find iframes and script tags in the oEmbed using the WP_HTML_Tag_Processor. $p = new WP_HTML_Tag_Processor( $html ); - if ( $p->next_tag( 'iframe' ) ) { - if ( empty( $p->get_attribute( 'loading' ) ) ) { - $p->set_attribute( 'loading', 'lazy' ); - $html = $p->get_updated_html(); + + // Find the first iframe or script tag to act on. + while ( $p->next_tag() ) { + if ( 'IFRAME' === $p->get_tag() ) { + $loading_value = $p->get_attribute( 'loading' ); + if ( ! is_string( $loading_value ) || empty( $loading_value ) ) { + $p->set_attribute( 'loading', 'lazy' ); + } + return $p->get_updated_html(); + + } elseif ( 'SCRIPT' === $p->get_tag() ) { + $oembed_lazy_load_scripts = true; + $p->set_attribute( 'data-lazy-embed-src', $p->get_attribute( 'src' ) ); + $p->set_attribute( 'src', '' ); + return $p->get_updated_html(); } } - $p = new WP_HTML_Tag_Processor( $html ); - if ( $p->next_tag( 'script' ) ) { - $oembed_lazy_load_scripts = true; - $p->set_attribute( 'data-lazy-embed-src', $p->get_attribute( 'src' ) ); - $p->set_attribute( 'src', '' ); - $html = $p->get_updated_html(); - } return $html; } From 3701f2d04048ac4445bdbb3aab134f2c45a50732 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Tue, 28 Nov 2023 11:29:25 -0700 Subject: [PATCH 11/28] remove extraneous is_string check --- modules/js-and-css/optimize-oembeds/hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index 6a6d8a302..67b89d6ac 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -32,7 +32,7 @@ function perflab_optimize_oembed_html( $html ) { while ( $p->next_tag() ) { if ( 'IFRAME' === $p->get_tag() ) { $loading_value = $p->get_attribute( 'loading' ); - if ( ! is_string( $loading_value ) || empty( $loading_value ) ) { + if ( empty( $loading_value ) ) { $p->set_attribute( 'loading', 'lazy' ); } return $p->get_updated_html(); From b96f6f6511efcdf2e37c602beab6801a71c6cfae Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 29 Nov 2023 09:09:55 -0700 Subject: [PATCH 12/28] add translations --- module-i18n.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/module-i18n.php b/module-i18n.php index 5270c77bf..6a7650784 100644 --- a/module-i18n.php +++ b/module-i18n.php @@ -9,6 +9,8 @@ _x( 'Creates WebP versions for new JPEG image uploads if supported by the server.', 'module description', 'performance-lab' ), _x( 'Enqueued Assets Health Check', 'module name', 'performance-lab' ), _x( 'Adds a CSS and JS resource check in Site Health status.', 'module description', 'performance-lab' ), + _x( 'oEmbed Optimizer', 'module name', 'performance-lab' ), + _x( 'Optimize oEmbed loading with improved lazy loading.', 'module description', 'performance-lab' ), _x( 'Autoloaded Options Health Check', 'module name', 'performance-lab' ), _x( 'Adds a check for autoloaded options in Site Health status.', 'module description', 'performance-lab' ), ); From 3fdfdc2f169bbf3c054bbfd7f34c78bd7bb2740a Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 15 Dec 2023 14:34:40 -0700 Subject: [PATCH 13/28] Update modules/js-and-css/optimize-oembeds/hooks.php Co-authored-by: Weston Ruter --- modules/js-and-css/optimize-oembeds/hooks.php | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index 67b89d6ac..e13b9ba38 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -62,30 +62,34 @@ function perflab_optimize_oembed_lazy_load_scripts() { return; } ?> - Date: Fri, 15 Dec 2023 14:35:16 -0700 Subject: [PATCH 14/28] Update modules/js-and-css/optimize-oembeds/hooks.php Co-authored-by: Weston Ruter --- modules/js-and-css/optimize-oembeds/hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index e13b9ba38..b6153d510 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -37,7 +37,7 @@ function perflab_optimize_oembed_html( $html ) { } return $p->get_updated_html(); - } elseif ( 'SCRIPT' === $p->get_tag() ) { + } elseif ( 'SCRIPT' === $p->get_tag() && $p->get_attribute( 'src' ) ) { $oembed_lazy_load_scripts = true; $p->set_attribute( 'data-lazy-embed-src', $p->get_attribute( 'src' ) ); $p->set_attribute( 'src', '' ); From 8f64e33f07b5ee4f861d6c811a85fa34dc5f46e7 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Tue, 23 Jan 2024 11:26:18 -0700 Subject: [PATCH 15/28] Update modules/js-and-css/optimize-oembeds/hooks.php Co-authored-by: Weston Ruter --- modules/js-and-css/optimize-oembeds/hooks.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index b6153d510..ee0e89044 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -72,8 +72,19 @@ function perflab_optimize_oembed_lazy_load_scripts() { if ( entry.isIntersecting ) { const lazyEmbedParent = entry.target; const lazyEmbedScript = lazyEmbedScriptsByParents.get( lazyEmbedParent ); - const embedScript = lazyEmbedScript.cloneNode(); - embedScript.src = lazyEmbedScript.dataset.lazyEmbedSrc; + const embedScript = document.createElement( 'script' ); + for ( const attr of lazyEmbedScript.attributes ) { + if ( attr.nodeName === 'src' ) { + // Even though the src attribute is absent, the browser seems to presume it is present. + continue; + } + + embedScript.setAttribute( + attr.nodeName === 'data-lazy-embed-src' ? 'src' : attr.nodeName, + attr.nodeValue + ); + } + lazyEmbedScript.replaceWith( embedScript ); lazyEmbedScript.replaceWith( embedScript ); lazyEmbedObserver.unobserve( lazyEmbedParent ); } From 3c0365845f38cdb9f0482c18ccf62b7f013e196d Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Tue, 23 Jan 2024 11:42:29 -0700 Subject: [PATCH 16/28] refine logic for iframe and script lazy loading --- modules/js-and-css/optimize-oembeds/hooks.php | 118 +++++++++++------- 1 file changed, 71 insertions(+), 47 deletions(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index ee0e89044..a86e18b1c 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -28,24 +28,48 @@ function perflab_optimize_oembed_html( $html ) { $p = new WP_HTML_Tag_Processor( $html ); - // Find the first iframe or script tag to act on. + /** + * Determine how to lazy load the embed. + * + * - If there is only one iframe, set loading="lazy". + * - Prevent making scripts lazy if there is an inline script. + * - Only make script lazy if there is a single external script (since if there are + * multiple they may not get loaded in the right order). + * - Ensure that both the iframe and the script are made lazy if both occur in the same embed. + */ + $iframe_count = 0; + $script_count = 0; + $has_inline_script = false; + // Locate the iframes and scripts. while ( $p->next_tag() ) { if ( 'IFRAME' === $p->get_tag() ) { $loading_value = $p->get_attribute( 'loading' ); if ( empty( $loading_value ) ) { - $p->set_attribute( 'loading', 'lazy' ); + ++$iframe_count; + $p->set_bookmark( 'iframe' ); + } + } elseif ( 'SCRIPT' === $p->get_tag() ) { + if ( ! $p->get_attribute( 'src' ) ) { + $has_inline_script = true; + } else { + ++$script_count; + $p->set_bookmark( 'script' ); } - return $p->get_updated_html(); - - } elseif ( 'SCRIPT' === $p->get_tag() && $p->get_attribute( 'src' ) ) { - $oembed_lazy_load_scripts = true; - $p->set_attribute( 'data-lazy-embed-src', $p->get_attribute( 'src' ) ); - $p->set_attribute( 'src', '' ); - return $p->get_updated_html(); } } - - return $html; + // If there was only one non-inline script, make it lazy. + if ( 1 === $script_count && ! $has_inline_script ) { + $oembed_lazy_load_scripts = true; + $p->seek( 'script' ); + $p->set_attribute( 'data-lazy-embed-src', $p->get_attribute( 'src' ) ); + $p->remove_attribute( 'src' ); + } + // If there was only one iframe, make it lazy. + if ( 1 === $iframe_count ) { + $p->seek( 'frame' ); + $p->set_attribute( 'loading', 'lazy' ); + } + return $p->get_updated_html(); } add_filter( 'embed_oembed_html', 'perflab_optimize_oembed_html', 10 ); @@ -63,44 +87,44 @@ function perflab_optimize_oembed_lazy_load_scripts() { } ?> Date: Tue, 23 Jan 2024 11:50:18 -0700 Subject: [PATCH 17/28] remove duplicate line --- modules/js-and-css/optimize-oembeds/hooks.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index a86e18b1c..add933d70 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -109,7 +109,6 @@ function perflab_optimize_oembed_lazy_load_scripts() { ); } lazyEmbedScript.replaceWith( embedScript ); - lazyEmbedScript.replaceWith( embedScript ); lazyEmbedObserver.unobserve( lazyEmbedParent ); } } From 5995820465adb62d7aa8c316dd35ddfcf1cba013 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 24 Jan 2024 07:32:38 -0700 Subject: [PATCH 18/28] Update modules/js-and-css/optimize-oembeds/hooks.php Co-authored-by: Weston Ruter --- modules/js-and-css/optimize-oembeds/hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index add933d70..cbff035d9 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -66,7 +66,7 @@ function perflab_optimize_oembed_html( $html ) { } // If there was only one iframe, make it lazy. if ( 1 === $iframe_count ) { - $p->seek( 'frame' ); + $p->seek( 'iframe' ); $p->set_attribute( 'loading', 'lazy' ); } return $p->get_updated_html(); From 1408cce23821d7a19430349183a378ea648152dc Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 24 Jan 2024 07:33:12 -0700 Subject: [PATCH 19/28] Update modules/js-and-css/optimize-oembeds/hooks.php Co-authored-by: Weston Ruter --- modules/js-and-css/optimize-oembeds/hooks.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index cbff035d9..cde22a778 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -10,8 +10,6 @@ exit; // Exit if accessed directly. } -$oembed_lazy_load_scripts = false; - /** * Filter the oEmbed HTML. * From 8a935a2562c4a80d31ffbb2f3fa31c7d611b693f Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 24 Jan 2024 07:33:22 -0700 Subject: [PATCH 20/28] Update modules/js-and-css/optimize-oembeds/hooks.php Co-authored-by: Weston Ruter --- modules/js-and-css/optimize-oembeds/hooks.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index cde22a778..7256c373d 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -22,8 +22,6 @@ * @return string */ function perflab_optimize_oembed_html( $html ) { - global $oembed_lazy_load_scripts; - $p = new WP_HTML_Tag_Processor( $html ); /** From 3b76392685f18c38ac345566eaa394c8c637c422 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 24 Jan 2024 11:50:48 -0700 Subject: [PATCH 21/28] Update modules/js-and-css/optimize-oembeds/hooks.php Co-authored-by: Weston Ruter --- modules/js-and-css/optimize-oembeds/hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index 7256c373d..df8550a7d 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -55,7 +55,7 @@ function perflab_optimize_oembed_html( $html ) { } // If there was only one non-inline script, make it lazy. if ( 1 === $script_count && ! $has_inline_script ) { - $oembed_lazy_load_scripts = true; + add_action( 'wp_footer', 'perflab_optimize_oembed_lazy_load_scripts' ); $p->seek( 'script' ); $p->set_attribute( 'data-lazy-embed-src', $p->get_attribute( 'src' ) ); $p->remove_attribute( 'src' ); From bbc8c4a9882b953939beb8c8b46f21ca36c937a1 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 24 Jan 2024 11:51:05 -0700 Subject: [PATCH 22/28] Update modules/js-and-css/optimize-oembeds/hooks.php Co-authored-by: Weston Ruter --- modules/js-and-css/optimize-oembeds/hooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index df8550a7d..d1d4ffe82 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -67,7 +67,7 @@ function perflab_optimize_oembed_html( $html ) { } return $p->get_updated_html(); } -add_filter( 'embed_oembed_html', 'perflab_optimize_oembed_html', 10 ); +add_filter( 'embed_oembed_html', 'perflab_optimize_oembed_html' ); /** * Add a script to the footer if there are lazy loaded embeds. From c5489be9027a7f4635fe06b00955e1ac2e2304c4 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 24 Jan 2024 11:51:29 -0700 Subject: [PATCH 23/28] Update modules/js-and-css/optimize-oembeds/hooks.php Co-authored-by: Weston Ruter --- modules/js-and-css/optimize-oembeds/hooks.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index d1d4ffe82..92d060618 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -122,5 +122,4 @@ function perflab_optimize_oembed_lazy_load_scripts() { } Date: Wed, 24 Jan 2024 11:51:41 -0700 Subject: [PATCH 24/28] Update modules/js-and-css/optimize-oembeds/hooks.php Co-authored-by: Weston Ruter --- modules/js-and-css/optimize-oembeds/hooks.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/js-and-css/optimize-oembeds/hooks.php b/modules/js-and-css/optimize-oembeds/hooks.php index 92d060618..e6a95bf2d 100644 --- a/modules/js-and-css/optimize-oembeds/hooks.php +++ b/modules/js-and-css/optimize-oembeds/hooks.php @@ -76,11 +76,6 @@ function perflab_optimize_oembed_html( $html ) { * @since n.e.x.t */ function perflab_optimize_oembed_lazy_load_scripts() { - global $oembed_lazy_load_scripts; - - if ( ! $oembed_lazy_load_scripts ) { - return; - } ?>