Skip to content

Commit

Permalink
Release v3.15.10 (PR #6482)
Browse files Browse the repository at this point in the history
  • Loading branch information
wordpressfan committed Mar 19, 2024
2 parents d7f250d + 631fc90 commit e159421
Show file tree
Hide file tree
Showing 103 changed files with 5,727 additions and 3,767 deletions.
2 changes: 1 addition & 1 deletion assets/js/lazyload-scripts.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"wpackagist-plugin/amp": "^1.1.4",
"wpackagist-plugin/hummingbird-performance": "2.0.1",
"wpackagist-plugin/jetpack": "9.3.2",
"wpackagist-plugin/pdf-embedder": "^4.6",
"wpackagist-plugin/pdf-embedder": "4.6.*",
"wpackagist-plugin/simple-custom-css": "^4.0.3",
"wpackagist-plugin/spinupwp": "^1.1",
"wpackagist-plugin/woocommerce": "^8",
Expand Down
2 changes: 1 addition & 1 deletion dynamic-lists-delayjs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dynamic-lists.json

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion inc/Dependencies/RocketLazyload/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,20 @@ public function getYoutubeThumbnailScript( $args = [] ) {
}
}

return "<script>function lazyLoadThumb(e,alt){var t='{$image}',a='<button class=\"play\" aria-label=\"play Youtube video\"></button>';t=t.replace('alt=\"\"','alt=\"'+alt+'\"');return t.replace(\"ID\",e)+a}function lazyLoadYoutubeIframe(){var e=document.createElement(\"iframe\"),t=\"ID?autoplay=1\";t+=0===this.parentNode.dataset.query.length?'':'&'+this.parentNode.dataset.query;e.setAttribute(\"src\",t.replace(\"ID\",this.parentNode.dataset.src)),e.setAttribute(\"frameborder\",\"0\"),e.setAttribute(\"allowfullscreen\",\"1\"),e.setAttribute(\"allow\", \"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\"),this.parentNode.parentNode.replaceChild(e,this.parentNode)}document.addEventListener(\"DOMContentLoaded\",function(){var e,t,p,a=document.getElementsByClassName(\"rll-youtube-player\");for(t=0;t<a.length;t++)e=document.createElement(\"div\"),e.setAttribute(\"data-id\",a[t].dataset.id),e.setAttribute(\"data-query\", a[t].dataset.query),e.setAttribute(\"data-src\", a[t].dataset.src),e.innerHTML=lazyLoadThumb(a[t].dataset.id,a[t].dataset.alt),a[t].appendChild(e),p=e.querySelector('.play'),p.onclick=lazyLoadYoutubeIframe});</script>";
/**
* Filters the patterns excluded from lazyload for youtube thumbnails.
*
* @param array $excluded_patterns Array of excluded patterns.
*/
$excluded_patterns = apply_filters( 'rocket_lazyload_exclude_youtube_thumbnail', [] );

if ( ! is_array( $excluded_patterns ) ) {
$excluded_patterns = [];
}

$excluded_patterns = wp_json_encode( $excluded_patterns );

return "<script>function lazyLoadThumb(e,alt,l){var t='{$image}',a='<button class=\"play\" aria-label=\"play Youtube video\"></button>';if(l){t=t.replace('data-lazy-','');t=t.replace('loading=\"lazy\"','');t=t.replace(/<noscript>.*?<\/noscript>/g,'');}t=t.replace('alt=\"\"','alt=\"'+alt+'\"');return t.replace(\"ID\",e)+a}function lazyLoadYoutubeIframe(){var e=document.createElement(\"iframe\"),t=\"ID?autoplay=1\";t+=0===this.parentNode.dataset.query.length?\"\":\"&\"+this.parentNode.dataset.query;e.setAttribute(\"src\",t.replace(\"ID\",this.parentNode.dataset.src)),e.setAttribute(\"frameborder\",\"0\"),e.setAttribute(\"allowfullscreen\",\"1\"),e.setAttribute(\"allow\",\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\"),this.parentNode.parentNode.replaceChild(e,this.parentNode)}document.addEventListener(\"DOMContentLoaded\",function(){var exclusions={$excluded_patterns};var e,t,p,u,l,a=document.getElementsByClassName(\"rll-youtube-player\");for(t=0;t<a.length;t++)(e=document.createElement(\"div\")),(u='{$image_url}'),(u=u.replace('ID',a[t].dataset.id)),(l=exclusions.some(exclusion=>u.includes(exclusion))),e.setAttribute(\"data-id\",a[t].dataset.id),e.setAttribute(\"data-query\",a[t].dataset.query),e.setAttribute(\"data-src\",a[t].dataset.src),(e.innerHTML=lazyLoadThumb(a[t].dataset.id,a[t].dataset.alt,l)),a[t].appendChild(e),(p=e.querySelector(\".play\")),(p.onclick=lazyLoadYoutubeIframe)});</script>";
}

/**
Expand Down
59 changes: 59 additions & 0 deletions inc/Engine/Debug/DebugSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace WP_Rocket\Engine\Debug;

use WP_Rocket\Event_Management\Subscriber_Interface;

class DebugSubscriber implements Subscriber_Interface {

/**
* Returns an array of events this listens to
*
* @return array
*/
public static function get_subscribed_events(): array {
return [
'wp_rocket_first_install' => 'on_first_install',
'wp_rocket_upgrade' => [ 'on_upgrade', 10, 2 ],
];
}

/**
* Adds the debug option on first install.
*
* @return void
*/
public function on_first_install(): void {
$this->add_debug_options();
}

/**
* Adds the debug option on upgrade.
*
* @param string $new_version New plugin version.
* @param string $old_version Previous plugin version.
*
* @return void
*/
public function on_upgrade( $new_version, $old_version ): void {
if ( version_compare( $old_version, '3.16', '>=' ) ) {
return;
}

$this->add_debug_options();
}

/**
* Adds the debug option.
*
* @return boolean
*/
private function add_debug_options(): bool {
return add_option(
'wp_rocket_debug',
[
'last_rucss_job_added' => '',
]
);
}
}
134 changes: 134 additions & 0 deletions inc/Engine/Debug/RUCSS/Subscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

namespace WP_Rocket\Engine\Debug\RUCSS;

use WP_Rocket\Admin\{Options, Options_Data};
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\Logger\Logger;

class Subscriber implements Subscriber_Interface {

/**
* Plugin options instance.
*
* @var Options_Data
*/
protected $options;

/**
* Options instance.
*
* @var Options
*/
private $options_api;

/**
* Instantiate the class
*
* @param Options_Data $options Options instance.
* @param Options $options_api Options instance.
*/
public function __construct( Options_Data $options, Options $options_api ) {
$this->options = $options;
$this->options_api = $options_api;
}

/**
* Returns an array of events this listens to
*
* @return array
*/
public static function get_subscribed_events(): array {
return [
'rocket_last_rucss_job_added_time' => [ 'log_last_added_job_time', 10, 2 ],
'rocket_rucss_process_pending_jobs_start' => [ 'log_process_pending_job_start_time', 10, 1 ],
'rocket_rucss_process_pending_jobs_end' => [ 'log_process_pending_job_end_time', 10, 1 ],
'rocket_rucss_check_job_status_end' => [ 'log_check_job_status_end', 10, 1 ],
'rocket_rucss_process_on_submit_jobs_start' => [ 'log_process_on_submit_start', 10, 1 ],
'rocket_rucss_process_on_submit_jobs_end' => [ 'log_process_on_submit_end', 10, 1 ],
];
}

/**
* Saves the last time a new job was added to rucss table.
*
* @param mixed $is_success New job status: ID of inserted row if successfully added; false otherwise.
* @param string $timestamp Current timestamp.
* @return void
*/
public function log_last_added_job_time( $is_success, $timestamp ) {
if ( Logger::debug_enabled() ) {
if ( ! $is_success ) {
return;
}

$this->options->set( 'last_rucss_job_added', $timestamp );
$this->options_api->set( 'debug', $this->options->get_options() );
}
}

/**
* Saves the time when the process pending jobs started.
*
* @param string $timestamp Current timestamp.
* @return void
*/
public function log_process_pending_job_start_time( $timestamp ) {
if ( Logger::debug_enabled() ) {
$this->options->set( 'rucss_process_pending_jobs_start', $timestamp );
$this->options_api->set( 'debug', $this->options->get_options() );
}
}

/**
* Saves the time when the process pending jobs ended.
*
* @param string $timestamp Current timestamp.
* @return void
*/
public function log_process_pending_job_end_time( $timestamp ) {
if ( Logger::debug_enabled() ) {
$this->options->set( 'rucss_process_pending_jobs_end', $timestamp );
$this->options_api->set( 'debug', $this->options->get_options() );
}
}

/**
* Saves the time when the check job status ended.
*
* @param string $timestamp Current timestamp.
* @return void
*/
public function log_check_job_status_end( $timestamp ) {
if ( Logger::debug_enabled() ) {
$this->options->set( 'rucss_check_job_status_end', $timestamp );
$this->options_api->set( 'debug', $this->options->get_options() );
}
}

/**
* Saves the time when the process on submit jobs started.
*
* @param string $timestamp Current timestamp.
* @return void
*/
public function log_process_on_submit_start( $timestamp ) {
if ( Logger::debug_enabled() ) {
$this->options->set( 'rucss_process_on_submit_jobs_start', $timestamp );
$this->options_api->set( 'debug', $this->options->get_options() );
}
}

/**
* Saves the time when the process on submit jobs ended.
*
* @param string $timestamp Current timestamp.
* @return void
*/
public function log_process_on_submit_end( $timestamp ) {
if ( Logger::debug_enabled() ) {
$this->options->set( 'rucss_process_on_submit_jobs_end', $timestamp );
$this->options_api->set( 'debug', $this->options->get_options() );
}
}
}
62 changes: 62 additions & 0 deletions inc/Engine/Debug/Resolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace WP_Rocket\Engine\Debug;

use WP_Rocket\Admin\Options_Data;

/**
* Resolver.
*/
class Resolver {

/**
* Array of WP Rocket Options.
*
* @var array
*/
private $options_services = [
'remove_unused_css' => [
'service' => 'rucss_debug_subscriber',
'class' => 'WP_Rocket\Engine\Debug\RUCSS\Subscriber',
],
];

/**
* Debug options instance.
*
* @var Options_Data
*/
private $options;

/**
* Instantiate the class.
*
* @param Options_Data $options Options instance.
*/
public function __construct( Options_Data $options ) {
$this->options = $options;
}

/**
* Ships an array of available services.
*
* @return array Array of services.
*/
public function get_services(): array {
$set_services = [];

if ( empty( $this->options_services ) ) {
return [];
}

foreach ( $this->options_services as $option => $services ) {
if ( ! (bool) $this->options->get( $option, 0 ) ) {
continue;
}

$set_services[] = $services;
}

return $set_services;
}
}
72 changes: 72 additions & 0 deletions inc/Engine/Debug/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
namespace WP_Rocket\Engine\Debug;

use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\BootableServiceProviderInterface;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\Debug\Resolver;

/**
* Service provider for Debug
*/
class ServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface {

/**
* The provides array is a way to let the container
* know that a service is provided by this service
* provider. Every service that is registered via
* this service provider must have an alias added
* to this array or it will be ignored.
*
* @var array
*/
protected $provides = [
'debug_subscriber',
];

/**
* Array of available debug services.
*
* @var array
*/
protected $services;

/**
* Register the service in the provider array
*
* @return void
*/
public function boot() {
$this->services = $this->getContainer()->get( 'debug_resolver' )->get_services();

if ( empty( $this->services ) ) {
return;
}

foreach ( $this->services as $service ) {
$this->provides[] = $service['service'];
}
}

/**
* Registers items with the container
*
* @return void
*/
public function register() {
$this->container->add( 'debug_subscriber', DebugSubscriber::class );

if ( empty( $this->services ) ) {
return;
}

$this->container->add( 'options_debug', Options_Data::class )
->addArgument( $this->container->get( 'options_api' )->get( 'debug', [] ) );

foreach ( $this->services as $service ) {
$this->getContainer()->add( $service['service'], $service['class'] )
->addArgument( $this->getContainer()->get( 'options_debug' ) )
->addArgument( $this->getContainer()->get( 'options_api' ) );
}
}
}
Loading

0 comments on commit e159421

Please sign in to comment.