diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..33ec8f4
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,370 @@
+# LazyLoad Plugin – Lazy Load Images, Videos, and Iframes
+
+The best free lazy load plugin for WordPress. Lazy load images, videos, and iframes to improve performance and Core Web Vitals scores.
+[Download the plugin on wordpress.org](https://wordpress.org/plugins/rocket-lazy-load/).
+
+## Description
+
+LazyLoad is the best free lazy load plugin for WordPress to lazy load images, videos, and iframes on WordPress. In a nutshell, LazyLoad displays images, videos, and iframes on a page only when they are visible to the user – that’s one crucial way to [speed up your WordPress site](https://wp-rocket.me/blog/guide-to-page-speed-optimization-for-wordpress/) and [optimize images for Google PageSpeed](https://imagify.io/blog/optimize-images-page-speed-google/#lazy-loading).
+
+You can lazy load images in post content or widget text, plus thumbnails, avatars, and smilies. LazyLoad takes care of iframe lazy load, too: you’ll easily replace Youtube iframes with a preview thumbnail to further speed up the loading time of your website.
+
+No JavaScript library such as jQuery is used, and the script weight is less than 10KB.
+
+## Why is lazy loading crucial for performance?
+
+Lazy loading is a key performance technique to make your site faster. You’ll reduce loading time, [improve your Lighthouse performance score](https://wp-rocket.me/lighthouse-performance-score-wordpress/) and [optimize your Core Web Vitals grades](https://wp-rocket.me/google-core-web-vitals-wordpress/).
+
+[Lazy loading your images on WordPress](https://wp-rocket.me/blog/lazy-loading-wordpress-5-5/) will help you achieve a better PageSpeed Insights score for three main reasons:
+
+* You’ll address a specific PageSpeed Insights recommendation: [Defer offscreen images](https://wp-rocket.me/google-core-web-vitals-wordpress/defer-offscreen-images/, which means image lazy loading.
+* You’ll improve the performance of two key metrics: [First Input Delay](https://wp-rocket.me/google-core-web-vitals-wordpress/improve-first-input-delay/) (Core Web Vital) and [Total Blocking Time](https://wp-rocket.me/lighthouse-performance-score-wordpress/reduce-total-blocking-time/) (Lighthouse metric).
+* You’ll [make fewer HTTP requests](https://wp-rocket.me/blog/reduce-http-requests-speed-wordpress-site/) – that is another way to boost your site speed and [improve the Largest Contentful Paint score](https://wp-rocket.me/google-core-web-vitals-wordpress/improve-largest-contentful-paint/) (another Core Web Vital).
+
+Take a look at our complete list of reasons [why you should use lazy loading](https://wp-rocket.me/blog/lazyloading/#section-2). Then, turn on LazyLoad and make your WordPress website faster!
+
+
+## How to build the plugin
+
+In order to build the plugin you need have composer installed.
+
+Once it is the case you can follow these steps:
+- Download the zip from the plugin and unzip in a folder.
+- Move inside that folder and run the command `composer i` to install the full plugin and let the script installing protected dependencies run.
+- Run the command `composer i --no-dev --no-scripts -o` to install a production version from dependencies.
+- Zip back the folder and you have a working version from the plugin.
+
+## Dependencies
+
+LazyLoad script: [https://github.com/verlok/lazyload](https://github.com/verlok/lazyload)
+
+== Installation ==
+
+1. Upload the complete `rocket-lazy-load` folder to the `/wp-content/plugins/` directory
+2. Activate the plugin through the 'Plugins' menu in WordPress
+
+## Frequently Asked Questions
+
+### How can I use native lazyload?
+To use native lazyload on browsers supporting this feature, you need to use the following line:
+
+`add_filter( 'rocket_use_native_lazyload', '__return_true' );`
+
+Browsers that do not support native lazyload will use the JS-based solution as before.
+
+### How can I deactivate Lazy Load on some pages?
+
+You can use the `do_rocket_lazyload` filter.
+
+Here is an example to put in functions.php files that disable lazyload on posts:
+
+`
+add_action( 'wp', 'deactivate_rocket_lazyload_on_single' );
+function deactivate_rocket_lazyload_on_single() {
+if ( is_single() ) {
+add_filter( 'do_rocket_lazyload', '__return_false' );
+}
+}
+`
+
+### How can I deactivate Lazy Load on some images?
+
+Simply add a `data-no-lazy="1"` property in you `img` or `iframe` tag.
+
+You can also use the filters `rocket_lazyload_excluded_attributes` or `rocket_lazyload_excluded_src` to exclude specific patterns.
+
+For iframes, the filter is `rocket_lazyload_iframe_excluded_patterns`.
+
+### How can I change the threshold to trigger the load?
+
+You can use the `rocket_lazyload_threshold` filter.
+
+Code sample:
+
+`
+function rocket_lazyload_custom_threshold( $threshold ) {
+return 100;
+}
+add_filter( 'rocket_lazyload_threshold', 'rocket_lazyload_custom_threshold' );
+`
+
+### I use plugin X and my images don't show anymore
+
+Some plugins are not compatible without lazy loading. Please open a support thread, and we will see how we can solve the issue by excluding lazy loading for this plugin.
+
+### How can I lazy load a background-image?
+
+The plugin will automatically lazy load background-images set with a `style` attribute to a `div` element:
+
+``
+
+You can also apply it manually. The element you want to apply lazy load on must have this specific markup:
+
+`
`
+
+The element must have the class `rocket-lazyload`, and a `data-bg` attribute, which value is the CSS url for the image.
+
+### Where do I report security bugs found in this plugin?
+
+You can report any security bugs found in the source code of the site-reviews plugin through the [Patchstack Vulnerability Disclosure Program](https://patchstack.com/database/vdp/rocket-lazy-load). The Patchstack team will assist you with verification, CVE assignment and take care of notifying the developers of this plugin.
+
+### Related Plugins
+
+* [Imagify: The Best image optimizer](https://imagify.io/?utm_source=wordpress.org&utm_medium=referral&utm_campaign=LazyLoadPlugin) to speed up your website with lighter images.
+* [WP Rocket: Best performance plugin](https://wp-rocket.me/?utm_source=wordpress.org&utm_medium=referral&utm_campaign=LazyLoadPlugin) to speed up your WordPress website.
+* [Heartbeat Control by WP Rocket](https://wordpress.org/plugins/heartbeat-control/): Heartbeat Control by WP Rocket: The best plugin to control the WordPress Heartbeat API and reduce CPU usage.
+* [RocketCDN: The best CDN plugin for WordPress](https://rocketcdn.me/wordpress/) to propel your content at the speed of light – no matter where your users are located in the world.
+* [Increase Max upload file size](https://wordpress.org/plugins/upload-max-file-size/) is the best plugin to increase the upload file size limit to any value with one click.
+
+## Changelog
+= 2.3.8 =
+Enhancement: Launchpad compatibility (see https://github.com/wp-launchpad)
+Enhancement: Raised compatibility with PHP > 7.3
+Bug: Removed `wp-media/rocket-lazyload-common` from vendors
+Enhancement: Raised `wp-media/rocket-lazyload-common` to 3.0
+
+= 2.3.7 =
+Bugfix: Removed `rocket_lazyload_polyfill` filter due to a vulnerability on polyfill
+
+= 2.3.5 =
+Enhancement: Test the plugin with latest version of WordPress v5.9.3
+Enhancement: Change WP readme content.
+
+= 2.3.4 =
+Enhancement: Allow `
` tags to lazyload background images
+Enhancement: Add tag to lazyloaded picture elements
+Bugfix: Prevent a Fatal error related to the League Container package conflict with WooCommerce 4.4
+Bugfix: Update lazyload for background images support for new version of lazyload script
+Bugfix: Correctly apply the rocket-lazyload class on elements with a background-image and an empty class value
+Bugfix: Correctly apply the rocket-lazyloadclass on elements with malformed HTML
+Bugfix: Prevent a display issue with background-images when using different types of quotes around the URL
+Bugfix: Prevent Layout from breaking when alt attribute has any html encoded characters
+
+= 2.3.3 =
+Enhancement: Add data-skip-lazy and skip-lazy class to exclusions list as part of the interoperability initiative between lazyload plugins
+Enhancement: Use native lazyload only if filter `rocket_use_native_lazyload` is true
+Enhancement: Apply lazyload on background images set on `figure` elements
+Bugfix: Correctly add the rocket-lazyload class when class attribute is empty on an element with a background image
+Bugfix: Correctly replace YouTube iframe with preview image when using relative protocol
+Bugfix: Preserve youtube-nocookie.com during LazyLoad
+
+= 2.3.2 =
+Bugfix: Incorrect characters used in Youtube thumbnail HTML code
+
+= 2.3.1 =
+Bugfix: Prevent a conflict with WP Rocket
+Bugfix: apply loading="lazy" on Youtube thumbnail
+Bugfix: Add autoplay attribute on iframe loaded with Youtube thumbnail
+
+= 2.3 =
+Enhancement: Add support for browser native lazyload
+Bugfix: Prevent broken image in some cases for picture element
+Bugfix: Prevent wrong lazy attributes for srcset and sizes on an image inside a picture element
+
+= 2.2.3 =
+* Enhancement: Improve compatibility for the picture element
+* Enhancement: Apply lazyload on background images set on section, span and li elements
+* Enhancement: also pass $width and $height values to the rocket_lazyload_placeholder filter
+* Bugfix: Use 0 instead of 1 for the default placeholder dimensions to improve compatibility
+* Bugfix: Improve infinite scroll support
+* Bugfix: Exclude Enfold avia-background-fixed background images and data-large_image from lazyload
+
+= 2.2.2 =
+* Bugfix: Auto-exclude data-height-percentage attribute to prevent display issues
+* Bugfix: Correctly handle responsive videos using fitVids again
+
+= 2.2.1 =
+* Enhancement: add a way to customize the lazyload script options
+* Bugfix: Prevent error on Internet Explorer 11
+* Bugfix: Prevent conflict with WooCommerce variation swatches
+* Bugfix: Prevent empty `src` when the image is an inline base64
+* Bugfix: Prevent issue when the original `src` attribute uses single quotes
+
+= 2.2 =
+* Enhancement: Update lazyload script to the latest version
+* Enhancement: Use the dimensions of the original image for the placeholder size when possible, to reduce content reflow
+* Enhancement: Ignore images using the new loading attribute introduce by Chrome for browser-native lazyload
+
+= 2.1.5 =
+* Bugfix: Prevent matching with the wrong data when a data-style attribute is on a div for background images
+* Remove data-cfasync="false" by default
+* Enhancement: Add filter rocket_lazyload_script_tag to modify the lazyload script HTML if needed
+* Enhancement: Add data-no-minify attribute to the lazyload script tag to prevent it from being combined by JS combiners
+* Enhancement: Improve MutationObserver code to only call the lazyload update method if an image/iframe or element with .rocket-lazyload is contained in the new node(s) added to the DOM
+
+= 2.1.4 =
+* Regression fix: Correctly exclude scripts from lazyload again
+
+= 2.1.3 =
+* Bugfix: Ignore content inside noscript tags to prevent modifying them and causing some display issues
+
+= 2.1.2 =
+* Enhancement: Update lazyload script to the latest version
+* Enhancement: Add a way to lazyload the Youtube thumbnail image
+* Enhancement: Add width and height attributes to the Youtube thumbnail image depending on the resolution
+* Enhancement: Disable polyfill for intersectionObserver by default, added a way to activate it instead
+* Enhancement: Add data-cfasync="false" to the lazyload script tag
+* Enhancement: Prevent lazyload on the Oxygen Builder page editor
+* Bugfix: Wrap no JS CSS in noscript tag and remove the no-js identifier
+
+
+= 2.1.1 =
+* Bugfix: Correctly apply lazyload on `picture` elements
+* Bugfix: Prevent double loading of an image when an `img` element inside a `picture` element only has a `srcset` attribute and no `src` attribute
+
+= 2.1 =
+* Enhancement: Update lazyload script to the latest version
+* Enhancement: Apply lazyload on picture elements found on the page
+* Enhancement: Apply lazyload on div elements with a background image found on the page. See FAQ for more info.
+
+= 2.0.4 =
+* Enhancement: Add filter for iframe lazyload pattern exclusion
+* Enhancement: Auto-exclude soliloquy-image pattern from lazyload
+* Bugfix: Prevent issue when an image/iframe is duplicated on the same page
+* Bugfix: Prevent W3C validation error for the SVG placeholder
+
+= 2.0.3.2 =
+* Bugfix: Correctly ignore inline scripts with line breaks inside
+
+= 2.0.3.1 =
+* Bugfix: Correct an issue preventing lazyload from working
+
+= 2.0.3 =
+* Bugfix: Prevent incorrect display if JavaScript is disabled
+* Bugfix: Don't apply lazyload on Divi/Extra/Beaver Builder Editor pages
+* Bugfix: Use the correct URL for each iframe when multiple iframes are on the same page
+* Bugfix: Ignore content inside inline script tags to prevent applying lazyload in it
+
+= 2.0.2 =
+* Bugfix: Fix an error in the compatibility for the AMP plugin
+
+= 2.0.1 =
+* Bugfix: Prevent a fatal error on case sensitive operating systems
+
+= 2.0 =
+* Enhancement: Lazyload is now applied on the template_redirect hook, which should allow the plugin to apply the optimization on more images and encountering less conflicts at the same time
+* Enhancement: Specifically target with the lazyload script images/iframes elements with a data-lazy-src attribute
+* Enhancement: Update lazyload script to the latest version
+* Enhancement: Possibility to apply lazyload on background-images with a specific markup, see FAQ
+* Enhancement: Use a svg image as placeholder instead of a base64 gif
+* Bugfix: Only use MutationObserver if available in the browser
+* Bugfix: When using the Youtube thumbnail option, correctly format the Youtube query if the video URL is encoded
+* Bugfix: Improve iframe matching to prevent unexpected results
+* Bugfix: Update CSS for the Youtube thumbnail option to prevent issue with the Gutenberg embeds block
+
+= 1.4.9 =
+* Enhancement: Update lazyload script to the latest available version
+* Enhancement: Use lazy-sizes to prevent W3C validation error when sizes is defined but srcset is not
+* Enhancement: Parse images or iframes only if the element is selected to be lazyloaded in the options
+* Fix: Prevent warning for lazyload+v in Google Search Console
+* Fix: Prevent PHP Notice with WooCommerce for product images
+
+= 1.4.8 =
+* Notice: Minimum WordPress version required is now 4.7
+* Enhancement: Update lazyload script version
+* Enhancement: Remove placeholder image to improve perceived loading time
+* Enhancement: Compatibility with Youtube privacy URL
+* Enhancement: Update play image to match Youtube logo
+* Enhancement: Support Youtube URL parameters
+* Enhancement: Lazyload images displayed with wp_get_attachment_image(). /!\ no fallback if JavaScript is disabled
+* Fix: Use the correct size set in srcset for the lazyloaded image
+* Fix: Prevent Youtube thumbnail replacement on playlists
+* Fix: Prevent iframe lazyload on AMP pages
+* Fix: Correct text domain for translations (thanks @ Chantal Coolsma)
+
+= 1.4.7 =
+* Fix compatibility with infinite scroll
+* Prevent lazyload on masterSlider images
+
+= 1.4.6 =
+* Correctly include version 8.5.2 of lazyload script
+* Prevent 404 error on lazyload script if URL contains "-v"
+
+= 1.4.5 =
+* Rename Setting Page Name in WP Menu
+* New Product Banner in Settings Page
+* Conditionally load a different version of the script depending on browser support of IntersectionObserver
+* Fix a bug where images initially hidden are not correctly displayed when coming into view (slider, tabs, accordion)
+
+= 1.4.4 =
+* Admin Redesign
+
+= 1.4.3 =
+* Plugin is compatible again with PHP < 5.4
+
+= 1.4.2 =
+* Update lazyload script to bring back compatibility with IE9/10
+
+= 1.4.1 =
+* Fix bug caused by a too aggressive cleanup
+
+= 1.4 =
+* New option: replace Youtube videos by thumbnail. This option can improve your loading time a lot, especially if you have multiple videos on the same page
+
+= 1.3.3 =
+* 2017-09-16
+* Prevent scripts and styles being removed during html parsing
+
+= 1.3.2 =
+* 2017-09-12
+* Fix images not displaying in certain conditions because image attributes exclusion was not working correctly
+
+= 1.3.1 =
+* 2017-09-07
+* Don't apply lazyload on Divi slider
+
+= 1.3 =
+* 2017-09-01
+* Improve HTML parsing of images and iframes to be faster and more efficient
+* Make the lazyload compatible with fitVids for iframes
+* Don't apply lazyload on AMP pages (compatible with AMP plugin from Automattic)
+* Use about:blank as default iframe placeholder to prevent warning in browser console
+* Don't apply lazyload on upPrev thumbnail
+
+= 1.2.1 =
+* 2017-08-22
+* Fix missing lazyload script
+* Don't lazyload for images in REST API requests
+
+= 1.2 =
+* 2017-08-22
+* Update lazyload script to latest version
+* Change the way the script is loaded
+
+= 1.1.1 =
+* 2017-02-13
+* Bug fix: Remove use of short tag to prevent 500 error on some installations
+
+= 1.1 =
+* 2017-02-12
+* *New*
+* JS library updated
+* Support for iFrame
+* Support for srcset and sizes
+* New options page
+
+= 1.0.4 =
+* 2015-04-28
+* Bug Fix: Resolved a conflict between LazyLoad & Emoji since WordPress 4.2
+
+= 1.0.3 =
+* 2015-01-08
+* Bug Fix: Don't apply LazyLoad on captcha from Really Simple CAPTCHA to prevent conflicts.
+
+= 1.0.2 =
+* 2014-12-28
+* Improvement: Add « rocket_lazyload_html » filter to manage the output that will be printed.
+
+= 1.0.1.1 =
+* 2014-07-25
+* Fix stupid error with new regex in 1.0.1
+
+= 1.0.1 =
+* 2014-07-16
+* Bug Fix: when a IMG tag or content (widget or post) contains the string "data-no-lazy", all IMG tags were ignored instead of one.
+* Security fix: The preg_replace() could lead to a XSS vuln, thanks to Alexander Concha
+* Code compliance
+
+= 1.0 =
+* 2014-01-01
+* Initial release.
diff --git a/readme.txt b/readme.txt
index ae09558..ca75363 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,10 +1,10 @@
=== LazyLoad Plugin – Lazy Load Images, Videos, and Iframes ===
Contributors: wp_rocket, wp_media
Tags: lazyload, lazy load, images, iframes, thumbnail, thumbnails, smiley, smilies, avatar, gravatar, youtube
-Requires at least: 4.7
-Tested up to: 6.3
-Requires PHP: 5.6
-Stable tag: 2.3.7
+Requires at least: 4.9
+Tested up to: 6.5
+Requires PHP: 7.3
+Stable tag: 2.3.8
Tags: lazy load, lazy loading, defer offscreen images, lazy load plugin, lazy load images, image lazy loading, iframe lazy load, video lazy load
The best free lazy load plugin for WordPress. Lazy load images, videos, and iframes to improve performance and Core Web Vitals scores.
@@ -100,8 +100,8 @@ You can also apply it manually. The element you want to apply lazy load on must
The element must have the class `rocket-lazyload`, and a `data-bg` attribute, which value is the CSS url for the image.
-= Where do I report security bugs found in this plugin? =
-
+= Where do I report security bugs found in this plugin? =
+
You can report any security bugs found in the source code of the site-reviews plugin through the [Patchstack Vulnerability Disclosure Program](https://patchstack.com/database/vdp/rocket-lazy-load). The Patchstack team will assist you with verification, CVE assignment and take care of notifying the developers of this plugin.
= Related Plugins =
@@ -113,6 +113,12 @@ You can report any security bugs found in the source code of the site-reviews pl
* [Increase Max upload file size](https://wordpress.org/plugins/upload-max-file-size/) is the best plugin to increase the upload file size limit to any value with one click.
== Changelog ==
+= 2.3.8 =
+Enhancement: Launchpad compatibility (see https://github.com/wp-launchpad)
+Enhancement: Raised compatibility with PHP > 7.3
+Bug: Removed `wp-media/rocket-lazyload-common` from vendors
+Enhancement: Raised `wp-media/rocket-lazyload-common` to 3.0
+
= 2.3.7 =
Bugfix: Removed `rocket_lazyload_polyfill` filter due to a vulnerability on polyfill
diff --git a/rocket-lazy-load.php b/rocket-lazy-load.php
index 4e64922..6ef23b7 100644
--- a/rocket-lazy-load.php
+++ b/rocket-lazy-load.php
@@ -3,8 +3,9 @@
* Plugin Name: Lazy Load - Optimize Images
* Plugin URI: http://wordpress.org/plugins/rocket-lazy-load/
* Description: The tiny Lazy Load script for WordPress without jQuery or others libraries.
- * Version: 2.3.7
- * Requires PHP: 5.6
+ * Version: 2.3.8
+ * Requires at least: 4.9
+ * Requires PHP: 7.3
* Author: WP Rocket
* Author URI: https://wp-rocket.me
* Text Domain: rocket-lazy-load
@@ -12,7 +13,7 @@
*
* @package RocketLazyloadPlugin
*
- * Copyright 2015-2019 WP Media
+ * Copyright 2015-2024 WP Media
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -30,37 +31,18 @@
defined( 'ABSPATH' ) || die( 'Cheatin\' uh?' );
-define( 'ROCKET_LL_VERSION', '2.3.7' );
+define( 'ROCKET_LL_VERSION', '2.3.8' );
define( 'ROCKET_LL_WP_VERSION', '4.9' );
-define( 'ROCKET_LL_PHP_VERSION', '5.6' );
+define( 'ROCKET_LL_PHP_VERSION', '7.3' );
define( 'ROCKET_LL_BASENAME', plugin_basename( __FILE__ ) );
define( 'ROCKET_LL_PATH', realpath( plugin_dir_path( __FILE__ ) ) . '/' );
define( 'ROCKET_LL_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets/' );
define( 'ROCKET_LL_FRONT_JS_URL', ROCKET_LL_ASSETS_URL . 'js/' );
define( 'ROCKET_LL_INT_MAX', PHP_INT_MAX - 15 );
-require ROCKET_LL_PATH . 'src/rocket-lazyload-requirements-check.php';
+use function RocketLazyLoadPlugin\Dependencies\LaunchpadCore\boot;
-/**
- * Loads plugin translations
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return void
- */
-function rocket_lazyload_textdomain() {
- // Load translations from the languages directory.
- $locale = get_locale();
-
- // This filter is documented in /wp-includes/l10n.php.
- $locale = apply_filters( 'plugin_locale', $locale, 'rocket-lazy-load' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
- load_textdomain( 'rocket-lazy-load', WP_LANG_DIR . '/plugins/rocket-lazy-load-' . $locale . '.mo' );
-
- load_plugin_textdomain( 'rocket-lazy-load', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
-}
-
-add_action( 'plugins_loaded', 'rocket_lazyload_textdomain' );
+require ROCKET_LL_PATH . 'includes/RocketLazyloadRequirementsCheck.php';
$rocket_lazyload_requirement_checks = new Rocket_Lazyload_Requirements_Check(
[
@@ -72,7 +54,10 @@ function rocket_lazyload_textdomain() {
);
if ( $rocket_lazyload_requirement_checks->check() ) {
- require ROCKET_LL_PATH . 'main.php';
+ require __DIR__ . '/src/Dependencies/LaunchpadCore/boot.php';
+
+ boot( __FILE__ );
}
+
unset( $rocket_lazyload_requirement_checks );
diff --git a/src/Admin/AdminPage.php b/src/Admin/AdminPage.php
index 79d3294..aa484f0 100644
--- a/src/Admin/AdminPage.php
+++ b/src/Admin/AdminPage.php
@@ -7,10 +7,11 @@
namespace RocketLazyLoadPlugin\Admin;
-defined('ABSPATH') || die('Cheatin\' uh?');
+defined( 'ABSPATH' ) || die( 'Cheatin\' uh?' );
+
+use RocketLazyLoadPlugin\Dependencies\LaunchpadFrameworkOptions\Interfaces\SettingsAwareInterface;
+use RocketLazyLoadPlugin\Dependencies\LaunchpadFrameworkOptions\Traits\SettingsAwareTrait;
-use RocketLazyLoadPlugin\Options\Options;
-use RocketLazyLoadPlugin\Options\OptionArray;
/**
* Admin page configuration
@@ -18,159 +19,130 @@
* @since 2.0
* @author Remy Perona
*/
-class AdminPage
-{
- /**
- * Plugin slug
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @var string
- */
- private $slug = 'rocket_lazyload';
-
- /**
- * Options instance
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @var Options
- */
- private $options;
-
- /**
- * OptionArray instance
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @var OptionArray
- */
- private $option_array;
-
- /**
- * Template path
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @var string
- */
- private $template_path;
-
- /**
- * Constructor
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @param Options $options Options instance.
- * @param OptionArray $option_array OptionArray instance.
- * @param string $template_path Template path.
- */
- public function __construct(Options $options, OptionArray $option_array, $template_path)
- {
- $this->options = $options;
- $this->option_array = $option_array;
- $this->template_path = $template_path;
- }
-
- /**
- * Registers plugin settings with WordPress
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return void
- */
- public function configure()
- {
- register_setting($this->getSlug(), $this->options->getOptionName('_options'));
- }
-
- /**
- * Gets the settings page title
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return string
- */
- public function getPageTitle()
- {
- return __('LazyLoad by WP Rocket', 'rocket-lazy-load');
- }
-
- /**
- * Gets the settings submenu title
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return string
- */
- public function getMenuTitle()
- {
- return __('LazyLoad', 'rocket-lazy-load');
- }
-
- /**
- * Gets the plugin slug
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return string
- */
- public function getSlug()
- {
- return $this->slug;
- }
-
- /**
- * Gets the plugin required capability
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return string
- */
- public function getCapability()
- {
- return 'manage_options';
- }
-
- /**
- * Renders the admin page template
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return void
- */
- public function renderPage()
- {
- $this->renderTemplate('admin-page');
- }
-
- /**
- * Renders the given template if it's readable.
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @param string $template Template name.
- */
- protected function renderTemplate($template)
- {
- $template_path = $this->template_path . $template . '.php';
-
- if (! is_readable($template_path)) {
- return;
- }
-
- include $template_path;
- }
+class AdminPage implements SettingsAwareInterface {
+ use SettingsAwareTrait;
+
+ /**
+ * Plugin slug
+ *
+ * @since 2.0
+ * @author Remy Perona
+ *
+ * @var string
+ */
+ private $slug = 'rocket_lazyload';
+
+ /**
+ * Template path
+ *
+ * @since 2.0
+ * @author Remy Perona
+ *
+ * @var string
+ */
+ private $template_path;
+
+ /**
+ * Constructor
+ *
+ * @param string $template_path Template path.
+ *
+ * @author Remy Perona
+ *
+ * @since 2.0
+ */
+ public function __construct( string $template_path ) {
+ $this->template_path = $template_path;
+ }
+
+ /**
+ * Registers plugin settings with WordPress
+ *
+ * @return void
+ * @author Remy Perona
+ *
+ * @since 2.0
+ */
+ public function configure() {
+ register_setting( $this->getSlug(), $this->getSlug() . '_options' );
+ }
+
+ /**
+ * Gets the settings page title
+ *
+ * @return string
+ * @author Remy Perona
+ *
+ * @since 2.0
+ */
+ public function getPageTitle() {
+ return __( 'LazyLoad by WP Rocket', 'rocket-lazy-load' );
+ }
+
+ /**
+ * Gets the settings submenu title
+ *
+ * @return string
+ * @author Remy Perona
+ *
+ * @since 2.0
+ */
+ public function getMenuTitle() {
+ return __( 'LazyLoad', 'rocket-lazy-load' );
+ }
+
+ /**
+ * Gets the plugin slug
+ *
+ * @return string
+ * @author Remy Perona
+ *
+ * @since 2.0
+ */
+ public function getSlug() {
+ return $this->slug;
+ }
+
+ /**
+ * Gets the plugin required capability
+ *
+ * @return string
+ * @author Remy Perona
+ *
+ * @since 2.0
+ */
+ public function getCapability() {
+ return 'manage_options';
+ }
+
+ /**
+ * Renders the admin page template
+ *
+ * @return void
+ * @author Remy Perona
+ *
+ * @since 2.0
+ */
+ public function renderPage() {
+ $this->renderTemplate( 'admin-page' );
+ }
+
+ /**
+ * Renders the given template if it's readable.
+ *
+ * @param string $template Template name.
+ *
+ * @author Remy Perona
+ *
+ * @since 2.0
+ */
+ protected function renderTemplate( $template ) {
+ $template_path = $this->template_path . $template . '.php';
+
+ if ( ! is_readable( $template_path ) ) {
+ return;
+ }
+
+ include $template_path;
+ }
}
diff --git a/src/Admin/ImagifyNotice.php b/src/Admin/ImagifyNotice.php
index f563ab9..26c6136 100644
--- a/src/Admin/ImagifyNotice.php
+++ b/src/Admin/ImagifyNotice.php
@@ -13,60 +13,58 @@
* @since 2.0
* @author Remy Perona
*/
-class ImagifyNotice
-{
- /**
- * Template path
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @var string
- */
- private $template_path;
+class ImagifyNotice {
+ /**
+ * Template path
+ *
+ * @since 2.0
+ * @author Remy Perona
+ *
+ * @var string
+ */
+ private $template_path;
- /**
- * Constructor
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @param string $template_path Template path.
- */
- public function __construct($template_path)
- {
- $this->template_path = $template_path;
- }
+ /**
+ * Constructor
+ *
+ * @param string $template_path Template path.
+ *
+ * @author Remy Perona
+ *
+ * @since 2.0
+ */
+ public function __construct( $template_path ) {
+ $this->template_path = $template_path;
+ }
- /**
- * Renders the Imagify notice
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return void
- */
- public function displayNotice()
- {
- $this->renderTemplate('imagify-notice');
- }
+ /**
+ * Renders the Imagify notice
+ *
+ * @return void
+ * @author Remy Perona
+ *
+ * @since 2.0
+ */
+ public function displayNotice() {
+ $this->renderTemplate( 'imagify-notice' );
+ }
- /**
- * Renders the given template if it's readable.
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @param string $template Template name.
- */
- protected function renderTemplate($template)
- {
- $template_path = $this->template_path . $template . '.php';
+ /**
+ * Renders the given template if it's readable.
+ *
+ * @param string $template Template name.
+ *
+ * @author Remy Perona
+ *
+ * @since 2.0
+ */
+ protected function renderTemplate( $template ) {
+ $template_path = $this->template_path . $template . '.php';
- if (! is_readable($template_path)) {
- return;
- }
+ if ( ! is_readable( $template_path ) ) {
+ return;
+ }
- include $template_path;
- }
+ include $template_path;
+ }
}
diff --git a/src/Dependencies/League/Container/Argument/ArgumentResolverInterface.php b/src/Dependencies/League/Container/Argument/ArgumentResolverInterface.php
index b449386..74041a8 100644
--- a/src/Dependencies/League/Container/Argument/ArgumentResolverInterface.php
+++ b/src/Dependencies/League/Container/Argument/ArgumentResolverInterface.php
@@ -1,26 +1,28 @@
-getValue();
- continue;
+ return array_map(function ($argument) {
+ $justStringValue = false;
+
+ if ($argument instanceof RawArgumentInterface) {
+ return $argument->getValue();
+ } elseif ($argument instanceof ClassNameInterface) {
+ $id = $argument->getClassName();
+ } elseif (!is_string($argument)) {
+ return $argument;
+ } else {
+ $justStringValue = true;
+ $id = $argument;
}
- if (! is_string($arg)) {
- continue;
- }
-
- $container = $this->getContainer();
+ $container = null;
- if (is_null($container) && $this instanceof ReflectionContainer) {
- $container = $this;
+ try {
+ $container = $this->getLeagueContainer();
+ } catch (ContainerException $e) {
+ if ($this instanceof ReflectionContainer) {
+ $container = $this;
+ }
}
- if (! is_null($container) && $container->has($arg)) {
- $arg = $container->get($arg);
+ if ($container !== null) {
+ try {
+ return $container->get($id);
+ } catch (NotFoundException $exception) {
+ if ($argument instanceof ClassNameWithOptionalValue) {
+ return $argument->getOptionalValue();
+ }
+
+ if ($justStringValue) {
+ return $id;
+ }
- if ($arg instanceof RawArgumentInterface) {
- $arg = $arg->getValue();
+ throw $exception;
}
+ }
- continue;
+ if ($argument instanceof ClassNameWithOptionalValue) {
+ return $argument->getOptionalValue();
}
- }
- return $arguments;
+ // Just a string value.
+ return $id;
+ }, $arguments);
}
/**
* {@inheritdoc}
*/
- public function reflectArguments(ReflectionFunctionAbstract $method, array $args = [])
+ public function reflectArguments(ReflectionFunctionAbstract $method, array $args = []) : array
{
$arguments = array_map(function (ReflectionParameter $param) use ($method, $args) {
- $name = $param->getName();
- $class = $param->getClass();
+ $name = $param->getName();
+ $type = $param->getType();
if (array_key_exists($name, $args)) {
- return $args[$name];
+ return new RawArgument($args[$name]);
}
- if (! is_null($class)) {
- return $class->getName();
+ if ($type) {
+ if (PHP_VERSION_ID >= 70100) {
+ $typeName = $type->getName();
+ } else {
+ $typeName = (string) $type;
+ }
+
+ $typeName = ltrim($typeName, '?');
+
+ if ($param->isDefaultValueAvailable()) {
+ return new ClassNameWithOptionalValue($typeName, $param->getDefaultValue());
+ }
+
+ return new ClassName($typeName);
}
if ($param->isDefaultValueAvailable()) {
- return $param->getDefaultValue();
+ return new RawArgument($param->getDefaultValue());
}
throw new NotFoundException(sprintf(
@@ -76,7 +109,12 @@ public function reflectArguments(ReflectionFunctionAbstract $method, array $args
}
/**
- * @return \RocketLazyLoadPlugin\Dependencies\League\Container\ContainerInterface
+ * @return ContainerInterface
+ */
+ abstract public function getContainer() : ContainerInterface;
+
+ /**
+ * @return Container
*/
- abstract public function getContainer();
+ abstract public function getLeagueContainer() : Container;
}
diff --git a/src/Dependencies/League/Container/Argument/RawArgument.php b/src/Dependencies/League/Container/Argument/RawArgument.php
index 128cf1b..f61fcbd 100644
--- a/src/Dependencies/League/Container/Argument/RawArgument.php
+++ b/src/Dependencies/League/Container/Argument/RawArgument.php
@@ -1,4 +1,4 @@
-providers = (is_null($providers))
- ? (new ServiceProviderAggregate)->setContainer($this)
- : $providers->setContainer($this);
-
- $this->inflectors = (is_null($inflectors))
- ? (new InflectorAggregate)->setContainer($this)
- : $inflectors->setContainer($this);
-
- $this->definitionFactory = (is_null($definitionFactory))
- ? (new DefinitionFactory)->setContainer($this)
- : $definitionFactory->setContainer($this);
- }
-
- /**
- * {@inheritdoc}
- */
- public function get($alias, array $args = [])
- {
- try {
- return $this->getFromThisContainer($alias, $args);
- } catch (NotFoundException $exception) {
- if ($this->providers->provides($alias)) {
- $this->providers->register($alias);
+ $this->definitions = $definitions ?? new DefinitionAggregate;
+ $this->providers = $providers ?? new ServiceProviderAggregate;
+ $this->inflectors = $inflectors ?? new InflectorAggregate;
- return $this->getFromThisContainer($alias, $args);
- }
+ if ($this->definitions instanceof ContainerAwareInterface) {
+ $this->definitions->setLeagueContainer($this);
+ }
- $resolved = $this->getFromDelegate($alias, $args);
+ if ($this->providers instanceof ContainerAwareInterface) {
+ $this->providers->setLeagueContainer($this);
+ }
- return $this->inflectors->inflect($resolved);
+ if ($this->inflectors instanceof ContainerAwareInterface) {
+ $this->inflectors->setLeagueContainer($this);
}
}
/**
- * {@inheritdoc}
+ * Add an item to the container.
+ *
+ * @param string $id
+ * @param mixed $concrete
+ * @param boolean $shared
+ *
+ * @return DefinitionInterface
*/
- public function has($alias)
+ public function add(string $id, $concrete = null, bool $shared = null) : DefinitionInterface
{
- if (array_key_exists($alias, $this->definitions) || $this->hasShared($alias)) {
- return true;
- }
-
- if ($this->providers->provides($alias)) {
- return true;
- }
+ $concrete = $concrete ?? $id;
+ $shared = $shared ?? $this->defaultToShared;
- return $this->hasInDelegate($alias);
+ return $this->definitions->add($id, $concrete, $shared);
}
/**
- * Returns a boolean to determine if the container has a shared instance of an alias.
+ * Proxy to add with shared as true.
+ *
+ * @param string $id
+ * @param mixed $concrete
*
- * @param string $alias
- * @param boolean $resolved
- * @return boolean
+ * @return DefinitionInterface
*/
- public function hasShared($alias, $resolved = false)
+ public function share(string $id, $concrete = null) : DefinitionInterface
{
- $shared = ($resolved === false) ? array_merge($this->shared, $this->sharedDefinitions) : $this->shared;
-
- return (array_key_exists($alias, $shared));
+ return $this->add($id, $concrete, true);
}
/**
- * {@inheritdoc}
+ * Whether the container should default to defining shared definitions.
+ *
+ * @param boolean $shared
+ *
+ * @return self
*/
- public function add($alias, $concrete = null, $share = false)
+ public function defaultToShared(bool $shared = true) : ContainerInterface
{
- unset($this->shared[$alias]);
- unset($this->definitions[$alias]);
- unset($this->sharedDefinitions[$alias]);
-
- if (is_null($concrete)) {
- $concrete = $alias;
- }
-
- $definition = $this->definitionFactory->getDefinition($alias, $concrete);
+ $this->defaultToShared = $shared;
- if ($definition instanceof DefinitionInterface) {
- if ($share === false) {
- $this->definitions[$alias] = $definition;
- } else {
- $this->sharedDefinitions[$alias] = $definition;
- }
-
- return $definition;
- }
-
- // dealing with a value that cannot build a definition
- $this->shared[$alias] = $concrete;
+ return $this;
}
/**
- * {@inheritdoc}
+ * Get a definition to extend.
+ *
+ * @param string $id [description]
+ *
+ * @return DefinitionInterface
*/
- public function share($alias, $concrete = null)
+ public function extend(string $id) : DefinitionInterface
{
- return $this->add($alias, $concrete, true);
+ if ($this->providers->provides($id)) {
+ $this->providers->register($id);
+ }
+
+ if ($this->definitions->has($id)) {
+ return $this->definitions->getDefinition($id);
+ }
+
+ throw new NotFoundException(
+ sprintf('Unable to extend alias (%s) as it is not being managed as a definition', $id)
+ );
}
/**
- * {@inheritdoc}
+ * Add a service provider.
+ *
+ * @param ServiceProviderInterface|string $provider
+ *
+ * @return self
*/
- public function addServiceProvider($provider)
+ public function addServiceProvider($provider) : self
{
$this->providers->add($provider);
@@ -176,69 +151,62 @@ public function addServiceProvider($provider)
/**
* {@inheritdoc}
*/
- public function extend($alias)
+ public function get($id, bool $new = false)
{
- if ($this->providers->provides($alias)) {
- $this->providers->register($alias);
+ if ($this->definitions->has($id)) {
+ $resolved = $this->definitions->resolve($id, $new);
+ return $this->inflectors->inflect($resolved);
}
- if (array_key_exists($alias, $this->definitions)) {
- return $this->definitions[$alias];
+ if ($this->definitions->hasTag($id)) {
+ $arrayOf = $this->definitions->resolveTagged($id, $new);
+
+ array_walk($arrayOf, function (&$resolved) {
+ $resolved = $this->inflectors->inflect($resolved);
+ });
+
+ return $arrayOf;
}
- if (array_key_exists($alias, $this->sharedDefinitions)) {
- return $this->sharedDefinitions[$alias];
+ if ($this->providers->provides($id)) {
+ $this->providers->register($id);
+
+ if (!$this->definitions->has($id) && !$this->definitions->hasTag($id)) {
+ throw new ContainerException(sprintf('Service provider lied about providing (%s) service', $id));
+ }
+
+ return $this->get($id, $new);
}
- throw new NotFoundException(
- sprintf('Unable to extend alias (%s) as it is not being managed as a definition', $alias)
- );
- }
+ foreach ($this->delegates as $delegate) {
+ if ($delegate->has($id)) {
+ $resolved = $delegate->get($id);
+ return $this->inflectors->inflect($resolved);
+ }
+ }
- /**
- * {@inheritdoc}
- */
- public function inflector($type, callable $callback = null)
- {
- return $this->inflectors->add($type, $callback);
+ throw new NotFoundException(sprintf('Alias (%s) is not being managed by the container or delegates', $id));
}
/**
* {@inheritdoc}
*/
- public function call(callable $callable, array $args = [])
+ public function has($id)
{
- return (new ReflectionContainer)->setContainer($this)->call($callable, $args);
- }
-
- /**
- * Delegate a backup container to be checked for services if it
- * cannot be resolved via this container.
- *
- * @param \RocketLazyLoadPlugin\Dependencies\Interop\Container\ContainerInterface $container
- * @return $this
- */
- public function delegate(InteropContainerInterface $container)
- {
- $this->delegates[] = $container;
+ if ($this->definitions->has($id)) {
+ return true;
+ }
- if ($container instanceof ImmutableContainerAwareInterface) {
- $container->setContainer($this);
+ if ($this->definitions->hasTag($id)) {
+ return true;
}
- return $this;
- }
+ if ($this->providers->provides($id)) {
+ return true;
+ }
- /**
- * Returns true if service is registered in one of the delegated backup containers.
- *
- * @param string $alias
- * @return boolean
- */
- public function hasInDelegate($alias)
- {
- foreach ($this->delegates as $container) {
- if ($container->has($alias)) {
+ foreach ($this->delegates as $delegate) {
+ if ($delegate->has($id)) {
return true;
}
}
@@ -247,59 +215,34 @@ public function hasInDelegate($alias)
}
/**
- * Attempt to get a service from the stack of delegated backup containers.
+ * Allows for manipulation of specific types on resolution.
+ *
+ * @param string $type
+ * @param callable|null $callback
*
- * @param string $alias
- * @param array $args
- * @return mixed
+ * @return InflectorInterface
*/
- protected function getFromDelegate($alias, array $args = [])
+ public function inflector(string $type, callable $callback = null) : InflectorInterface
{
- foreach ($this->delegates as $container) {
- if ($container->has($alias)) {
- return $container->get($alias, $args);
- }
-
- continue;
- }
-
- throw new NotFoundException(
- sprintf('Alias (%s) is not being managed by the container', $alias)
- );
-
+ return $this->inflectors->add($type, $callback);
}
/**
- * Get a service that has been registered in this container.
+ * Delegate a backup container to be checked for services if it
+ * cannot be resolved via this container.
*
- * @param string $alias
- * @param array $args
- * @return mixed
+ * @param ContainerInterface $container
+ *
+ * @return self
*/
- protected function getFromThisContainer($alias, array $args = [])
+ public function delegate(ContainerInterface $container) : self
{
- if ($this->hasShared($alias, true)) {
- $shared = $this->inflectors->inflect($this->shared[$alias]);
- if ($shared instanceof RawArgumentInterface) {
- return $shared->getValue();
- }
- return $shared;
- }
-
- if (array_key_exists($alias, $this->sharedDefinitions)) {
- $shared = $this->inflectors->inflect($this->sharedDefinitions[$alias]->build());
- $this->shared[$alias] = $shared;
- return $shared;
- }
+ $this->delegates[] = $container;
- if (array_key_exists($alias, $this->definitions)) {
- return $this->inflectors->inflect(
- $this->definitions[$alias]->build($args)
- );
+ if ($container instanceof ContainerAwareInterface) {
+ $container->setLeagueContainer($this);
}
- throw new NotFoundException(
- sprintf('Alias (%s) is not being managed by the container', $alias)
- );
+ return $this;
}
}
diff --git a/src/Dependencies/League/Container/ContainerAwareInterface.php b/src/Dependencies/League/Container/ContainerAwareInterface.php
index c165bc7..f261731 100644
--- a/src/Dependencies/League/Container/ContainerAwareInterface.php
+++ b/src/Dependencies/League/Container/ContainerAwareInterface.php
@@ -1,20 +1,40 @@
-container = $container;
@@ -25,10 +34,43 @@ public function setContainer(ContainerInterface $container)
/**
* Get the container.
*
- * @return \RocketLazyLoadPlugin\Dependencies\League\Container\ContainerInterface
+ * @return ContainerInterface
*/
- public function getContainer()
+ public function getContainer() : ContainerInterface
{
- return $this->container;
+ if ($this->container instanceof ContainerInterface) {
+ return $this->container;
+ }
+
+ throw new ContainerException('No container implementation has been set.');
+ }
+
+ /**
+ * Set a container.
+ *
+ * @param Container $container
+ *
+ * @return self
+ */
+ public function setLeagueContainer(Container $container) : ContainerAwareInterface
+ {
+ $this->container = $container;
+ $this->leagueContainer = $container;
+
+ return $this;
+ }
+
+ /**
+ * Get the container.
+ *
+ * @return Container
+ */
+ public function getLeagueContainer() : Container
+ {
+ if ($this->leagueContainer instanceof Container) {
+ return $this->leagueContainer;
+ }
+
+ throw new ContainerException('No container implementation has been set.');
}
}
diff --git a/src/Dependencies/League/Container/ContainerInterface.php b/src/Dependencies/League/Container/ContainerInterface.php
deleted file mode 100644
index e03a796..0000000
--- a/src/Dependencies/League/Container/ContainerInterface.php
+++ /dev/null
@@ -1,59 +0,0 @@
-alias = $alias;
- $this->concrete = $concrete;
- }
-
- /**
- * {@inheritdoc}
- */
- public function withArgument($arg)
- {
- $this->arguments[] = $arg;
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function withArguments(array $args)
- {
- foreach ($args as $arg) {
- $this->withArgument($arg);
- }
-
- return $this;
- }
-}
diff --git a/src/Dependencies/League/Container/Definition/CallableDefinition.php b/src/Dependencies/League/Container/Definition/CallableDefinition.php
deleted file mode 100644
index eb2dfe5..0000000
--- a/src/Dependencies/League/Container/Definition/CallableDefinition.php
+++ /dev/null
@@ -1,23 +0,0 @@
-arguments : $args;
- $resolved = $this->resolveArguments($args);
-
- if (is_array($this->concrete) && is_string($this->concrete[0])) {
- $this->concrete[0] = ($this->getContainer()->has($this->concrete[0]))
- ? $this->getContainer()->get($this->concrete[0])
- : $this->concrete[0];
- }
-
- return call_user_func_array($this->concrete, $resolved);
- }
-}
diff --git a/src/Dependencies/League/Container/Definition/ClassDefinition.php b/src/Dependencies/League/Container/Definition/ClassDefinition.php
deleted file mode 100644
index 2c7627e..0000000
--- a/src/Dependencies/League/Container/Definition/ClassDefinition.php
+++ /dev/null
@@ -1,67 +0,0 @@
-methods[] = [
- 'method' => $method,
- 'arguments' => $args
- ];
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function withMethodCalls(array $methods = [])
- {
- foreach ($methods as $method => $args) {
- $this->withMethodCall($method, $args);
- }
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function build(array $args = [])
- {
- $args = (empty($args)) ? $this->arguments : $args;
- $resolved = $this->resolveArguments($args);
- $reflection = new ReflectionClass($this->concrete);
- $instance = $reflection->newInstanceArgs($resolved);
-
- return $this->invokeMethods($instance);
- }
-
- /**
- * Invoke methods on resolved instance.
- *
- * @param object $instance
- * @return object
- */
- protected function invokeMethods($instance)
- {
- foreach ($this->methods as $method) {
- $args = $this->resolveArguments($method['arguments']);
- call_user_func_array([$instance, $method['method']], $args);
- }
-
- return $instance;
- }
-}
diff --git a/src/Dependencies/League/Container/Definition/ClassDefinitionInterface.php b/src/Dependencies/League/Container/Definition/ClassDefinitionInterface.php
deleted file mode 100644
index e8a8c8d..0000000
--- a/src/Dependencies/League/Container/Definition/ClassDefinitionInterface.php
+++ /dev/null
@@ -1,23 +0,0 @@
-setContainer($this->getContainer());
- }
-
- if (is_string($concrete) && class_exists($concrete)) {
- return (new ClassDefinition($alias, $concrete))->setContainer($this->getContainer());
- }
-
- // if the item is not definable we just return the value to be stored
- // in the container as an arbitrary value/instance
- return $concrete;
- }
-}
diff --git a/src/Dependencies/League/Container/Definition/DefinitionFactoryInterface.php b/src/Dependencies/League/Container/Definition/DefinitionFactoryInterface.php
deleted file mode 100644
index d11fa8f..0000000
--- a/src/Dependencies/League/Container/Definition/DefinitionFactoryInterface.php
+++ /dev/null
@@ -1,17 +0,0 @@
-container = $container;
-
- return $this;
- }
-
- /**
- * Get the container.
- *
- * @return \RocketLazyLoadPlugin\Dependencies\League\Container\ImmutableContainerInterface
- */
- public function getContainer()
- {
- return $this->container;
- }
-}
diff --git a/src/Dependencies/League/Container/ImmutableContainerInterface.php b/src/Dependencies/League/Container/ImmutableContainerInterface.php
deleted file mode 100644
index 43d5610..0000000
--- a/src/Dependencies/League/Container/ImmutableContainerInterface.php
+++ /dev/null
@@ -1,10 +0,0 @@
-type = $type;
+ $this->callback = $callback;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getType() : string
+ {
+ return $this->type;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function invokeMethod(string $name, array $args) : InflectorInterface
{
$this->methods[$name] = $args;
@@ -36,12 +62,9 @@ public function invokeMethod($name, array $args)
}
/**
- * Defines multiple methods to be invoked on the subject object.
- *
- * @param array $methods
- * @return $this
+ * {@inheritdoc}
*/
- public function invokeMethods(array $methods)
+ public function invokeMethods(array $methods) : InflectorInterface
{
foreach ($methods as $name => $args) {
$this->invokeMethod($name, $args);
@@ -51,26 +74,19 @@ public function invokeMethods(array $methods)
}
/**
- * Defines a property to be set on the subject object.
- *
- * @param string $property
- * @param mixed $value
- * @return $this
+ * {@inheritdoc}
*/
- public function setProperty($property, $value)
+ public function setProperty(string $property, $value) : InflectorInterface
{
- $this->properties[$property] = $value;
+ $this->properties[$property] = $this->resolveArguments([$value])[0];
return $this;
}
/**
- * Defines multiple properties to be set on the subject object.
- *
- * @param array $properties
- * @return $this
+ * {@inheritdoc}
*/
- public function setProperties(array $properties)
+ public function setProperties(array $properties) : InflectorInterface
{
foreach ($properties as $property => $value) {
$this->setProperty($property, $value);
@@ -80,24 +96,28 @@ public function setProperties(array $properties)
}
/**
- * Apply inflections to an object.
- *
- * @param object $object
- * @return void
+ * {@inheritdoc}
*/
public function inflect($object)
{
$properties = $this->resolveArguments(array_values($this->properties));
$properties = array_combine(array_keys($this->properties), $properties);
- foreach ($properties as $property => $value) {
+ // array_combine() can technically return false
+ foreach ($properties ?: [] as $property => $value) {
$object->{$property} = $value;
}
foreach ($this->methods as $method => $args) {
$args = $this->resolveArguments($args);
- call_user_func_array([$object, $method], $args);
+ /** @var callable $callable */
+ $callable = [$object, $method];
+ call_user_func_array($callable, $args);
+ }
+
+ if ($this->callback !== null) {
+ call_user_func($this->callback, $object);
}
}
}
diff --git a/src/Dependencies/League/Container/Inflector/InflectorAggregate.php b/src/Dependencies/League/Container/Inflector/InflectorAggregate.php
index e6d4cc1..8f99aab 100644
--- a/src/Dependencies/League/Container/Inflector/InflectorAggregate.php
+++ b/src/Dependencies/League/Container/Inflector/InflectorAggregate.php
@@ -1,31 +1,40 @@
-inflectors[$type] = $inflector;
+ $inflector = new Inflector($type, $callback);
+ $this->inflectors[] = $inflector;
- return $inflector;
- }
+ return $inflector;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getIterator() : Generator
+ {
+ $count = count($this->inflectors);
- $this->inflectors[$type] = $callback;
+ for ($i = 0; $i < $count; $i++) {
+ yield $this->inflectors[$i];
+ }
}
/**
@@ -33,19 +42,15 @@ public function add($type, callable $callback = null)
*/
public function inflect($object)
{
- foreach ($this->inflectors as $type => $inflector) {
- if (! $object instanceof $type) {
- continue;
- }
+ foreach ($this->getIterator() as $inflector) {
+ $type = $inflector->getType();
- if ($inflector instanceof Inflector) {
- $inflector->setContainer($this->getContainer());
- $inflector->inflect($object);
+ if (! $object instanceof $type) {
continue;
}
- // must be dealing with a callable as the inflector
- call_user_func_array($inflector, [$object]);
+ $inflector->setLeagueContainer($this->getLeagueContainer());
+ $inflector->inflect($object);
}
return $object;
diff --git a/src/Dependencies/League/Container/Inflector/InflectorAggregateInterface.php b/src/Dependencies/League/Container/Inflector/InflectorAggregateInterface.php
index 33247c6..13f15db 100644
--- a/src/Dependencies/League/Container/Inflector/InflectorAggregateInterface.php
+++ b/src/Dependencies/League/Container/Inflector/InflectorAggregateInterface.php
@@ -1,19 +1,21 @@
-has($alias)) {
+ if ($this->cacheResolutions === true && array_key_exists($id, $this->cache)) {
+ return $this->cache[$id];
+ }
+
+ if (! $this->has($id)) {
throw new NotFoundException(
- sprintf('Alias (%s) is not an existing class and therefore cannot be resolved', $alias)
+ sprintf('Alias (%s) is not an existing class and therefore cannot be resolved', $id)
);
}
- $reflector = new ReflectionClass($alias);
+ $reflector = new ReflectionClass($id);
$construct = $reflector->getConstructor();
- if ($construct === null) {
- return new $alias;
+ if ($construct && !$construct->isPublic()) {
+ throw new NotFoundException(
+ sprintf('Alias (%s) has a non-public constructor and therefore cannot be instantiated', $id)
+ );
}
- return $reflector->newInstanceArgs(
- $this->reflectArguments($construct, $args)
- );
+ $resolution = $construct === null
+ ? new $id
+ : $resolution = $reflector->newInstanceArgs($this->reflectArguments($construct, $args))
+ ;
+
+ if ($this->cacheResolutions === true) {
+ $this->cache[$id] = $resolution;
+ }
+
+ return $resolution;
}
/**
* {@inheritdoc}
*/
- public function has($alias)
+ public function has($id)
{
- return class_exists($alias);
+ return class_exists($id);
}
/**
* Invoke a callable via the container.
*
- * @param callable $callable
- * @param array $args
+ * @param callable $callable
+ * @param array $args
+ *
* @return mixed
+ *
+ * @throws ReflectionException
*/
public function call(callable $callable, array $args = [])
{
@@ -80,8 +109,23 @@ public function call(callable $callable, array $args = [])
return $reflection->invokeArgs($callable, $this->reflectArguments($reflection, $args));
}
- $reflection = new ReflectionFunction($callable);
+ $reflection = new ReflectionFunction(\Closure::fromCallable($callable));
return $reflection->invokeArgs($this->reflectArguments($reflection, $args));
}
+
+ /**
+ * Whether the container should default to caching resolutions and returning
+ * the cache on following calls.
+ *
+ * @param boolean $option
+ *
+ * @return self
+ */
+ public function cacheResolutions(bool $option = true) : ContainerInterface
+ {
+ $this->cacheResolutions = $option;
+
+ return $this;
+ }
}
diff --git a/src/Dependencies/League/Container/ServiceProvider/AbstractServiceProvider.php b/src/Dependencies/League/Container/ServiceProvider/AbstractServiceProvider.php
index 2ed2866..7374fba 100644
--- a/src/Dependencies/League/Container/ServiceProvider/AbstractServiceProvider.php
+++ b/src/Dependencies/League/Container/ServiceProvider/AbstractServiceProvider.php
@@ -1,4 +1,4 @@
-provides));
- }
+ return in_array($alias, $this->provides, true);
+ }
- return $this->provides;
+ /**
+ * {@inheritdoc}
+ */
+ public function setIdentifier(string $id) : ServiceProviderInterface
+ {
+ $this->identifier = $id;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getIdentifier() : string
+ {
+ return $this->identifier ?? get_class($this);
}
}
diff --git a/src/Dependencies/League/Container/ServiceProvider/AbstractSignatureServiceProvider.php b/src/Dependencies/League/Container/ServiceProvider/AbstractSignatureServiceProvider.php
deleted file mode 100644
index 029c367..0000000
--- a/src/Dependencies/League/Container/ServiceProvider/AbstractSignatureServiceProvider.php
+++ /dev/null
@@ -1,31 +0,0 @@
-signature = $signature;
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getSignature()
- {
- return (is_null($this->signature)) ? get_class($this) : $this->signature;
- }
-}
diff --git a/src/Dependencies/League/Container/ServiceProvider/BootableServiceProviderInterface.php b/src/Dependencies/League/Container/ServiceProvider/BootableServiceProviderInterface.php
index e730c6f..72f2876 100644
--- a/src/Dependencies/League/Container/ServiceProvider/BootableServiceProviderInterface.php
+++ b/src/Dependencies/League/Container/ServiceProvider/BootableServiceProviderInterface.php
@@ -1,4 +1,4 @@
-getContainer()->has($provider)) {
+ $provider = $this->getContainer()->get($provider);
+ } elseif (is_string($provider) && class_exists($provider)) {
$provider = new $provider;
}
+ if (in_array($provider, $this->providers, true)) {
+ return $this;
+ }
+
if ($provider instanceof ContainerAwareInterface) {
- $provider->setContainer($this->getContainer());
+ $provider->setLeagueContainer($this->getLeagueContainer());
}
if ($provider instanceof BootableServiceProviderInterface) {
@@ -37,14 +44,12 @@ public function add($provider)
}
if ($provider instanceof ServiceProviderInterface) {
- foreach ($provider->provides() as $service) {
- $this->providers[$service] = $provider;
- }
+ $this->providers[] = $provider;
return $this;
}
- throw new \InvalidArgumentException(
+ throw new ContainerException(
'A service provider must be a fully qualified class name or instance ' .
'of (\RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\ServiceProviderInterface)'
);
@@ -53,36 +58,49 @@ public function add($provider)
/**
* {@inheritdoc}
*/
- public function provides($service)
+ public function provides(string $service) : bool
{
- return array_key_exists($service, $this->providers);
+ foreach ($this->getIterator() as $provider) {
+ if ($provider->provides($service)) {
+ return true;
+ }
+ }
+
+ return false;
}
/**
* {@inheritdoc}
*/
- public function register($service)
+ public function getIterator() : Generator
{
- if (! array_key_exists($service, $this->providers)) {
- throw new \InvalidArgumentException(
- sprintf('(%s) is not provided by a service provider', $service)
- );
- }
+ $count = count($this->providers);
- $provider = $this->providers[$service];
- $signature = get_class($provider);
-
- if ($provider instanceof SignatureServiceProviderInterface) {
- $signature = $provider->getSignature();
+ for ($i = 0; $i < $count; $i++) {
+ yield $this->providers[$i];
}
+ }
- // ensure that the provider hasn't already been invoked by any other service request
- if (in_array($signature, $this->registered)) {
- return;
+ /**
+ * {@inheritdoc}
+ */
+ public function register(string $service)
+ {
+ if (false === $this->provides($service)) {
+ throw new ContainerException(
+ sprintf('(%s) is not provided by a service provider', $service)
+ );
}
- $provider->register();
+ foreach ($this->getIterator() as $provider) {
+ if (in_array($provider->getIdentifier(), $this->registered, true)) {
+ continue;
+ }
- $this->registered[] = $signature;
+ if ($provider->provides($service)) {
+ $this->registered[] = $provider->getIdentifier();
+ $provider->register();
+ }
+ }
}
}
diff --git a/src/Dependencies/League/Container/ServiceProvider/ServiceProviderAggregateInterface.php b/src/Dependencies/League/Container/ServiceProvider/ServiceProviderAggregateInterface.php
index 0165d69..d765286 100644
--- a/src/Dependencies/League/Container/ServiceProvider/ServiceProviderAggregateInterface.php
+++ b/src/Dependencies/League/Container/ServiceProvider/ServiceProviderAggregateInterface.php
@@ -1,32 +1,36 @@
-container property or the `getContainer` method
+ * protected $this->leagueContainer property or the `getLeagueContainer` method
* from the ContainerAwareTrait.
*
* @return void
*/
public function register();
+
+ /**
+ * Set a custom id for the service provider. This enables
+ * registering the same service provider multiple times.
+ *
+ * @param string $id
+ *
+ * @return self
+ */
+ public function setIdentifier(string $id) : ServiceProviderInterface;
+
+ /**
+ * The id of the service provider uniquely identifies it, so
+ * that we can quickly determine if it has already been registered.
+ * Defaults to get_class($provider).
+ *
+ * @return string
+ */
+ public function getIdentifier() : string;
}
diff --git a/src/Dependencies/League/Container/ServiceProvider/SignatureServiceProviderInterface.php b/src/Dependencies/League/Container/ServiceProvider/SignatureServiceProviderInterface.php
deleted file mode 100644
index 273b0ad..0000000
--- a/src/Dependencies/League/Container/ServiceProvider/SignatureServiceProviderInterface.php
+++ /dev/null
@@ -1,24 +0,0 @@
-getLazyloadScript( $args );
+ echo $this->getLazyloadScript( $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
@@ -31,7 +33,6 @@ public function insertLazyloadScript( $args = [] ) {
public function getInlineLazyloadScript( $args = [] ) {
$defaults = [
'elements' => [
- 'img',
'iframe',
],
'threshold' => 300,
@@ -42,13 +43,24 @@ public function getInlineLazyloadScript( $args = [] ) {
'container' => 1,
'thresholds' => 1,
'data_bg' => 1,
+ 'data_bg_hidpi' => 1,
+ 'data_bg_multi' => 1,
+ 'data_bg_multi_hidpi' => 1,
+ 'data_poster' => 1,
+ 'class_applied' => 1,
'class_error' => 1,
+ 'class_entered' => 1,
+ 'class_exited' => 1,
'cancel_on_exit' => 1,
+ 'unobserve_entered' => 1,
'unobserve_completed' => 1,
'callback_enter' => 1,
'callback_exit' => 1,
'callback_loading' => 1,
+ 'callback_cancel' => 1,
+ 'callback_loaded' => 1,
'callback_error' => 1,
+ 'callback_applied' => 1,
'callback_finish' => 1,
'use_native' => 1,
];
@@ -57,8 +69,13 @@ public function getInlineLazyloadScript( $args = [] ) {
$script = '';
$args['options'] = array_intersect_key( $args['options'], $allowed_options );
+ $script .= 'window.lazyLoadOptions = ';
+
+ if ( isset( $args['elements']['background_image'] ) ) {
+ $script .= '[';
+ }
- $script .= 'window.lazyLoadOptions = {
+ $script .= '{
elements_selector: "' . esc_attr( implode( ',', $args['elements'] ) ) . '",
data_src: "lazy-src",
data_srcset: "lazy-srcset",
@@ -88,7 +105,19 @@ class_loaded: "lazyloaded",
$script = rtrim( $script, ',' );
}
- $script .= '};';
+ if ( isset( $args['elements']['background_image'] ) ) {
+ $script .= '},{
+ elements_selector: "' . esc_attr( $args['elements']['background_image'] ) . '",
+ data_src: "lazy-src",
+ data_srcset: "lazy-srcset",
+ data_sizes: "lazy-sizes",
+ class_loading: "lazyloading",
+ class_loaded: "lazyloaded",
+ threshold: ' . esc_attr( $args['threshold'] ) . ',
+ }];';
+ } else {
+ $script .= '};';
+ }
$script .= '
window.addEventListener(\'LazyLoad::Initialized\', function (e) {
@@ -101,13 +130,13 @@ class_loaded: "lazyloaded",
var rocketlazy_count = 0;
mutations.forEach(function(mutation) {
- for (i = 0; i < mutation.addedNodes.length; i++) {
+ for (var i = 0; i < mutation.addedNodes.length; i++) {
if (typeof mutation.addedNodes[i].getElementsByTagName !== \'function\') {
- return;
+ continue;
}
- if (typeof mutation.addedNodes[i].getElementsByClassName !== \'function\') {
- return;
+ if (typeof mutation.addedNodes[i].getElementsByClassName !== \'function\') {
+ continue;
}
images = mutation.addedNodes[i].getElementsByTagName(\'img\');
@@ -157,9 +186,8 @@ public function getLazyloadScript( $args = [] ) {
'version' => '',
];
- $args = wp_parse_args( $args, $defaults );
- $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
- $script = '';
+ $args = wp_parse_args( $args, $defaults );
+ $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
/**
* Filters the script tag for the lazyload script
@@ -168,9 +196,7 @@ public function getLazyloadScript( $args = [] ) {
*
* @param $script_tag HTML tag for the lazyload script.
*/
- $script .= apply_filters( 'rocket_lazyload_script_tag', '' );
-
- return $script;
+ return apply_filters( 'rocket_lazyload_script_tag', '' ); // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
}
/**
@@ -180,7 +206,7 @@ public function getLazyloadScript( $args = [] ) {
* @return void
*/
public function insertYoutubeThumbnailScript( $args = [] ) {
- echo $this->getYoutubeThumbnailScript( $args );
+ echo $this->getYoutubeThumbnailScript( $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
@@ -193,6 +219,8 @@ public function getYoutubeThumbnailScript( $args = [] ) {
$defaults = [
'resolution' => 'hqdefault',
'lazy_image' => false,
+ 'native' => true,
+ 'extension' => 'jpg',
];
$allowed_resolutions = [
@@ -223,13 +251,23 @@ public function getYoutubeThumbnailScript( $args = [] ) {
$args = wp_parse_args( $args, $defaults );
- $image = ' ';
+ $extension_uri = 'webp' === $args['extension'] ? 'vi_webp' : 'vi';
+
+ $image_url = 'https://i.ytimg.com/' . $extension_uri . '/ID/' . $args['resolution'] . '.' . $args['extension'];
+
+ $image = ' ';
if ( isset( $args['lazy_image'] ) && $args['lazy_image'] ) {
- $image = ' ';
+ $attributes = 'alt="" width="' . $allowed_resolutions[ $args['resolution'] ]['width'] . '" height="' . $allowed_resolutions[ $args['resolution'] ]['height'] . '"';
+
+ $image = ' ';
+
+ if ( $args['native'] ) {
+ $image = ' ';
+ }
}
- return "";
+ return "";
}
/**
@@ -239,7 +277,7 @@ public function getYoutubeThumbnailScript( $args = [] ) {
* @return void
*/
public function insertYoutubeThumbnailCSS( $args = [] ) {
- wp_register_style( 'rocket-lazyload', false );
+ wp_register_style( 'rocket-lazyload', false ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
wp_enqueue_style( 'rocket-lazyload' );
wp_add_inline_style( 'rocket-lazyload', $this->getYoutubeThumbnailCSS( $args ) );
}
@@ -258,10 +296,10 @@ public function getYoutubeThumbnailCSS( $args = [] ) {
$args = wp_parse_args( $args, $defaults );
- $css = '.rll-youtube-player{position:relative;padding-bottom:56.23%;height:0;overflow:hidden;max-width:100%;}.rll-youtube-player iframe{position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;background:0 0}.rll-youtube-player img{bottom:0;display:block;left:0;margin:auto;max-width:100%;width:100%;position:absolute;right:0;top:0;border:none;height:auto;cursor:pointer;-webkit-transition:.4s all;-moz-transition:.4s all;transition:.4s all}.rll-youtube-player img:hover{-webkit-filter:brightness(75%)}.rll-youtube-player .play{height:72px;width:72px;left:50%;top:50%;margin-left:-36px;margin-top:-36px;position:absolute;background:url(' . $args['base_url'] . 'img/youtube.png) no-repeat;cursor:pointer}';
+ $css = '.rll-youtube-player{position:relative;padding-bottom:56.23%;height:0;overflow:hidden;max-width:100%;}.rll-youtube-player:focus-within{outline: 2px solid currentColor;outline-offset: 5px;}.rll-youtube-player iframe{position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;background:0 0}.rll-youtube-player img{bottom:0;display:block;left:0;margin:auto;max-width:100%;width:100%;position:absolute;right:0;top:0;border:none;height:auto;-webkit-transition:.4s all;-moz-transition:.4s all;transition:.4s all}.rll-youtube-player img:hover{-webkit-filter:brightness(75%)}.rll-youtube-player .play{height:100%;width:100%;left:0;top:0;position:absolute;background:url(' . $args['base_url'] . 'img/youtube.png) no-repeat center;background-color: transparent !important;cursor:pointer;border:none;}';
if ( $args['responsive_embeds'] ) {
- $css .= '.wp-has-aspect-ratio .rll-youtube-player{position:absolute;padding-bottom:0;width:100%;height:100%;top:0;bottom:0;left:0;right:0}';
+ $css .= '.wp-embed-responsive .wp-has-aspect-ratio .rll-youtube-player{position:absolute;padding-bottom:0;width:100%;height:100%;top:0;bottom:0;left:0;right:0}';
}
return $css;
@@ -271,7 +309,7 @@ public function getYoutubeThumbnailCSS( $args = [] ) {
* Inserts the CSS needed when Javascript is not enabled to keep the display correct
*/
public function insertNoJSCSS() {
- echo $this->getNoJSCSS();
+ echo $this->getNoJSCSS(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
diff --git a/src/Dependencies/RocketLazyload/Iframe.php b/src/Dependencies/RocketLazyload/Iframe.php
index a4fc295..a4b369a 100644
--- a/src/Dependencies/RocketLazyload/Iframe.php
+++ b/src/Dependencies/RocketLazyload/Iframe.php
@@ -2,7 +2,7 @@
/**
* Handles lazyloading of iframes
*
- * @package RocketLazyload
+ * @package RocketLazyLoadPlugin\Dependencies\RocketLazyload
*/
namespace RocketLazyLoadPlugin\Dependencies\RocketLazyload;
@@ -106,6 +106,7 @@ private function getExcludedPatterns() {
'loading="eager"',
'data-skip-lazy',
'skip-lazy',
+ 'google_ads_iframe_',
]
);
}
@@ -163,6 +164,10 @@ private function replaceYoutubeThumbnail( $iframe ) {
$youtube_url = $this->changeYoutubeUrlForYoutuDotBe( $iframe['src'] );
$youtube_url = $this->cleanYoutubeUrl( $iframe['src'] );
+
+ preg_match( '@\s*title\s*=\s*(\'|")(?.*)\1@iUs', $iframe['atts'], $atts );
+
+ $title = $atts['title'] ?? '';
/**
* Filter the LazyLoad HTML output on Youtube iframes
*
@@ -170,7 +175,7 @@ private function replaceYoutubeThumbnail( $iframe ) {
*
* @param array $html Output that will be printed.
*/
- $youtube_lazyload = apply_filters( 'rocket_lazyload_youtube_html', '
' );
+ $youtube_lazyload = apply_filters( 'rocket_lazyload_youtube_html', '
' );
$youtube_lazyload .= '' . $iframe[0] . ' ';
return $youtube_lazyload;
diff --git a/src/Dependencies/RocketLazyload/Image.php b/src/Dependencies/RocketLazyload/Image.php
index bf09538..e86a80c 100644
--- a/src/Dependencies/RocketLazyload/Image.php
+++ b/src/Dependencies/RocketLazyload/Image.php
@@ -1,8 +1,10 @@
]*)>(?:.+)?<\/script>/Umsi', '', $html );
- $clean_buffer = preg_replace( '#(?:.+) #Umsi', '', $clean_buffer );
- if (! preg_match_all('# \s.+)\s?/?>#iUs', $clean_buffer, $images, PREG_SET_ORDER)) {
+ public function lazyloadImages( $html, $buffer, $use_native = true ) {
+ if ( ! preg_match_all( '# \s.+)\s?/?>#iUs', $buffer, $images, PREG_SET_ORDER ) ) {
return $html;
}
@@ -35,9 +36,13 @@ public function lazyloadImages( $html, $buffer ) {
continue;
}
- $image_lazyload = $this->replaceImage( $image );
- $image_lazyload .= $this->noscript( $image[0] );
- $html = str_replace( $image[0], $image_lazyload, $html );
+ $image_lazyload = $this->replaceImage( $image, $use_native );
+
+ if ( ! $use_native ) {
+ $image_lazyload .= $this->noscript( $image[0] );
+ }
+
+ $html = str_replace( $image[0], $image_lazyload, $html );
unset( $image_lazyload );
}
@@ -62,17 +67,34 @@ public function lazyloadBackgroundImages( $html, $buffer ) {
continue;
}
- if ( ! preg_match( '#background-image\s*:\s*(?\s*url\s*\((?[^)]+)\))\s*;?#is', $element['styles'], $url ) ) {
+ /**
+ * Regex to detect bg images inside CSS.
+ *
+ * @param string $regex regex to detect.
+ * @return string
+ */
+ $regex = apply_filters( 'rocket_lazyload_bg_images_regex', 'background-image\s*:\s*(?\s*url\s*\((?[^)]+)\))\s*;?' );
+
+ if ( @preg_match( "#$regex#is", '' ) === false ) {// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
+ $regex = 'background-image\s*:\s*(?\s*url\s*\((?[^)]+)\))\s*;?';
+ }
+
+ if ( ! preg_match( "#$regex#is", $element['styles'], $url ) ) {
continue;
}
+ if ( preg_match( '#data:image#is', $url['url'], $img ) ) {
+ continue;
+ }
$url['url'] = esc_url(
trim(
- strip_tags(
+ wp_strip_all_tags(
html_entity_decode(
- $url['url'], ENT_QUOTES|ENT_HTML5
+ $url['url'],
+ ENT_QUOTES | ENT_HTML5
)
- ), '\'" '
+ ),
+ '\'" '
)
);
@@ -99,7 +121,7 @@ public function lazyloadBackgroundImages( $html, $buffer ) {
*/
private function addLazyClass( $element ) {
$class = $this->getClasses( $element );
- if ( empty( $class ) ) {
+ if ( empty( $class ) ) {
return preg_replace( '#<(img|div|figure|section|li|span|a)([^>]*)>#is', '<\1 class="rocket-lazyload"\2>', $element );
}
@@ -132,7 +154,7 @@ private function addLazyClass( $element ) {
*/
private function getAttributeQuotes( $attribute_value ) {
$attribute_value = trim( $attribute_value );
- $first_char = $attribute_value[0];
+ $first_char = $attribute_value[0];
if ( '"' === $first_char || "'" === $first_char ) {
return $first_char;
@@ -230,7 +252,7 @@ private function stringToArray( $string, $delimiter = ' ' ) {
}
$array = explode( $delimiter, $string );
- $array = array_map('trim', $array );
+ $array = array_map( 'trim', $array );
// Remove empties.
return array_filter( $array );
@@ -253,25 +275,40 @@ public function lazyloadPictures( $html, $buffer ) {
foreach ( $pictures as $picture ) {
if ( $this->isExcluded( $picture[0], $excluded ) ) {
+ if ( ! preg_match( '# \s.+)\s?/?>#iUs', $picture[0], $img ) ) {
+ continue;
+ }
+
+ $img = $this->canLazyload( $img );
+
+ if ( ! $img ) {
+ continue;
+ }
+
+ $nolazy_picture = str_replace( ' \s.+)>#iUs', $picture['sources'], $sources, PREG_SET_ORDER ) ) {
- $sources = array_unique( $sources, SORT_REGULAR );
-
$lazy_sources = 0;
+ $sources = array_unique( $sources, SORT_REGULAR );
+ $lazy_picture = $picture[0];
foreach ( $sources as $source ) {
$lazyload_srcset = preg_replace( '/([\s"\'])srcset/i', '\1data-lazy-srcset', $source[0] );
- $html = str_replace( $source[0], $lazyload_srcset, $html );
+ $lazy_picture = str_replace( $source[0], $lazyload_srcset, $lazy_picture );
unset( $lazyload_srcset );
$lazy_sources++;
}
- }
- if ( 0 === $lazy_sources ) {
- continue;
+ if ( 0 === $lazy_sources ) {
+ continue;
+ }
+
+ $html = str_replace( $picture[0], $lazy_picture, $html );
}
if ( ! preg_match( '# \s.+)\s?/?>#iUs', $picture[0], $img ) ) {
@@ -284,10 +321,10 @@ public function lazyloadPictures( $html, $buffer ) {
continue;
}
- $img_lazy = $this->replaceImage( $img );
+ $img_lazy = $this->replaceImage( $img, false );
$img_lazy .= $this->noscript( $img[0] );
- $safe_img = str_replace('/', '\/', preg_quote( $img[0], '#' ));
- $html = preg_replace( '#]*>.*' . $safe_img . '.*<\/noscript>(*SKIP)(*FAIL)|' . $safe_img . '#iU', $img_lazy, $html );
+ $safe_img = str_replace( '/', '\/', preg_quote( $img[0], '#' ) );
+ $html = preg_replace( '#]*>.*' . $safe_img . '.*<\/noscript>(*SKIP)(*FAIL)|' . $safe_img . '#i', $img_lazy, $html );
unset( $img_lazy );
}
@@ -321,13 +358,6 @@ private function canLazyload( $image ) {
return false;
}
- // Don't apply LazyLoad on images from WP Retina x2.
- if ( function_exists( 'wr2x_picture_rewrite' ) ) {
- if ( wr2x_get_retina( trailingslashit( ABSPATH ) . wr2x_get_pathinfo_from_image_src( trim( $image['src'], '"' ) ) ) ) {
- return false;
- }
- }
-
return $image;
}
@@ -340,7 +370,7 @@ private function canLazyload( $image ) {
*/
public function isExcluded( $string, $excluded_values ) {
if ( ! is_array( $excluded_values ) ) {
- (array) $excluded_values;
+ $excluded_values = (array) $excluded_values;
}
if ( empty( $excluded_values ) ) {
@@ -366,7 +396,6 @@ public function getExcludedAttributes() {
* Filters the attributes used to prevent lazylad from being applied
*
* @since 1.0
- * @author Remy Perona
*
* @param array $excluded_attributes An array of excluded attributes.
*/
@@ -394,6 +423,7 @@ public function getExcludedAttributes() {
'avia-bg-style-fixed',
'data-skip-lazy',
'skip-lazy',
+ 'image-compare__',
]
);
}
@@ -408,7 +438,6 @@ public function getExcludedSrc() {
* Filters the src used to prevent lazylad from being applied
*
* @since 1.0
- * @author Remy Perona
*
* @param array $excluded_src An array of excluded src.
*/
@@ -426,26 +455,43 @@ public function getExcludedSrc() {
* Replaces the original image by the lazyload one
*
* @param array $image Array of matches elements.
+ * @param bool $use_native Use native lazyload.
+ *
* @return string
*/
- private function replaceImage( $image ) {
- $width = 0;
- $height = 0;
-
- if ( preg_match( '@[\s"\']width\s*=\s*(\'|")(?.*)\1@iUs', $image['atts'], $atts ) ) {
- $width = absint( $atts['width'] );
- }
-
- if ( preg_match( '@[\s"\']height\s*=\s*(\'|")(?.*)\1@iUs', $image['atts'], $atts ) ) {
- $height = absint( $atts['height'] );
+ private function replaceImage( $image, $use_native = true ) {
+ if ( empty( $image ) ) {
+ return '';
}
- $placeholder_atts = preg_replace( '@\ssrc\s*=\s*(\'|")(?.*)\1@iUs', ' src="' . $this->getPlaceholder( $width, $height ) . '"', $image['atts'] );
+ $native_pattern = '@\sloading\s*=\s*(\'|")(?:lazy|auto)\1@i';
+ $image_lazyload = $image[0];
- $image_lazyload = str_replace( $image['atts'], $placeholder_atts . ' data-lazy-src="' . $image['src'] . '"', $image[0] );
+ if ( $use_native ) {
+ if ( preg_match( $native_pattern, $image[0] ) ) {
+ return $image[0];
+ }
- if ( ! preg_match( '@\sloading\s*=\s*(\'|")(?:lazy|auto)\1@i', $image_lazyload ) && apply_filters( 'rocket_use_native_lazyload', false ) ) {
$image_lazyload = str_replace( ' .*)\1@iUs', $image['atts'], $atts ) ) {
+ $width = absint( $atts['width'] );
+ }
+
+ if ( preg_match( '@[\s"\']height\s*=\s*(\'|")(?.*)\1@iUs', $image['atts'], $atts ) ) {
+ $height = absint( $atts['height'] );
+ }
+
+ $placeholder_atts = preg_replace( '@\ssrc\s*=\s*(\'|")(?.*)\1@iUs', ' src="' . $this->getPlaceholder( $width, $height ) . '"', $image['atts'] );
+
+ $image_lazyload = str_replace( $image['atts'], $placeholder_atts . ' data-lazy-src="' . $image['src'] . '"', $image_lazyload );
+
+ if ( preg_match( $native_pattern, $image_lazyload ) ) {
+ $image_lazyload = preg_replace( $native_pattern, '', $image_lazyload );
+ }
}
/**
@@ -492,6 +538,10 @@ public function lazyloadResponsiveAttributes( $html ) {
public function convertSmilies( $text ) {
global $wp_smiliessearch;
+ if ( empty( $text ) || ! is_string( $text ) ) {
+ return $text;
+ }
+
if ( ! get_option( 'use_smilies' ) || empty( $wp_smiliessearch ) ) {
return $text;
}
@@ -563,7 +613,7 @@ private function translateSmiley( $matches ) {
* @param string $img Filename for the smiley image.
* @param string $site_url Site URL, as returned by site_url().
*/
- $src_url = apply_filters( 'smilies_src', includes_url( "images/smilies/$img" ), $img, site_url() );
+ $src_url = apply_filters( 'smilies_src', includes_url( "images/smilies/$img" ), $img, site_url() ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
// Don't LazyLoad if process is stopped for these reasons.
if ( is_feed() || is_preview() ) {
@@ -577,7 +627,6 @@ private function translateSmiley( $matches ) {
* Returns the placeholder for the src attribute
*
* @since 1.2
- * @author Remy Perona
*
* @param int $width Width of the placeholder image. Default 0.
* @param int $height Height of the placeholder image. Default 0.
diff --git a/src/EventManagement/EventManager.php b/src/EventManagement/EventManager.php
deleted file mode 100644
index 3b696bd..0000000
--- a/src/EventManagement/EventManager.php
+++ /dev/null
@@ -1,145 +0,0 @@
-
- */
-class EventManager
-{
- /**
- * Adds a callback to a specific hook of the WordPress plugin API.
- *
- * @uses add_filter()
- *
- * @param string $hook_name Name of the hook.
- * @param callable $callback Callback function.
- * @param int $priority Priority.
- * @param int $accepted_args Number of arguments.
- */
- public function addCallback($hook_name, $callback, $priority = 10, $accepted_args = 1)
- {
- add_filter($hook_name, $callback, $priority, $accepted_args);
- }
-
- /**
- * Add an event subscriber.
- *
- * The event manager registers all the hooks that the given subscriber
- * wants to register with the WordPress Plugin API.
- *
- * @param SubscriberInterface $subscriber SubscriberInterface implementation.
- */
- public function addSubscriber(SubscriberInterface $subscriber)
- {
- if ($subscriber instanceof EventManagerAwareSubscriberInterface) {
- $subscriber->setEventManager($this);
- }
-
- foreach ($subscriber->getSubscribedEvents() as $hook_name => $parameters) {
- $this->addSubscriberCallback($subscriber, $hook_name, $parameters);
- }
- }
-
- /**
- * Checks the WordPress plugin API to see if the given hook has
- * the given callback. The priority of the callback will be returned
- * or false. If no callback is given will return true or false if
- * there's any callbacks registered to the hook.
- *
- * @uses has_filter()
- *
- * @param string $hook_name Hook name.
- * @param mixed $callback Callback.
- *
- * @return bool|int
- */
- public function hasCallback($hook_name, $callback = false)
- {
- return has_filter($hook_name, $callback);
- }
-
- /**
- * Removes the given callback from the given hook. The WordPress plugin API only
- * removes the hook if the callback and priority match a registered hook.
- *
- * @uses remove_filter()
- *
- * @param string $hook_name Hook name.
- * @param callable $callback Callback.
- * @param int $priority Priority.
- *
- * @return bool
- */
- public function removeCallback($hook_name, $callback, $priority = 10)
- {
- return remove_filter($hook_name, $callback, $priority);
- }
-
- /**
- * Remove an event subscriber.
- *
- * The event manager removes all the hooks that the given subscriber
- * wants to register with the WordPress Plugin API.
- *
- * @param SubscriberInterface $subscriber SubscriberInterface implementation.
- */
- public function removeSubscriber(SubscriberInterface $subscriber)
- {
- foreach ($subscriber->getSubscribedEvents() as $hook_name => $parameters) {
- $this->removeSubscriberCallback($subscriber, $hook_name, $parameters);
- }
- }
-
- /**
- * Adds the given subscriber's callback to a specific hook
- * of the WordPress plugin API.
- *
- * @param SubscriberInterface $subscriber SubscriberInterface implementation.
- * @param string $hook_name Hook name.
- * @param mixed $parameters Parameters, can be a string, an array or a multidimensional array.
- */
- private function addSubscriberCallback(SubscriberInterface $subscriber, $hook_name, $parameters)
- {
- if (is_string($parameters)) {
- $this->addCallback($hook_name, [ $subscriber, $parameters ]);
- } elseif (is_array($parameters) && count($parameters) !== count($parameters, COUNT_RECURSIVE)) {
- foreach ($parameters as $parameter) {
- $this->addSubscriberCallback($subscriber, $hook_name, $parameter);
- }
- } elseif (is_array($parameters) && isset($parameters[0])) {
- $this->addCallback($hook_name, [ $subscriber, $parameters[0] ], isset($parameters[1]) ? $parameters[1] : 10, isset($parameters[2]) ? $parameters[2] : 1);
- }
- }
-
- /**
- * Removes the given subscriber's callback to a specific hook
- * of the WordPress plugin API.
- *
- * @param SubscriberInterface $subscriber SubscriberInterface implementation.
- * @param string $hook_name Hook name.
- * @param mixed $parameters Parameters, can be a string, an array or a multidimensional array.
- */
- private function removeSubscriberCallback(SubscriberInterface $subscriber, $hook_name, $parameters)
- {
- if (is_string($parameters)) {
- $this->removeCallback($hook_name, [ $subscriber, $parameters ]);
- } elseif (is_array($parameters) && count($parameters) !== count($parameters, COUNT_RECURSIVE)) {
- foreach ($parameters as $parameter) {
- $this->removeSubscriberCallback($subscriber, $hook_name, $parameter);
- }
- } elseif (is_array($parameters) && isset($parameters[0])) {
- $this->removeCallback($hook_name, [ $subscriber, $parameters[0] ], isset($parameters[1]) ? $parameters[1] : 10);
- }
- }
-}
diff --git a/src/EventManagement/EventManagerAwareSubscriberInterface.php b/src/EventManagement/EventManagerAwareSubscriberInterface.php
deleted file mode 100644
index 2b5b2a1..0000000
--- a/src/EventManagement/EventManagerAwareSubscriberInterface.php
+++ /dev/null
@@ -1,21 +0,0 @@
-
- */
-interface SubscriberInterface
-{
- /**
- * Returns an array of events that this subscriber wants to listen to.
- *
- * The array key is the event name. The value can be:
- *
- * * The method name
- * * An array with the method name and priority
- * * An array with the method name, priority and number of accepted arguments
- *
- * For instance:
- *
- * * array('hook_name' => 'method_name')
- * * array('hook_name' => array('method_name', $priority))
- * * array('hook_name' => array('method_name', $priority, $accepted_args))
- * * array('hook_name' => array(array('method_name_1', $priority_1, $accepted_args_1)), array('method_name_2', $priority_2, $accepted_args_2)))
- *
- * @return array
- */
- public function getSubscribedEvents();
-}
diff --git a/src/Options/AbstractOptions.php b/src/Options/AbstractOptions.php
deleted file mode 100644
index 8cdf555..0000000
--- a/src/Options/AbstractOptions.php
+++ /dev/null
@@ -1,69 +0,0 @@
-get($name);
- }
-}
diff --git a/src/Options/OptionArray.php b/src/Options/OptionArray.php
deleted file mode 100644
index 6b647a4..0000000
--- a/src/Options/OptionArray.php
+++ /dev/null
@@ -1,111 +0,0 @@
-options = $options;
- }
-
- /**
- * Checks if the provided key exists in the option data array.
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @param string $key key name.
- * @return boolean
- */
- public function has($key)
- {
- return isset($this->options[ $key ]);
- }
-
- /**
- * Gets the value associated with a specific key.
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @param string $key key name.
- * @param mixed $default default value to return if key doesn't exist.
- * @return mixed
- */
- public function get($key, $default = '')
- {
- if (! $this->has($key)) {
- return $default;
- }
-
- return $this->options[ $key ];
- }
-
- /**
- * Sets the value associated with a specific key.
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @param string $key key name.
- * @param mixed $value Value to set.
- * @return void
- */
- public function set($key, $value)
- {
- $this->options[ $key ] = $value;
- }
-
- /**
- * Sets multiple values.
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @param array $options An array of key/value pairs to set.
- * @return void
- */
- public function setValues($options)
- {
- foreach ($options as $key => $value) {
- $this->set($key, $value);
- }
- }
-
- /**
- * Gets the option array.
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return array
- */
- public function getOptions()
- {
- return $this->options;
- }
-}
diff --git a/src/Options/Options.php b/src/Options/Options.php
deleted file mode 100644
index b942643..0000000
--- a/src/Options/Options.php
+++ /dev/null
@@ -1,106 +0,0 @@
-prefix = $prefix;
- }
-
- /**
- * Gets the option name used to store the option in the WordPress database.
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @param string $name Unprefixed name of the option.
- *
- * @return string
- */
- public function getOptionName($name)
- {
- return $this->prefix . $name;
- }
-
- /**
- * Gets the option for the given name. Returns the default value if the value does not exist.
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @param string $name Name of the option to get.
- * @param mixed $default Default value to return if the value does not exist.
- *
- * @return mixed
- */
- public function get($name, $default = null)
- {
- $option = get_option($this->getOptionName($name), $default);
-
- if (is_array($default) && ! is_array($option)) {
- $option = (array) $option;
- }
-
- return $option;
- }
-
- /**
- * Sets the value of an option. Update the value if the option for the given name already exists.
- *
- * @since 2.0
- * @author Remy Perona
- * @param string $name Name of the option to set.
- * @param mixed $value Value to set for the option.
- *
- * @return void
- */
- public function set($name, $value)
- {
- update_option($this->getOptionName($name), $value);
- }
-
- /**
- * Deletes the option with the given name.
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @param string $name Name of the option to delete.
- *
- * @return void
- */
- public function delete($name)
- {
- delete_option($this->getOptionName($name));
- }
-}
diff --git a/src/Plugin.php b/src/Plugin.php
deleted file mode 100644
index 49bba68..0000000
--- a/src/Plugin.php
+++ /dev/null
@@ -1,96 +0,0 @@
-loaded;
- }
-
- /**
- * Loads the plugin in WordPress
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return void
- */
- public function load() {
- if ( $this->isLoaded() ) {
- return;
- }
-
- $container = new Container();
-
- $container->add( 'template_path', \ROCKET_LL_PATH . 'views/' );
- $container->add( 'plugin_basename', \ROCKET_LL_BASENAME );
-
- $container->add(
- 'options',
- function () {
- return new Options( 'rocket_lazyload' );
- }
- );
-
- $container->add(
- 'event_manager',
- function () {
- return new EventManager();
- }
- );
-
- $service_providers = [
- 'RocketLazyLoadPlugin\ServiceProvider\OptionServiceProvider',
- 'RocketLazyLoadPlugin\ServiceProvider\AdminServiceProvider',
- 'RocketLazyLoadPlugin\ServiceProvider\ImagifyNoticeServiceProvider',
- 'RocketLazyLoadPlugin\ServiceProvider\LazyloadServiceProvider',
- 'RocketLazyLoadPlugin\ServiceProvider\SubscribersServiceProvider',
- ];
-
- foreach ( $service_providers as $service ) {
- $container->addServiceProvider( $service );
- }
-
- $subscribers = [
- 'RocketLazyLoadPlugin\Subscriber\ThirdParty\AMPSubscriber',
- 'RocketLazyLoadPlugin\Subscriber\AdminPageSubscriber',
- 'RocketLazyLoadPlugin\Subscriber\ImagifyNoticeSubscriber',
- 'RocketLazyLoadPlugin\Subscriber\LazyloadSubscriber',
- ];
-
- foreach ( $subscribers as $subscriber ) {
- $container->get( 'event_manager' )->addSubscriber( $container->get( $subscriber ) );
- }
-
- $this->loaded = true;
- }
-}
diff --git a/src/ServiceProvider/AdminServiceProvider.php b/src/ServiceProvider/AdminServiceProvider.php
index caa9842..7f8a4c8 100644
--- a/src/ServiceProvider/AdminServiceProvider.php
+++ b/src/ServiceProvider/AdminServiceProvider.php
@@ -7,7 +7,10 @@
namespace RocketLazyLoadPlugin\ServiceProvider;
-use RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
+use RocketLazyLoadPlugin\Admin\AdminPage;
+use RocketLazyLoadPlugin\Dependencies\LaunchpadCore\Container\AbstractServiceProvider;
+use RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface;
+use RocketLazyLoadPlugin\Subscriber\AdminPageSubscriber;
/**
* Adds the admin page to the container
@@ -15,33 +18,30 @@
* @since 2.0
* @author Remy Perona
*/
-class AdminServiceProvider extends AbstractServiceProvider
-{
- /**
- * Data provided by the service provider
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @var array
- */
- protected $provides = [
- 'RocketLazyLoadPlugin\Admin\AdminPage',
- ];
+class AdminServiceProvider extends AbstractServiceProvider {
- /**
- * Registers the admin page in the container
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return void
- */
- public function register()
- {
- $this->getContainer()->add('RocketLazyLoadPlugin\Admin\AdminPage')
- ->withArgument($this->getContainer()->get('options'))
- ->withArgument($this->getContainer()->get('RocketLazyLoadPlugin\Options\OptionArray'))
- ->withArgument($this->getContainer()->get('template_path'));
- }
-}
+ public function get_common_subscribers(): array {
+ return [
+ AdminPageSubscriber::class,
+ ];
+ }
+
+ public function define() {
+ $this->register_service( AdminPage::class )
+ ->set_definition( function ( DefinitionInterface $instance ) {
+ $instance->addArguments( [
+ 'template_path'
+ ] );
+ } );
+
+ $this->register_service( AdminPageSubscriber::class )
+ ->share()
+ ->set_definition( function ( DefinitionInterface $instance ) {
+ $instance->addArguments( [
+ AdminPage::class,
+ 'plugin_basename'
+ ]
+ );
+ } );
+ }
+}
\ No newline at end of file
diff --git a/src/ServiceProvider/ImagifyNoticeServiceProvider.php b/src/ServiceProvider/ImagifyNoticeServiceProvider.php
index 6277ebc..e275c32 100644
--- a/src/ServiceProvider/ImagifyNoticeServiceProvider.php
+++ b/src/ServiceProvider/ImagifyNoticeServiceProvider.php
@@ -7,39 +7,21 @@
namespace RocketLazyLoadPlugin\ServiceProvider;
-use RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
+use RocketLazyLoadPlugin\Dependencies\LaunchpadCore\Container\AbstractServiceProvider;
+use RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface;
+
/**
* Adds the Imagify notice to the container
- *
- * @since 2.0
- * @author Remy Perona
*/
-class ImagifyNoticeServiceProvider extends AbstractServiceProvider
-{
- /**
- * Data provided by the service provider
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @var array
- */
- protected $provides = [
- 'RocketLazyLoadPlugin\Admin\ImagifyNotice',
- ];
+class ImagifyNoticeServiceProvider extends AbstractServiceProvider {
- /**
- * Registers the Imagify notice in the container
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return void
- */
- public function register()
- {
- $this->getContainer()->add('RocketLazyLoadPlugin\Admin\ImagifyNotice')
- ->withArgument($this->getContainer()->get('template_path'));
- }
+ public function define() {
+ $this->register_service( \RocketLazyLoadPlugin\Admin\ImagifyNotice::class )
+ ->set_definition( function ( DefinitionInterface $instance ) {
+ $instance->addArguments( [
+ 'template_path',
+ ] );
+ } );
+ }
}
diff --git a/src/ServiceProvider/LazyloadServiceProvider.php b/src/ServiceProvider/LazyloadServiceProvider.php
index 6c68f0b..d044a1d 100644
--- a/src/ServiceProvider/LazyloadServiceProvider.php
+++ b/src/ServiceProvider/LazyloadServiceProvider.php
@@ -7,7 +7,7 @@
namespace RocketLazyLoadPlugin\ServiceProvider;
-use RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
+use RocketLazyLoadPlugin\Dependencies\LaunchpadCore\Container\AbstractServiceProvider;
/**
* Adds the lazyload library to the container
@@ -15,34 +15,11 @@
* @since 2.0
* @author Remy Perona
*/
-class LazyloadServiceProvider extends AbstractServiceProvider
-{
- /**
- * Data provided by the service provider
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @var array
- */
- protected $provides = [
- 'RocketLazyLoadPlugin\Dependencies\RocketLazyload\Assets',
- 'RocketLazyLoadPlugin\Dependencies\RocketLazyload\Image',
- 'RocketLazyLoadPlugin\Dependencies\RocketLazyload\Iframe',
- ];
+class LazyloadServiceProvider extends AbstractServiceProvider {
- /**
- * Registers the lazyload library in the container
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return void
- */
- public function register()
- {
- $this->getContainer()->add('RocketLazyLoadPlugin\Dependencies\RocketLazyload\Assets');
- $this->getContainer()->add('RocketLazyLoadPlugin\Dependencies\RocketLazyload\Image');
- $this->getContainer()->add('RocketLazyLoadPlugin\Dependencies\RocketLazyload\Iframe');
- }
+ public function define() {
+ $this->register_service( \RocketLazyLoadPlugin\Dependencies\RocketLazyload\Assets::class );
+ $this->register_service( \RocketLazyLoadPlugin\Dependencies\RocketLazyload\Image::class );
+ $this->register_service( \RocketLazyLoadPlugin\Dependencies\RocketLazyload\Iframe::class );
+ }
}
diff --git a/src/ServiceProvider/OptionServiceProvider.php b/src/ServiceProvider/OptionServiceProvider.php
deleted file mode 100644
index 99953a6..0000000
--- a/src/ServiceProvider/OptionServiceProvider.php
+++ /dev/null
@@ -1,45 +0,0 @@
-getContainer()->add('RocketLazyLoadPlugin\Options\OptionArray')
- ->withArgument($this->getContainer()->get('options')->get('_options'));
- }
-}
diff --git a/src/ServiceProvider/SubscribersServiceProvider.php b/src/ServiceProvider/SubscribersServiceProvider.php
index 6fcc15a..9db7bfa 100644
--- a/src/ServiceProvider/SubscribersServiceProvider.php
+++ b/src/ServiceProvider/SubscribersServiceProvider.php
@@ -7,54 +7,48 @@
namespace RocketLazyLoadPlugin\ServiceProvider;
-use RocketLazyLoadPlugin\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
+use RocketLazyLoadPlugin\Admin\ImagifyNotice;
+use RocketLazyLoadPlugin\Dependencies\LaunchpadCore\Container\AbstractServiceProvider;
+
+use RocketLazyLoadPlugin\Dependencies\League\Container\Definition\DefinitionInterface;
+use RocketLazyLoadPlugin\Dependencies\RocketLazyload\Assets;
+use RocketLazyLoadPlugin\Dependencies\RocketLazyload\Iframe;
+use RocketLazyLoadPlugin\Dependencies\RocketLazyload\Image;
+use RocketLazyLoadPlugin\Subscriber\ImagifyNoticeSubscriber;
+use RocketLazyLoadPlugin\Subscriber\LazyloadSubscriber;
+use RocketLazyLoadPlugin\Subscriber\ThirdParty\AMPSubscriber;
+
+class SubscribersServiceProvider extends AbstractServiceProvider {
+
+ public function get_common_subscribers(): array {
+ return [
+ AMPSubscriber::class,
+ ImagifyNoticeSubscriber::class,
+ LazyloadSubscriber::class
+ ];
+ }
+
+ public function define() {
+ $this->register_service( AMPSubscriber::class )
+ ->share();
+
+ $this->register_service( ImagifyNoticeSubscriber::class )
+ ->share()
+ ->set_definition( function ( DefinitionInterface $instance ) {
+ $instance->addArgument( ImagifyNotice::class );
+ } );
+
+ $this->register_service( LazyloadSubscriber::class )
+ ->share()
+ ->set_definition( function ( DefinitionInterface $instance ) {
+ $instance->addArguments( [
+ Assets::class,
+ Image::class,
+ Iframe::class
+ ]
+ );
+ }
+ );
+ }
-/**
- * Adds the subscribers to the container
- *
- * @since 2.0
- * @author Remy Perona
- */
-class SubscribersServiceProvider extends AbstractServiceProvider
-{
- /**
- * Data provided by the service provider
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @var array
- */
- protected $provides = [
- 'RocketLazyLoadPlugin\Subscriber\ThirdParty\AMPSubscriber',
- 'RocketLazyLoadPlugin\Subscriber\AdminPageSubscriber',
- 'RocketLazyLoadPlugin\Subscriber\ImagifyNoticeSubscriber',
- 'RocketLazyLoadPlugin\Subscriber\LazyloadSubscriber',
- ];
-
- /**
- * Registers the subscribers in the container
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return void
- */
- public function register()
- {
- $this->getContainer()->share('RocketLazyLoadPlugin\Subscriber\ThirdParty\AMPSubscriber');
-
- $this->getContainer()->share('RocketLazyLoadPlugin\Subscriber\AdminPageSubscriber')
- ->withArgument($this->getContainer()->get('RocketLazyLoadPlugin\Admin\AdminPage'))
- ->withArgument($this->getContainer()->get('plugin_basename'));
-
- $this->getContainer()->share('RocketLazyLoadPlugin\Subscriber\ImagifyNoticeSubscriber')
- ->withArgument($this->getContainer()->get('RocketLazyLoadPlugin\Admin\ImagifyNotice'));
-
- $this->getContainer()->share('RocketLazyLoadPlugin\Subscriber\LazyloadSubscriber')
- ->withArgument($this->getContainer()->get('RocketLazyLoadPlugin\Options\OptionArray'))
- ->withArgument($this->getContainer()->get('RocketLazyLoadPlugin\Dependencies\RocketLazyload\Assets'))
- ->withArgument($this->getContainer()->get('RocketLazyLoadPlugin\Dependencies\RocketLazyload\Image'))
- ->withArgument($this->getContainer()->get('RocketLazyLoadPlugin\Dependencies\RocketLazyload\Iframe'));
- }
}
diff --git a/src/Subscriber/AdminPageSubscriber.php b/src/Subscriber/AdminPageSubscriber.php
index 09de84d..6f7da29 100644
--- a/src/Subscriber/AdminPageSubscriber.php
+++ b/src/Subscriber/AdminPageSubscriber.php
@@ -2,7 +2,7 @@
namespace RocketLazyLoadPlugin\Subscriber;
-use RocketLazyLoadPlugin\EventManagement\SubscriberInterface;
+use RocketLazyLoadPlugin\Dependencies\LaunchpadCore\EventManagement\ClassicSubscriberInterface;
use RocketLazyLoadPlugin\Admin\AdminPage;
/**
@@ -11,7 +11,7 @@
* @since 2.0
* @author Remy Perona
*/
-class AdminPageSubscriber implements SubscriberInterface {
+class AdminPageSubscriber implements ClassicSubscriberInterface {
/**
* AdminPage instance
@@ -31,20 +31,21 @@ class AdminPageSubscriber implements SubscriberInterface {
*
* @var string
*/
- private $plugin_basename;
+ private static $plugin_basename;
/**
* Constructor
*
+ * @param AdminPage $page AdminPage instance.
+ * @param string $plugin_basename Plugin basename.
+ *
* @since 2.0
* @author Remy Perona
*
- * @param AdminPage $page AdminPage instance.
- * @param string $plugin_basename Plugin basename.
*/
public function __construct( AdminPage $page, $plugin_basename ) {
$this->page = $page;
- $this->plugin_basename = $plugin_basename;
+ self::$plugin_basename = $plugin_basename;
}
/**
@@ -52,22 +53,22 @@ public function __construct( AdminPage $page, $plugin_basename ) {
*
* @return array
*/
- public function getSubscribedEvents() {
+ public function get_subscribed_events(): array {
return [
- 'admin_init' => 'configure',
- 'admin_menu' => 'addAdminPage',
- "plugin_action_links_{$this->plugin_basename}" => 'addPluginPageLink',
- 'admin_enqueue_scripts' => 'enqueueAdminStyle',
+ 'admin_init' => 'configure',
+ 'admin_menu' => 'addAdminPage',
+ "plugin_action_links_" . self::$plugin_basename => 'addPluginPageLink',
+ 'admin_enqueue_scripts' => 'enqueueAdminStyle',
];
}
/**
* Registers the plugin settings in WordPress
*
- * @since 2.0
+ * @return void
* @author Remy Perona
*
- * @return void
+ * @since 2.0
*/
public function configure() {
$this->page->configure();
@@ -76,10 +77,10 @@ public function configure() {
/**
* Adds the admin page to the settings menu
*
- * @since 2.0
+ * @return void
* @author Remy Perona
*
- * @return void
+ * @since 2.0
*/
public function addAdminPage() {
add_options_page(
@@ -94,11 +95,12 @@ public function addAdminPage() {
/**
* Adds a link to the plugin settings on the plugins page
*
+ * @param array $actions Actions for the plugin.
+ *
+ * @return array
* @since 2.0
* @author Remy Perona
*
- * @param array $actions Actions for the plugin.
- * @return array
*/
public function addPluginPageLink( $actions ) {
array_unshift(
@@ -116,10 +118,11 @@ public function addPluginPageLink( $actions ) {
/**
* Enqueue the css for the option page
*
- * @since 2.0
+ * @param string $hook_suffix Current page hook.
+ *
* @author Remy Perona
*
- * @param string $hook_suffix Current page hook.
+ * @since 2.0
*/
public function enqueueAdminStyle( $hook_suffix ) {
if ( 'settings_page_rocket_lazyload' !== $hook_suffix ) {
diff --git a/src/Subscriber/ImagifyNoticeSubscriber.php b/src/Subscriber/ImagifyNoticeSubscriber.php
index c056b77..8a13f54 100644
--- a/src/Subscriber/ImagifyNoticeSubscriber.php
+++ b/src/Subscriber/ImagifyNoticeSubscriber.php
@@ -7,9 +7,9 @@
namespace RocketLazyLoadPlugin\Subscriber;
-defined('ABSPATH') || die('Cheatin\' uh?');
+defined( 'ABSPATH' ) || die( 'Cheatin\' uh?' );
-use RocketLazyLoadPlugin\EventManagement\SubscriberInterface;
+use RocketLazyLoadPlugin\Dependencies\LaunchpadCore\EventManagement\ClassicSubscriberInterface;
use RocketLazyLoadPlugin\Admin\ImagifyNotice;
/**
@@ -18,80 +18,76 @@
* @since 2.0
* @author Remy Perona
*/
-class ImagifyNoticeSubscriber implements SubscriberInterface
-{
- /**
- * ImagifyNotice instance
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @var ImagifyNotice
- */
- private $imagify_notice;
-
- /**
- * Constructor
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @param ImagifyNotice $imagify_notice ImagifyNotice instance.
- */
- public function __construct(ImagifyNotice $imagify_notice)
- {
- $this->imagify_notice = $imagify_notice;
- }
-
- /**
- * @inheritDoc
- */
- public function getSubscribedEvents()
- {
- return [
- 'admin_notices' => 'imagifyNotice',
- 'admin_footer-settings_page_rocket_lazyload' => 'dismissNoticeJS',
- 'wp_ajax_rocket_lazyload_ignore' => 'dismissBoxes',
- 'admin_post_rocket_lazyload_ignore' => 'dismissBoxes',
- ];
- }
-
- /**
- * Displays the Imagify notice
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return void
- */
- public function imagifyNotice()
- {
- $current_screen = get_current_screen();
-
- if ('admin_notices' === current_filter() && ( isset($current_screen) && 'settings_page_rocket_lazyload' !== $current_screen->base )) {
- return;
- }
-
- $boxes = get_user_meta(get_current_user_id(), 'rocket_lazyload_boxes', true);
-
- if (defined('IMAGIFY_VERSION') || in_array('rocket_lazyload_imagify_notice', (array) $boxes, true) || 1 === get_option('rocket_lazyload_dismiss_imagify_notice') || ! current_user_can('manage_options')) {
- return;
- }
-
- $this->imagify_notice->displayNotice();
- }
-
- /**
- * Inserts the javascript to dismiss the notice
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return void
- */
- public function dismissNoticeJS()
- {
- echo "";
- }
-
- /**
- * Saves the dismiss for the user
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @return void
- */
- public function dismissBoxes()
- {
- if (! isset($_GET['box'], $_GET['action'], $_GET['_wpnonce'])) {
- return;
- }
-
- if (! wp_verify_nonce(sanitize_key($_GET['_wpnonce']), 'rocket_lazyload_ignore_rocket_lazyload_imagify_notice')) {
- if (defined('DOING_AJAX')) {
- wp_send_json(['error' => 1]);
- } else {
- wp_nonce_ays('');
- }
- }
-
- $box = sanitize_key(wp_unslash($_GET['box']));
-
- if ('rocket_lazyload_imagify_notice' === $box) {
- update_option('rocket_lazyload_dismiss_imagify_notice', 0);
- }
-
- $actual = (array) get_user_meta(get_current_user_id(), 'rocket_lazyload_boxes', true);
- $actual = array_merge($actual, [ $box ]);
- $actual = array_filter($actual);
- $actual = array_unique($actual);
-
- update_user_meta(get_current_user_id(), 'rocket_lazyload_boxes', $actual);
- delete_transient($box);
-
- if (empty($GLOBALS['pagenow']) || 'admin-post.php' !== $GLOBALS['pagenow']) {
- return;
- }
-
- if (defined('DOING_AJAX')) {
- wp_send_json(['error' => 0]);
- } else {
- wp_safe_redirect(esc_url_raw(wp_get_referer()));
- die();
- }
- }
+ }
+
+ /**
+ * Saves the dismiss for the user
+ *
+ * @return void
+ * @author Remy Perona
+ *
+ * @since 2.0
+ */
+ public function dismissBoxes() {
+ if ( ! isset( $_GET['box'], $_GET['action'], $_GET['_wpnonce'] ) ) {
+ return;
+ }
+
+ if ( ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'rocket_lazyload_ignore_rocket_lazyload_imagify_notice' ) ) {
+ if ( defined( 'DOING_AJAX' ) ) {
+ wp_send_json( [ 'error' => 1 ] );
+ } else {
+ wp_nonce_ays( '' );
+ }
+ }
+
+ $box = sanitize_key( wp_unslash( $_GET['box'] ) );
+
+ if ( 'rocket_lazyload_imagify_notice' === $box ) {
+ update_option( 'rocket_lazyload_dismiss_imagify_notice', 0 );
+ }
+
+ $actual = (array) get_user_meta( get_current_user_id(), 'rocket_lazyload_boxes', true );
+ $actual = array_merge( $actual, [ $box ] );
+ $actual = array_filter( $actual );
+ $actual = array_unique( $actual );
+
+ update_user_meta( get_current_user_id(), 'rocket_lazyload_boxes', $actual );
+ delete_transient( $box );
+
+ if ( empty( $GLOBALS['pagenow'] ) || 'admin-post.php' !== $GLOBALS['pagenow'] ) {
+ return;
+ }
+
+ if ( defined( 'DOING_AJAX' ) ) {
+ wp_send_json( [ 'error' => 0 ] );
+ } else {
+ wp_safe_redirect( esc_url_raw( wp_get_referer() ) );
+ die();
+ }
+ }
}
diff --git a/src/Subscriber/LazyloadSubscriber.php b/src/Subscriber/LazyloadSubscriber.php
index 145c1af..3549de7 100644
--- a/src/Subscriber/LazyloadSubscriber.php
+++ b/src/Subscriber/LazyloadSubscriber.php
@@ -2,8 +2,9 @@
namespace RocketLazyLoadPlugin\Subscriber;
-use RocketLazyLoadPlugin\EventManagement\SubscriberInterface;
-use RocketLazyLoadPlugin\Options\OptionArray;
+use RocketLazyLoadPlugin\Dependencies\LaunchpadCore\EventManagement\ClassicSubscriberInterface;
+use RocketLazyLoadPlugin\Dependencies\LaunchpadFrameworkOptions\Interfaces\SettingsAwareInterface;
+use RocketLazyLoadPlugin\Dependencies\LaunchpadFrameworkOptions\Traits\SettingsAwareTrait;
use RocketLazyLoadPlugin\Dependencies\RocketLazyload\Assets;
use RocketLazyLoadPlugin\Dependencies\RocketLazyload\Image;
use RocketLazyLoadPlugin\Dependencies\RocketLazyload\Iframe;
@@ -14,17 +15,9 @@
* @since 2.0
* @author Remy Perona
*/
-class LazyloadSubscriber implements SubscriberInterface {
+class LazyloadSubscriber implements ClassicSubscriberInterface, SettingsAwareInterface {
- /**
- * OptionArray instance
- *
- * @since 2.0
- * @author Remy Perona
- *
- * @var OptionArray
- */
- private $option_array;
+ use SettingsAwareTrait;
/**
* Assets instance
@@ -59,19 +52,18 @@ class LazyloadSubscriber implements SubscriberInterface {
/**
* Constructor
*
- * @since 2.0
+ * @param Assets $assets Assets instance.
+ * @param Image $image Image instance.
+ * @param Iframe $iframe Iframe instance.
+ *
* @author Remy Perona
*
- * @param OptionArray $option_array OptionArray instance.
- * @param Assets $assets Assets instance.
- * @param Image $image Image instance.
- * @param Iframe $iframe Iframe instance.
+ * @since 2.0
*/
- public function __construct( OptionArray $option_array, Assets $assets, Image $image, Iframe $iframe ) {
- $this->option_array = $option_array;
- $this->assets = $assets;
- $this->image = $image;
- $this->iframe = $iframe;
+ public function __construct( Assets $assets, Image $image, Iframe $iframe ) {
+ $this->assets = $assets;
+ $this->image = $image;
+ $this->iframe = $iframe;
}
/**
@@ -79,7 +71,7 @@ public function __construct( OptionArray $option_array, Assets $assets, Image $i
*
* @return array
*/
- public function getSubscribedEvents() {
+ public function get_subscribed_events(): array {
return [
'wp_footer' => [
[ 'insertLazyloadScript', \ROCKET_LL_INT_MAX ],
@@ -96,13 +88,13 @@ public function getSubscribedEvents() {
/**
* Inserts the lazyload script in the footer
*
- * @since 2.0
+ * @return void
* @author Remy Perona
*
- * @return void
+ * @since 2.0
*/
public function insertLazyloadScript() {
- if ( ! $this->option_array->get( 'images' ) && ! $this->option_array->get( 'iframes' ) ) {
+ if ( ! $this->settings->get( 'images' ) && ! $this->settings->get( 'iframes' ) ) {
return;
}
@@ -113,10 +105,11 @@ public function insertLazyloadScript() {
/**
* Filters the threshold at which lazyload is triggered
*
- * @since 1.2
+ * @param int $threshold Threshold value.
+ *
* @author Remy Perona
*
- * @param int $threshold Threshold value.
+ * @since 1.2
*/
$threshold = apply_filters( 'rocket_lazyload_threshold', 300 );
@@ -130,33 +123,26 @@ public function insertLazyloadScript() {
'threshold' => $threshold,
];
- /**
- * Filters the use of native lazyload
- *
- * @since 2.3.3
- * @param bool $use_native True to enable native lazyload usage.
- */
- if ( apply_filters( 'rocket_use_native_lazyload', false ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
+ if ( $this->is_native_images() ) {
$inline_args['options'] = [
'use_native' => 'true',
];
}
- if ( $this->option_array->get( 'images' ) || $this->option_array->get( 'iframes' ) ) {
- // This filter is documented in src/Subscriber/LazyloadSubscriber.php.
- if ( apply_filters( 'rocket_use_native_lazyload', false ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
+ if ( $this->settings->get( 'images' ) || $this->settings->get( 'iframes' ) ) {
+ if ( $this->is_native_images() ) {
$inline_args['elements'] = isset( $inline_args['elements'] ) ? $inline_args['elements'] : [];
$inline_args['elements']['loading'] = '[loading=lazy]';
}
}
- if ( $this->option_array->get( 'images' ) ) {
+ if ( $this->settings->get( 'images' ) ) {
$inline_args['elements'] = isset( $inline_args['elements'] ) ? $inline_args['elements'] : [];
$inline_args['elements']['image'] = 'img[data-lazy-src]';
$inline_args['elements']['background_image'] = '.rocket-lazyload';
}
- if ( $this->option_array->get( 'iframes' ) ) {
+ if ( $this->settings->get( 'iframes' ) ) {
$inline_args['elements'] = isset( $inline_args['elements'] ) ? $inline_args['elements'] : [];
$inline_args['elements']['iframe'] = 'iframe[data-lazy-src]';
}
@@ -164,10 +150,11 @@ public function insertLazyloadScript() {
/**
* Filters the arguments array for the lazyload script options
*
- * @since 2.0
+ * @param array $inline_args Arguments used for the lazyload script options.
+ *
* @author Remy Perona
*
- * @param array $inline_args Arguments used for the lazyload script options.
+ * @since 2.0
*/
$inline_args = apply_filters( 'rocket_lazyload_script_args', $inline_args );
@@ -178,13 +165,13 @@ public function insertLazyloadScript() {
/**
* Inserts the Youtube thumbnail script in the footer
*
- * @since 2.0
+ * @return void
* @author Remy Perona
*
- * @return void
+ * @since 2.0
*/
public function insertYoutubeThumbnailScript() {
- if ( ! $this->option_array->get( 'youtube' ) ) {
+ if ( ! $this->settings->get( 'youtube' ) ) {
return;
}
@@ -195,17 +182,18 @@ public function insertYoutubeThumbnailScript() {
/**
* Filters the resolution of the YouTube thumbnail
*
- * @since 1.4.8
+ * @param string $thumbnail_resolution The resolution of the thumbnail. Accepted values: default, mqdefault, sddefault, hqdefault, maxresdefault
+ *
* @author Arun Basil Lal
*
- * @param string $thumbnail_resolution The resolution of the thumbnail. Accepted values: default, mqdefault, sddefault, hqdefault, maxresdefault
+ * @since 1.4.8
*/
$thumbnail_resolution = apply_filters( 'rocket_lazyload_youtube_thumbnail_resolution', 'hqdefault' );
$this->assets->insertYoutubeThumbnailScript(
[
'resolution' => $thumbnail_resolution,
- 'lazy_image' => (bool) $this->option_array->get( 'images' ),
+ 'lazy_image' => (bool) $this->settings->get( 'images' ),
]
);
}
@@ -213,10 +201,10 @@ public function insertYoutubeThumbnailScript() {
/**
* Inserts the no JS CSS compatibility in the header
*
- * @since 2.0.3
+ * @return void
* @author Remy Perona
*
- * @return void
+ * @since 2.0.3
*/
public function insertNoJSStyle() {
if ( ! $this->shouldLazyload() ) {
@@ -229,13 +217,13 @@ public function insertNoJSStyle() {
/**
* Inserts the Youtube thumbnail CSS in the header
*
- * @since 2.0
+ * @return void
* @author Remy Perona
*
- * @return void
+ * @since 2.0
*/
public function insertYoutubeThumbnailStyle() {
- if ( ! $this->option_array->get( 'youtube' ) ) {
+ if ( ! $this->settings->get( 'youtube' ) ) {
return;
}
@@ -254,10 +242,10 @@ public function insertYoutubeThumbnailStyle() {
/**
* Checks if lazyload should be applied
*
- * @since 2.0
+ * @return bool
* @author Remy Perona
*
- * @return bool
+ * @since 2.0
*/
private function shouldLazyload() {
if ( is_admin() || is_feed() || is_preview() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || ( defined( 'DONOTLAZYLOAD' ) && DONOTLAZYLOAD ) ) {
@@ -271,10 +259,11 @@ private function shouldLazyload() {
/**
* Filters the lazyload application
*
- * @since 2.0
+ * @param bool $do_rocket_lazyload True to apply lazyload, false otherwise.
+ *
* @author Remy Perona
*
- * @param bool $do_rocket_lazyload True to apply lazyload, false otherwise.
+ * @since 2.0
*/
if ( ! apply_filters( 'do_rocket_lazyload', true ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
return false;
@@ -286,10 +275,10 @@ private function shouldLazyload() {
/**
* Checks if current page is a page builder editor.
*
- * @since 2.2.2
+ * @return bool
* @author Remy Perona
*
- * @return bool
+ * @since 2.2.2
*/
private function isPageBuilder() {
// Exclude Page Builders editors.
@@ -311,10 +300,10 @@ private function isPageBuilder() {
/**
* Gets the content to lazyload
*
- * @since 2.0
+ * @return void
* @author Remy Perona
*
- * @return void
+ * @since 2.0
*/
public function lazyload() {
if ( ! $this->shouldLazyload() ) {
@@ -327,25 +316,26 @@ public function lazyload() {
/**
* Applies lazyload on the provided content
*
+ * @param string $html HTML content.
+ *
+ * @return string
* @since 2.0
* @author Remy Perona
*
- * @param string $html HTML content.
- * @return string
*/
public function lazyloadBuffer( $html ) {
$buffer = $this->ignoreScripts( $html );
$buffer = $this->ignoreNoscripts( $buffer );
- if ( $this->option_array->get( 'images' ) ) {
- $html = $this->image->lazyloadImages( $html, $buffer );
+ if ( $this->settings->get( 'images' ) ) {
+ $html = $this->image->lazyloadImages( $html, $buffer , $this->is_native_images() );
$html = $this->image->lazyloadPictures( $html, $buffer );
$html = $this->image->lazyloadBackgroundImages( $html, $buffer );
}
- if ( $this->option_array->get( 'iframes' ) ) {
+ if ( $this->settings->get( 'iframes' ) ) {
$args = [
- 'youtube' => $this->option_array->get( 'youtube' ),
+ 'youtube' => $this->settings->get( 'youtube' ),
];
$html = $this->iframe->lazyloadIframes( $html, $buffer, $args );
@@ -357,11 +347,12 @@ public function lazyloadBuffer( $html ) {
/**
* Applies lazyload on responsive images attributes srcset and sizes
*
+ * @param string $html Image HTML.
+ *
+ * @return string
* @since 2.0
* @author Remy Perona
*
- * @param string $html Image HTML.
- * @return string
*/
public function lazyloadResponsive( $html ) {
return $this->image->lazyloadResponsiveAttributes( $html );
@@ -370,17 +361,17 @@ public function lazyloadResponsive( $html ) {
/**
* Applies lazyload on WordPress smilies
*
- * @since 2.0
+ * @return void
* @author Remy Perona
*
- * @return void
+ * @since 2.0
*/
public function lazyloadSmilies() {
if ( ! $this->shouldLazyload() ) {
return;
}
- if ( ! $this->option_array->get( 'images' ) ) {
+ if ( ! $this->settings->get( 'images' ) ) {
return;
}
@@ -404,6 +395,7 @@ public function lazyloadSmilies() {
* Remove inline scripts from the HTML to parse
*
* @param string $html HTML content.
+ *
* @return string
*/
private function ignoreScripts( $html ) {
@@ -414,9 +406,24 @@ private function ignoreScripts( $html ) {
* Remove noscript tags from the HTML to parse
*
* @param string $html HTML content.
+ *
* @return string
*/
private function ignoreNoscripts( $html ) {
return preg_replace( '#(?:.+) #Umsi', '', $html );
}
+
+ /**
+ * Checks if native lazyload is enabled for images
+ **
+ * @return bool
+ */
+ private function is_native_images(): bool {
+ /**
+ * Filters the use of native lazyload for images
+ *
+ * @param bool $use_native True to use native lazyload for images, false otherwise.
+ */
+ return (bool) apply_filters( 'rocket_use_native_lazyload', false );
+ }
}
diff --git a/src/Subscriber/ThirdParty/AMPSubscriber.php b/src/Subscriber/ThirdParty/AMPSubscriber.php
index 04016df..0cdf6bc 100644
--- a/src/Subscriber/ThirdParty/AMPSubscriber.php
+++ b/src/Subscriber/ThirdParty/AMPSubscriber.php
@@ -2,8 +2,8 @@
namespace RocketLazyLoadPlugin\Subscriber\ThirdParty;
-use RocketLazyLoadPlugin\EventManagement\EventManager;
-use RocketLazyLoadPlugin\EventManagement\EventManagerAwareSubscriberInterface;
+use RocketLazyLoadPlugin\Dependencies\LaunchpadCore\EventManagement\EventManagerAwareSubscriberInterface;
+use RocketLazyLoadPlugin\Dependencies\LaunchpadCore\EventManagement\EventManager;
/**
* Manages compatibility with the AMP plugin
@@ -25,7 +25,7 @@ class AMPSubscriber implements EventManagerAwareSubscriberInterface {
*
* @return array
*/
- public function getSubscribedEvents() {
+ public function get_subscribed_events() {
return [
'wp' => 'disableIfAMP',
];
@@ -35,34 +35,35 @@ public function getSubscribedEvents() {
* Set the WordPress event manager for the subscriber.
*
* @param EventManager $event_manager EventManager instance.
+ *
* @return void
*/
- public function setEventManager( EventManager $event_manager ) {
+ public function set_event_manager( EventManager $event_manager ) {
$this->event_manager = $event_manager;
}
/**
* Disable if on AMP page
*
- * @since 2.0.2
+ * @return void
* @author Remy Perona
*
- * @return void
+ * @since 2.0.2
*/
public function disableIfAMP() {
if ( $this->isAmpEndpoint() ) {
- $this->event_manager->addCallback( 'do_rocket_lazyload', '__return_false' );
- $this->event_manager->addCallback( 'do_rocket_lazyload_iframes', '__return_false' );
+ $this->event_manager->add_callback( 'do_rocket_lazyload', '__return_false' );
+ $this->event_manager->add_callback( 'do_rocket_lazyload_iframes', '__return_false' );
}
}
/**
* Checks if current page uses AMP
*
- * @since 2.0
+ * @return boolean
* @author Remy Perona
*
- * @return boolean
+ * @since 2.0
*/
private function isAmpEndpoint() {
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
diff --git a/tests/Integration/bootstrap.php b/tests/Integration/bootstrap.php
index a1f8175..4e45159 100644
--- a/tests/Integration/bootstrap.php
+++ b/tests/Integration/bootstrap.php
@@ -5,8 +5,8 @@
* @package RocketlazyloadPlugin\Tests\Integration
*/
-if (version_compare(phpversion(), '5.6.0', '<')) {
- die('Rocket Lazyload Plugin Integration Tests require PHP 5.6 or higher.');
+if (version_compare(phpversion(), '7.3.0', '<')) {
+ die('Rocket Lazyload Plugin Integration Tests require PHP 7.3 or higher.');
}
// Define testing constants.
diff --git a/tests/Unit/boostrap.php b/tests/Unit/bootstrap.php
similarity index 83%
rename from tests/Unit/boostrap.php
rename to tests/Unit/bootstrap.php
index 742a274..b4004df 100644
--- a/tests/Unit/boostrap.php
+++ b/tests/Unit/bootstrap.php
@@ -5,8 +5,8 @@
* @package RocketLazyload\Tests\Unit
*/
-if (version_compare(phpversion(), '5.6.0', '<')) {
- die('Rocket Lazyload Plugin Unit Tests require PHP 5.6 or higher.');
+if (version_compare(phpversion(), '7.3.0', '<')) {
+ die('Rocket Lazyload Plugin Unit Tests require PHP 7.3 or higher.');
}
define('RLL_PLUGIN_TESTS_ROOT', __DIR__);
diff --git a/views/admin-page.php b/views/admin-page.php
index d1a1a66..6dc7f3a 100644
--- a/views/admin-page.php
+++ b/views/admin-page.php
@@ -12,12 +12,15 @@
$options = [
'images' => [
'label' => __('Images', 'rocket-lazy-load'),
+ 'value' => $this->settings->get('images'),
],
'iframes' => [
'label' => __('Iframes & Videos', 'rocket-lazy-load'),
+ 'value' => $this->settings->get('iframes'),
],
'youtube' => [
'label' => __('Replace Youtube videos by thumbnail', 'rocket-lazy-load'),
+ 'value' => $this->settings->get('youtube'),
],
];
@@ -48,9 +51,10 @@