add wp-rocket
This commit is contained in:
63
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/AbstractNoCacheHost.php
vendored
Normal file
63
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/AbstractNoCacheHost.php
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Hostings;
|
||||
|
||||
use WP_Rocket\Engine\Activation\ActivationInterface;
|
||||
use WP_Rocket\Engine\Deactivation\DeactivationInterface;
|
||||
use WP_Rocket\Event_Management\Event_Manager;
|
||||
use WP_Rocket\Event_Management\Event_Manager_Aware_Subscriber_Interface;
|
||||
use WP_Rocket\ThirdParty\ReturnTypesTrait;
|
||||
|
||||
abstract class AbstractNoCacheHost implements ActivationInterface, DeactivationInterface, Event_Manager_Aware_Subscriber_Interface {
|
||||
use ReturnTypesTrait;
|
||||
|
||||
/**
|
||||
* Event Manager instance
|
||||
*
|
||||
* @var Event_Manager
|
||||
*/
|
||||
protected $event_manager;
|
||||
|
||||
/**
|
||||
* Actions to perform on plugin activation
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function activate() {
|
||||
add_action( 'rocket_activation', [ $this, 'no_cache_config' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Actions to perform on plugin deactivation
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deactivate() {
|
||||
add_action( 'rocket_deactivation', [ $this, 'no_cache_config' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent writing in advanced-cache.php & wp-config.php when on self-caching host.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function no_cache_config() {
|
||||
add_filter( 'rocket_set_wp_cache_constant', [ $this, 'return_false' ] );
|
||||
add_filter( 'rocket_generate_advanced_cache_file', [ $this, 'return_false' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the event manager for the subscriber.
|
||||
*
|
||||
* @param Event_Manager $event_manager Event Manager instance.
|
||||
*/
|
||||
public function set_event_manager( Event_Manager $event_manager ) {
|
||||
$this->event_manager = $event_manager;
|
||||
}
|
||||
}
|
117
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/Cloudways.php
vendored
Normal file
117
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/Cloudways.php
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Hostings;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
use WP_Rocket\ThirdParty\NullSubscriber;
|
||||
|
||||
/**
|
||||
* Compatibility class for Cloudways Varnish
|
||||
*
|
||||
* @since 3.5.5
|
||||
*/
|
||||
class Cloudways extends NullSubscriber implements Subscriber_Interface {
|
||||
|
||||
/**
|
||||
* Array of events this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.5.5
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'rocket_display_input_varnish_auto_purge' => 'return_false',
|
||||
'do_rocket_varnish_http_purge' => 'should_purge',
|
||||
'rocket_varnish_field_settings' => 'varnish_addon_title',
|
||||
'rocket_varnish_ip' => 'varnish_ip',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the Varnish server is up and running.
|
||||
*
|
||||
* @since 3.6.1
|
||||
*/
|
||||
private static function is_varnish_running() {
|
||||
if ( ! isset( $_SERVER['HTTP_X_VARNISH'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! isset( $_SERVER['HTTP_X_APPLICATION'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ( 'varnishpass' !== trim( strtolower( $_SERVER['HTTP_X_APPLICATION'] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns false
|
||||
*
|
||||
* @since 3.5.5
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function return_false() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns should purge Varnish.
|
||||
*
|
||||
* @since 3.5.5
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public function should_purge() {
|
||||
return self::is_varnish_running();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays custom title for the Varnish add-on
|
||||
*
|
||||
* @since 3.5.5
|
||||
*
|
||||
* @param array $settings Array of settings for Varnish.
|
||||
* @return array
|
||||
*/
|
||||
public function varnish_addon_title( array $settings ) {
|
||||
if ( ! self::is_varnish_running() ) {
|
||||
$settings['varnish_auto_purge']['title'] = sprintf(
|
||||
// Translators: %s = Hosting name.
|
||||
__( 'Varnish auto-purge will be automatically enabled once Varnish is enabled on your %s server.', 'rocket' ),
|
||||
'Cloudways'
|
||||
);
|
||||
|
||||
return $settings;
|
||||
}
|
||||
$settings['varnish_auto_purge']['title'] = sprintf(
|
||||
// Translators: %s = Hosting name.
|
||||
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
|
||||
'Cloudways'
|
||||
);
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Cloudways Varnish IP to varnish IPs array
|
||||
*
|
||||
* @since 3.5.5
|
||||
*
|
||||
* @param array $varnish_ip Varnish IP.
|
||||
* @return array
|
||||
*/
|
||||
public function varnish_ip( $varnish_ip ) {
|
||||
if ( ! self::is_varnish_running() ) {
|
||||
return $varnish_ip;
|
||||
}
|
||||
if ( ! is_array( $varnish_ip ) ) {
|
||||
$varnish_ip = (array) $varnish_ip;
|
||||
}
|
||||
|
||||
$varnish_ip[] = '127.0.0.1:8080';
|
||||
|
||||
return $varnish_ip;
|
||||
}
|
||||
}
|
112
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/Dreampress.php
vendored
Normal file
112
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/Dreampress.php
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Hostings;
|
||||
|
||||
/**
|
||||
* Compatibility class for DreamPress
|
||||
*
|
||||
* @since 3.7.2
|
||||
*/
|
||||
class Dreampress extends AbstractNoCacheHost {
|
||||
/**
|
||||
* Array of events this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.7.2
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'do_rocket_varnish_http_purge' => 'return_true',
|
||||
'rocket_varnish_field_settings' => 'set_varnish_addon_title',
|
||||
'rocket_display_input_varnish_auto_purge' => 'return_false',
|
||||
'rocket_varnish_ip' => 'set_varnish_host',
|
||||
'rocket_set_wp_cache_constant' => 'return_false',
|
||||
'do_rocket_generate_caching_files' => 'return_false',
|
||||
'rocket_generate_advanced_cache_file' => 'return_false',
|
||||
'rocket_cache_mandatory_cookies' => [ 'return_empty_array', PHP_INT_MAX ],
|
||||
'rocket_htaccess_mod_expires' => [ 'remove_htaccess_html_expire', 5 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the text on the Varnish one-click block.
|
||||
*
|
||||
* @since 3.7.2
|
||||
*
|
||||
* @param array $settings Field settings data.
|
||||
*
|
||||
* @return array modified field settings data.
|
||||
*/
|
||||
public function set_varnish_addon_title( $settings ) {
|
||||
$settings['varnish_auto_purge']['title'] = sprintf(
|
||||
// Translators: %s = Hosting name.
|
||||
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
|
||||
'DreamPress'
|
||||
);
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Varnish host to localhost
|
||||
*
|
||||
* @since 3.7.2
|
||||
*
|
||||
* @param mixed $hosts Varnish hosts.
|
||||
* @return array
|
||||
*/
|
||||
public function set_varnish_host( $hosts ) {
|
||||
if ( ! is_array( $hosts ) ) {
|
||||
$hosts = (array) $hosts;
|
||||
}
|
||||
|
||||
if ( in_array( 'localhost', $hosts, true ) ) {
|
||||
return $hosts;
|
||||
}
|
||||
|
||||
$hosts[] = 'localhost';
|
||||
|
||||
return $hosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove expiration on HTML to prevent issue with Varnish cache.
|
||||
*
|
||||
* @since 3.7.2
|
||||
*
|
||||
* @param string $rules htaccess rules.
|
||||
*
|
||||
* @return string Updated htaccess rules.
|
||||
*/
|
||||
public function remove_htaccess_html_expire( $rules ) {
|
||||
$rules = preg_replace( '@\s*#\s*Your document html@', '', $rules );
|
||||
$rules = preg_replace( '@\s*ExpiresByType text/html\s*"access plus \d+ (seconds|minutes|hour|week|month|year)"@', '', $rules );
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs these actions during the plugin activation
|
||||
*
|
||||
* @since 3.7.2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function activate() {
|
||||
parent::activate();
|
||||
|
||||
add_action( 'rocket_activation', [ $this, 'activate_no_htaccess_html_expire' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove expiration on HTML on activation to prevent issue with Varnish cache.
|
||||
*
|
||||
* @since 3.7.2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function activate_no_htaccess_html_expire() {
|
||||
add_filter( 'rocket_htaccess_mod_expires', [ $this, 'remove_htaccess_html_expire' ] );
|
||||
}
|
||||
}
|
113
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/HostResolver.php
vendored
Normal file
113
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/HostResolver.php
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Hostings;
|
||||
|
||||
/**
|
||||
* Host Resolver.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*/
|
||||
class HostResolver {
|
||||
|
||||
/**
|
||||
* Name of the current host service.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $hostname = '';
|
||||
|
||||
/**
|
||||
* Get the name of an identifiable hosting service.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @param bool $ignore_cached_hostname (optional) Don't use cached hostname when true.
|
||||
*
|
||||
* @return string Name of the hosting service or '' if no service is recognized.
|
||||
*/
|
||||
public static function get_host_service( $ignore_cached_hostname = false ) {
|
||||
|
||||
if ( ! $ignore_cached_hostname && ! empty( self::$hostname ) ) {
|
||||
return self::$hostname;
|
||||
}
|
||||
|
||||
if ( isset( $_SERVER['cw_allowed_ip'] ) ) {
|
||||
self::$hostname = 'cloudways';
|
||||
|
||||
return 'cloudways';
|
||||
}
|
||||
|
||||
if ( rocket_get_constant( 'IS_PRESSABLE' ) ) {
|
||||
self::$hostname = 'pressable';
|
||||
|
||||
return 'pressable';
|
||||
}
|
||||
|
||||
if ( getenv( 'SPINUPWP_CACHE_PATH' ) ) {
|
||||
self::$hostname = 'spinupwp';
|
||||
|
||||
return 'spinupwp';
|
||||
}
|
||||
|
||||
if (
|
||||
(
|
||||
class_exists( 'WpeCommon' )
|
||||
&&
|
||||
function_exists( 'wpe_param' )
|
||||
)
|
||||
) {
|
||||
self::$hostname = 'wpengine';
|
||||
|
||||
return 'wpengine';
|
||||
}
|
||||
|
||||
if ( rocket_has_constant( 'O2SWITCH_VARNISH_PURGE_KEY' ) ) {
|
||||
self::$hostname = 'o2switch';
|
||||
|
||||
return 'o2switch';
|
||||
}
|
||||
|
||||
if ( rocket_get_constant( 'WPCOMSH_VERSION' ) ) {
|
||||
self::$hostname = 'wordpresscom';
|
||||
|
||||
return 'wordpresscom';
|
||||
}
|
||||
|
||||
if (
|
||||
rocket_get_constant( '\Savvii\CacheFlusherPlugin::NAME_FLUSH_NOW' )
|
||||
&&
|
||||
rocket_get_constant( '\Savvii\CacheFlusherPlugin::NAME_DOMAINFLUSH_NOW' )
|
||||
) {
|
||||
return 'savvii';
|
||||
}
|
||||
|
||||
if ( self::is_dreampress() ) {
|
||||
return 'dreampress';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current host is DreamPress
|
||||
*
|
||||
* @since 3.7.2
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private static function is_dreampress() {
|
||||
if ( ! isset( $_SERVER['DH_USER'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
! rocket_get_constant( 'WP_ROCKET_IS_TESTING', false )
|
||||
&&
|
||||
'dp-' !== substr( gethostname(), 0, 3 )
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 'wp_' === substr( sanitize_key( wp_unslash( $_SERVER['DH_USER'] ) ), 0, 3 );
|
||||
}
|
||||
}
|
46
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/HostSubscriberFactory.php
vendored
Normal file
46
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/HostSubscriberFactory.php
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Hostings;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
use WP_Rocket\ThirdParty\NullSubscriber;
|
||||
use WP_Rocket\ThirdParty\SubscriberFactoryInterface;
|
||||
|
||||
/**
|
||||
* Host Subscriber Factory
|
||||
*
|
||||
* @since 3.6.3
|
||||
*/
|
||||
class HostSubscriberFactory implements SubscriberFactoryInterface {
|
||||
/**
|
||||
* Get a Subscriber Interface object.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @return Subscriber_Interface A Subscribe Interface for the current host.
|
||||
*/
|
||||
public function get_subscriber() {
|
||||
$host_service = HostResolver::get_host_service( rocket_get_constant( 'WP_ROCKET_IS_TESTING', false ) );
|
||||
|
||||
switch ( $host_service ) {
|
||||
case 'pressable':
|
||||
return new Pressable();
|
||||
case 'cloudways':
|
||||
return new Cloudways();
|
||||
case 'spinupwp':
|
||||
return new SpinUpWP();
|
||||
case 'wpengine':
|
||||
return new WPEngine();
|
||||
case 'o2switch':
|
||||
return new O2Switch();
|
||||
case 'wordpresscom':
|
||||
return new WordPressCom();
|
||||
case 'savvii':
|
||||
return new Savvii();
|
||||
case 'dreampress':
|
||||
return new Dreampress();
|
||||
default:
|
||||
return new NullSubscriber();
|
||||
}
|
||||
}
|
||||
}
|
126
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/O2Switch.php
vendored
Normal file
126
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/O2Switch.php
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Hostings;
|
||||
|
||||
use WP_Rocket\Engine\Activation\ActivationInterface;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
use WP_Rocket\ThirdParty\NullSubscriber;
|
||||
use WP_Rocket\ThirdParty\ReturnTypesTrait;
|
||||
|
||||
/**
|
||||
* Compatibility class for O2Switch
|
||||
*
|
||||
* @since 3.6.3
|
||||
*/
|
||||
class O2Switch extends NullSubscriber implements Subscriber_Interface, ActivationInterface {
|
||||
use ReturnTypesTrait;
|
||||
|
||||
/**
|
||||
* Array of events this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'do_rocket_varnish_http_purge' => 'return_true',
|
||||
'rocket_varnish_field_settings' => 'varnish_addon_title',
|
||||
'rocket_display_input_varnish_auto_purge' => 'return_false',
|
||||
'rocket_cache_mandatory_cookies' => [ 'return_empty_array', PHP_INT_MAX ],
|
||||
'rocket_htaccess_mod_expires' => [ 'remove_htaccess_html_expire', 5 ],
|
||||
'rocket_varnish_purge_headers' => 'add_purge_headers',
|
||||
'rocket_varnish_purge_url' => [ 'remove_regex_from_purge_url', 10, 2 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the text on the Varnish one-click block.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @param array $settings Field settings data.
|
||||
*
|
||||
* @return array modified field settings data.
|
||||
*/
|
||||
public function varnish_addon_title( $settings ) {
|
||||
$settings['varnish_auto_purge']['title'] = sprintf(
|
||||
// Translators: %s = Hosting name.
|
||||
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
|
||||
'O2Switch'
|
||||
);
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove expiration on HTML to prevent issue with Varnish cache.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @param string $rules htaccess rules.
|
||||
*
|
||||
* @return string Updated htaccess rules.
|
||||
*/
|
||||
public function remove_htaccess_html_expire( $rules ) {
|
||||
$rules = preg_replace( '@\s*#\s*Your document html@', '', $rules );
|
||||
$rules = preg_replace( '@\s*ExpiresByType text/html\s*"access plus \d+ (seconds|minutes|hour|week|month|year)"@', '', $rules );
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust purge request header array.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @param array $headers Headers to send.
|
||||
*
|
||||
* @return array Array for headers to be sent.
|
||||
*/
|
||||
public function add_purge_headers( $headers ) {
|
||||
$headers['X-VC-Purge-Key'] = rocket_get_constant( 'O2SWITCH_VARNISH_PURGE_KEY' );
|
||||
|
||||
if ( isset( $headers['X-Purge-Method'] ) && 'regex' === $headers['X-Purge-Method'] ) {
|
||||
$headers['X-Purge-Regex'] = '.*';
|
||||
|
||||
unset( $headers['X-Purge-Method'] );
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove regex part from purge_url as it's handled via headers instead.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @param string $full_purge_url Full url for purge, regex included.
|
||||
* @param string $main_purge_url Main url without regex.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function remove_regex_from_purge_url( $full_purge_url, $main_purge_url ) {
|
||||
return $main_purge_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs these actions during the plugin activation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function activate() {
|
||||
add_action( 'rocket_activation', [ $this, 'activate_no_htaccess_html_expire' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove expiration on HTML on activation to prevent issue with Varnish cache.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function activate_no_htaccess_html_expire() {
|
||||
add_filter( 'rocket_htaccess_mod_expires', [ $this, 'remove_htaccess_html_expire' ] );
|
||||
}
|
||||
}
|
70
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/Pressable.php
vendored
Normal file
70
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/Pressable.php
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Hostings;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with Pressable hosting
|
||||
*
|
||||
* @since 3.3
|
||||
*/
|
||||
class Pressable extends AbstractNoCacheHost {
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.3
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'do_rocket_generate_caching_files' => [ 'return_false', PHP_INT_MAX ],
|
||||
'rocket_display_varnish_options_tab' => 'return_false',
|
||||
'rocket_cache_mandatory_cookies' => [ 'return_empty_array', PHP_INT_MAX ],
|
||||
'after_rocket_clean_domain' => 'purge_pressable_cache',
|
||||
'rocket_url_to_path' => 'fix_wp_includes_path',
|
||||
'rocket_set_wp_cache_constant' => 'return_false',
|
||||
'rocket_generate_advanced_cache_file' => 'return_false',
|
||||
'rocket_cdn_cnames' => [ 'add_pressable_cdn_cname', 1 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge Pressable cache
|
||||
*
|
||||
* @since 3.3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function purge_pressable_cache() {
|
||||
wp_cache_flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify wp-includes absolute path to be able to optimize assets in this directory on Pressable
|
||||
*
|
||||
* @since 3.3
|
||||
*
|
||||
* @param string $file Absolute path to the file.
|
||||
* @return string
|
||||
*/
|
||||
public function fix_wp_includes_path( $file ) {
|
||||
return preg_replace( '#^(.+)(wp-includes(?:.+))$#is', ABSPATH . '$2', $file );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Pressable CDN cname to WP Rocket list to recognize assets as internal ones.
|
||||
*
|
||||
* @since 3.3
|
||||
*
|
||||
* @param array $hosts Array of CDN URLs.
|
||||
* @return array
|
||||
*/
|
||||
public function add_pressable_cdn_cname( $hosts ) {
|
||||
if ( ! rocket_get_constant( 'WP_STACK_CDN_DOMAIN' ) ) {
|
||||
return $hosts;
|
||||
}
|
||||
|
||||
$hosts[] = WP_STACK_CDN_DOMAIN;
|
||||
|
||||
return $hosts;
|
||||
}
|
||||
}
|
97
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/Savvii.php
vendored
Normal file
97
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/Savvii.php
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Hostings;
|
||||
|
||||
use Savvii\CacheFlusherPlugin;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
use WP_Rocket\ThirdParty\ReturnTypesTrait;
|
||||
|
||||
/**
|
||||
* Compatibility for Savvii.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*/
|
||||
class Savvii implements Subscriber_Interface {
|
||||
use ReturnTypesTrait;
|
||||
|
||||
/**
|
||||
* Returns an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @see Subscriber_Interface.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'do_rocket_generate_caching_files' => [ 'return_false', PHP_INT_MAX ],
|
||||
'rocket_varnish_field_settings' => 'varnish_addon_title',
|
||||
'rocket_display_input_varnish_auto_purge' => 'return_false',
|
||||
'rocket_cache_mandatory_cookies' => 'return_empty_array',
|
||||
'init' => 'clear_cache_after_savvii',
|
||||
'after_rocket_clean_domain' => 'clean_savvii',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the text on the Varnish one-click block.
|
||||
*
|
||||
* @since 3.6.3 Rename and move to new architecture.
|
||||
* @since 3.0
|
||||
*
|
||||
* @param array $settings Field settings data.
|
||||
*
|
||||
* @return array modified field settings data.
|
||||
*/
|
||||
public function varnish_addon_title( $settings ) {
|
||||
$settings['varnish_auto_purge']['title'] = sprintf(
|
||||
// Translators: %s = Hosting name.
|
||||
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
|
||||
'Savvii'
|
||||
);
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear WP Rocket cache after purged the Varnish cache via Savvii Hosting.
|
||||
*
|
||||
* @since 3.6.3 Rename and move to new architecture. Refactor. Fix wrong nonce names/actions.
|
||||
* @since 2.6.5
|
||||
*/
|
||||
public function clear_cache_after_savvii() {
|
||||
if (
|
||||
! (
|
||||
isset( $_REQUEST[ CacheFlusherPlugin::NAME_FLUSH_NOW ] )
|
||||
&&
|
||||
check_admin_referer( CacheFlusherPlugin::NAME_FLUSH_NOW )
|
||||
)
|
||||
&&
|
||||
! (
|
||||
isset( $_REQUEST[ CacheFlusherPlugin::NAME_DOMAINFLUSH_NOW ] )
|
||||
&&
|
||||
check_admin_referer( CacheFlusherPlugin::NAME_DOMAINFLUSH_NOW )
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear all caching files.
|
||||
rocket_clean_domain();
|
||||
|
||||
// Preload cache.
|
||||
run_rocket_bot();
|
||||
run_rocket_sitemap_preload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the cache server to purge the cache with Savvii hosting.
|
||||
*
|
||||
* @since 3.6.3 Rename and move to new architecture.
|
||||
* @since 2.6.5
|
||||
*/
|
||||
public function clean_savvii() {
|
||||
do_action( 'warpdrive_domain_flush' ); //phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
|
||||
}
|
||||
}
|
50
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/ServiceProvider.php
vendored
Normal file
50
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/ServiceProvider.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Hostings;
|
||||
|
||||
use WP_Rocket\Engine\Container\ServiceProvider\AbstractServiceProvider;
|
||||
use WP_Rocket\Engine\Container\ServiceProvider\BootableServiceProviderInterface;
|
||||
use WP_Rocket\ThirdParty\Hostings\HostResolver;
|
||||
use WP_Rocket\ThirdParty\Hostings\HostSubscriberFactory;
|
||||
|
||||
/**
|
||||
* Hostings compatibility service provider
|
||||
*
|
||||
* @since 3.6.3
|
||||
*/
|
||||
class ServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface {
|
||||
/**
|
||||
* Services provided
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $provides = [];
|
||||
|
||||
/**
|
||||
* Register the service in the provider array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot() {
|
||||
$hosting_service = HostResolver::get_host_service();
|
||||
|
||||
if ( ! empty( $hosting_service ) ) {
|
||||
$this->provides[] = $hosting_service;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the current hosting subscriber in the container
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
$hosting_service = HostResolver::get_host_service();
|
||||
|
||||
if ( ! empty( $hosting_service ) ) {
|
||||
$this->getContainer()->share( $hosting_service, ( new HostSubscriberFactory() )->get_subscriber() );
|
||||
}
|
||||
}
|
||||
}
|
56
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/SpinUpWP.php
vendored
Normal file
56
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/SpinUpWP.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Hostings;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
use WP_Rocket\ThirdParty\NullSubscriber;
|
||||
use WP_Rocket\ThirdParty\ReturnTypesTrait;
|
||||
|
||||
/**
|
||||
* Compatibility class for SpinUpWP
|
||||
*
|
||||
* @since 3.6.2
|
||||
*/
|
||||
class SpinUpWP extends NullSubscriber implements Subscriber_Interface {
|
||||
use ReturnTypesTrait;
|
||||
|
||||
/**
|
||||
* Array of events this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.6.2
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'do_rocket_generate_caching_files' => 'return_false',
|
||||
'rocket_display_varnish_options_tab' => 'return_false',
|
||||
'rocket_cache_mandatory_cookies' => 'return_empty_array',
|
||||
'after_rocket_clean_domain' => 'purge_site',
|
||||
'wp_rocket_loaded' => 'remove_actions',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge SpinUpWP cache after clean domain.
|
||||
*
|
||||
* @since 3.6.2
|
||||
*/
|
||||
public function purge_site() {
|
||||
if ( ! function_exists( 'spinupwp_purge_site' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
spinupwp_purge_site();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove rocket_clean_domain which prevents a double clear of the cache.
|
||||
*
|
||||
* @since 3.6.2
|
||||
*/
|
||||
public function remove_actions() {
|
||||
remove_action( 'switch_theme', 'rocket_clean_domain' );
|
||||
}
|
||||
|
||||
}
|
113
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/WPEngine.php
vendored
Normal file
113
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/WPEngine.php
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Hostings;
|
||||
|
||||
use WpeCommon;
|
||||
|
||||
/**
|
||||
* Compatibility class for WP Engine.
|
||||
*
|
||||
* @since 3.6.1
|
||||
*/
|
||||
class WPEngine extends AbstractNoCacheHost {
|
||||
/**
|
||||
* Array of events this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'rocket_varnish_field_settings' => 'varnish_addon_title',
|
||||
'rocket_display_input_varnish_auto_purge' => 'return_false',
|
||||
'rocket_cache_mandatory_cookies' => [ 'return_empty_array', PHP_INT_MAX ],
|
||||
'admin_init' => 'run_rocket_bot_after_wpengine',
|
||||
'rocket_set_wp_cache_constant' => 'return_false',
|
||||
'do_rocket_generate_caching_files' => 'return_false',
|
||||
'after_rocket_clean_domain' => 'clean_wpengine',
|
||||
'rocket_buffer' => [ 'add_footprint', 50 ],
|
||||
'rocket_disable_htaccess' => 'return_true',
|
||||
'rocket_generate_advanced_cache_file' => 'return_false',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the text on the Varnish one-click block.
|
||||
*
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @param array $settings Field settings data.
|
||||
*
|
||||
* @return array modified field settings data.
|
||||
*/
|
||||
public function varnish_addon_title( $settings ) {
|
||||
$settings['varnish_auto_purge']['title'] = sprintf(
|
||||
// Translators: %s = Hosting name.
|
||||
__( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ),
|
||||
'WP Engine'
|
||||
);
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run WP Rocket preload bot after purged the Varnish cache via WP Engine Hosting.
|
||||
*
|
||||
* @since 3.6.1
|
||||
*/
|
||||
public function run_rocket_bot_after_wpengine() {
|
||||
if ( ! wpe_param( 'purge-all' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! rocket_has_constant( 'PWP_NAME' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! check_admin_referer( rocket_get_constant( 'PWP_NAME' ) . '-config' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Preload cache.
|
||||
run_rocket_bot();
|
||||
run_rocket_sitemap_preload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the cache server to purge the cache with WP Engine hosting.
|
||||
*
|
||||
* @since 3.6.1
|
||||
*/
|
||||
public function clean_wpengine() {
|
||||
if ( method_exists( 'WpeCommon', 'purge_memcached' ) ) {
|
||||
WpeCommon::purge_memcached();
|
||||
}
|
||||
|
||||
if ( method_exists( 'WpeCommon', 'purge_varnish_cache' ) ) {
|
||||
WpeCommon::purge_varnish_cache();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add WP Rocket footprint on Buffer.
|
||||
*
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @param string $buffer HTML content.
|
||||
*
|
||||
* @return string HTML with WP Rocket footprint.
|
||||
*/
|
||||
public function add_footprint( $buffer ) {
|
||||
if ( ! preg_match( '/<\/html>/i', $buffer ) ) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
$footprint = rocket_get_constant( 'WP_ROCKET_WHITE_LABEL_FOOTPRINT' )
|
||||
? "\n" . '<!-- Optimized for great performance'
|
||||
: "\n" . '<!-- This website is like a Rocket, isn\'t it? Performance optimized by ' . rocket_get_constant( 'WP_ROCKET_PLUGIN_NAME' ) . '. Learn more: https://wp-rocket.me';
|
||||
$footprint .= ' -->';
|
||||
|
||||
return $buffer . $footprint;
|
||||
}
|
||||
}
|
39
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/WordPressCom.php
vendored
Normal file
39
wp-content/plugins/wp-rocket/inc/ThirdParty/Hostings/WordPressCom.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Hostings;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with WordPress.com hosting.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*/
|
||||
class WordPressCom extends AbstractNoCacheHost {
|
||||
/**
|
||||
* Array of events this subscriber listens to.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @return array The array of subscribed events.
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'do_rocket_generate_caching_files' => 'return_false',
|
||||
'rocket_cache_mandatory_cookies' => 'return_empty_array',
|
||||
'rocket_display_varnish_options_tab' => 'return_false',
|
||||
'rocket_set_wp_cache_constant' => 'return_false',
|
||||
'rocket_generate_advanced_cache_file' => 'return_false',
|
||||
'after_rocket_clean_domain' => 'purge_wpcom_cache',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge WordPress.com cache
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function purge_wpcom_cache() {
|
||||
wp_cache_flush();
|
||||
}
|
||||
}
|
28
wp-content/plugins/wp-rocket/inc/ThirdParty/NullSubscriber.php
vendored
Normal file
28
wp-content/plugins/wp-rocket/inc/ThirdParty/NullSubscriber.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Null Subscriber.
|
||||
*
|
||||
* Provides a base class to extend for common Subscribers.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*/
|
||||
class NullSubscriber implements Subscriber_Interface {
|
||||
|
||||
/**
|
||||
* Get an array of subscribed events.
|
||||
*
|
||||
* To be overloaded with actual subscribed events in extending Subscribers.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [];
|
||||
}
|
||||
}
|
483
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Ecommerce/WooCommerceSubscriber.php
vendored
Normal file
483
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Ecommerce/WooCommerceSubscriber.php
vendored
Normal file
@@ -0,0 +1,483 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Ecommerce;
|
||||
|
||||
use WP_Rocket\Event_Management\Event_Manager;
|
||||
use WP_Rocket\Event_Management\Event_Manager_Aware_Subscriber_Interface;
|
||||
use WooCommerce;
|
||||
use WC_API;
|
||||
|
||||
/**
|
||||
* WooCommerce compatibility
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*/
|
||||
class WooCommerceSubscriber implements Event_Manager_Aware_Subscriber_Interface {
|
||||
use \WP_Rocket\Traits\Config_Updater;
|
||||
|
||||
/**
|
||||
* The WordPress Event Manager
|
||||
*
|
||||
* @var Event_Manager;
|
||||
*/
|
||||
protected $event_manager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param Event_Manager $event_manager The WordPress Event Manager.
|
||||
*/
|
||||
public function set_event_manager( Event_Manager $event_manager ) {
|
||||
$this->event_manager = $event_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
$events = [
|
||||
'activate_woocommerce/woocommerce.php' => [ 'activate_woocommerce', 11 ],
|
||||
'deactivate_woocommerce/woocommerce.php' => [ 'deactivate_woocommerce', 11 ],
|
||||
];
|
||||
|
||||
if ( class_exists( 'WooCommerce' ) ) {
|
||||
$events['update_option_woocommerce_cart_page_id'] = [ 'after_update_single_option', 10, 2 ];
|
||||
$events['update_option_woocommerce_checkout_page_id'] = [ 'after_update_single_option', 10, 2 ];
|
||||
$events['update_option_woocommerce_myaccount_page_id'] = [ 'after_update_single_option', 10, 2 ];
|
||||
$events['update_option_woocommerce_default_customer_address'] = [ 'after_update_single_option', 10, 2 ];
|
||||
|
||||
$events['shutdown'] = 'maybe_update_config';
|
||||
$events['woocommerce_save_product_variation'] = 'clean_cache_after_woocommerce_save_product_variation';
|
||||
$events['transition_post_status'] = [ 'maybe_exclude_page', 10, 3 ];
|
||||
$events['rocket_cache_reject_uri'] = [
|
||||
[ 'exclude_pages' ],
|
||||
];
|
||||
$events['rocket_cache_query_strings'] = 'cache_geolocation_query_string';
|
||||
$events['rocket_cpcss_excluded_taxonomies'] = 'exclude_product_attributes_cpcss';
|
||||
$events['nonce_user_logged_out'] = [ 'maybe_revert_uid_for_nonce_actions', PHP_INT_MAX, 2 ];
|
||||
|
||||
/**
|
||||
* Filters activation of WooCommerce empty cart caching
|
||||
*
|
||||
* @since 3.1
|
||||
*
|
||||
* @param bool true to activate, false to deactivate.
|
||||
*/
|
||||
if ( apply_filters( 'rocket_cache_wc_empty_cart', true ) ) {
|
||||
$events['after_setup_theme'] = [ 'serve_cache_empty_cart', 11 ];
|
||||
$events['template_redirect'] = [ 'cache_empty_cart', -1 ];
|
||||
$events['switch_theme'] = 'delete_cache_empty_cart';
|
||||
}
|
||||
}
|
||||
|
||||
if ( class_exists( 'WC_API' ) ) {
|
||||
$events['rocket_cache_reject_uri'][] = [ 'exclude_wc_rest_api' ];
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add query string to exclusion when activating the plugin
|
||||
*
|
||||
* @since 2.8.6
|
||||
* @author Rémy Perona
|
||||
*/
|
||||
public function activate_woocommerce() {
|
||||
$this->event_manager->add_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_pages' ] );
|
||||
$this->event_manager->add_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_wc_rest_api' ] );
|
||||
$this->event_manager->add_callback( 'rocket_cache_query_strings', [ $this, 'cache_geolocation_query_string' ] );
|
||||
|
||||
// Update .htaccess file rules.
|
||||
flush_rocket_htaccess();
|
||||
|
||||
// Regenerate the config file.
|
||||
rocket_generate_config_file();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove query string from exclusion when deactivating the plugin
|
||||
*
|
||||
* @since 2.8.6
|
||||
* @author Rémy Perona
|
||||
*/
|
||||
public function deactivate_woocommerce() {
|
||||
$this->event_manager->remove_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_pages' ] );
|
||||
$this->event_manager->remove_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_wc_rest_api' ] );
|
||||
$this->event_manager->remove_callback( 'rocket_cache_query_strings', [ $this, 'cache_geolocation_query_string' ] );
|
||||
|
||||
// Update .htaccess file rules.
|
||||
flush_rocket_htaccess();
|
||||
|
||||
// Regenerate the config file.
|
||||
rocket_generate_config_file();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean product cache on variation update
|
||||
*
|
||||
* @since 2.9
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param int $variation_id ID of the variation.
|
||||
* @return bool
|
||||
*/
|
||||
public function clean_cache_after_woocommerce_save_product_variation( $variation_id ) {
|
||||
$product_id = wp_get_post_parent_id( $variation_id );
|
||||
|
||||
if ( ! $product_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rocket_clean_post( $product_id );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe regenerate the htaccess & config file if a WooCommerce page is published
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $new_status New post status.
|
||||
* @param string $old_status Old post status.
|
||||
* @param WP_Post $post Post object.
|
||||
* @return bool
|
||||
*/
|
||||
public function maybe_exclude_page( $new_status, $old_status, $post ) {
|
||||
if ( 'publish' === $old_status || 'publish' !== $new_status ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wc_get_page_id' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( wc_get_page_id( 'checkout' ) !== $post->ID && wc_get_page_id( 'cart' ) !== $post->ID && wc_get_page_id( 'myaccount' ) !== $post->ID ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update .htaccess file rules.
|
||||
flush_rocket_htaccess();
|
||||
|
||||
// Regenerate the config file.
|
||||
rocket_generate_config_file();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude WooCommerce cart, checkout and account pages from caching
|
||||
*
|
||||
* @since 2.11 Moved to 3rd party
|
||||
* @since 2.4
|
||||
*
|
||||
* @param array $urls An array of excluded pages.
|
||||
* @return array Updated array of excluded pages
|
||||
*/
|
||||
public function exclude_pages( $urls ) {
|
||||
if ( ! function_exists( 'wc_get_page_id' ) ) {
|
||||
return $urls;
|
||||
}
|
||||
$checkout_urls = $this->exclude_page( wc_get_page_id( 'checkout' ), 'page', '(.*)' );
|
||||
$cart_urls = $this->exclude_page( wc_get_page_id( 'cart' ) );
|
||||
$account_urls = $this->exclude_page( wc_get_page_id( 'myaccount' ), 'page', '(.*)' );
|
||||
|
||||
return array_merge( $urls, $checkout_urls, $cart_urls, $account_urls );
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes WooCommerce checkout page from cache
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param int $page_id ID of page to exclude.
|
||||
* @param string $post_type Post type of the page.
|
||||
* @param string $pattern Pattern to use for the exclusion.
|
||||
* @return array
|
||||
*/
|
||||
private function exclude_page( $page_id, $post_type = 'page', $pattern = '' ) {
|
||||
$urls = [];
|
||||
|
||||
if ( $page_id <= 0 || (int) get_option( 'page_on_front' ) === $page_id ) {
|
||||
return $urls;
|
||||
}
|
||||
|
||||
if ( 'publish' !== get_post_status( $page_id ) ) {
|
||||
return $urls;
|
||||
}
|
||||
|
||||
$urls = get_rocket_i18n_translated_post_urls( $page_id, $post_type, $pattern );
|
||||
|
||||
return $urls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically cache v query string when WC geolocation with cache compatibility option is active
|
||||
*
|
||||
* @since 2.8.6
|
||||
* @author Rémy Perona
|
||||
*
|
||||
* @param array $query_strings list of query strings to cache.
|
||||
* @return array Updated list of query strings to cache
|
||||
*/
|
||||
public function cache_geolocation_query_string( $query_strings ) {
|
||||
if ( 'geolocation_ajax' !== get_option( 'woocommerce_default_customer_address' ) ) {
|
||||
return $query_strings;
|
||||
}
|
||||
|
||||
$query_strings[] = 'v';
|
||||
|
||||
return $query_strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns WooCommerce API endpoint
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_wc_api_endpoint() {
|
||||
return home_url( '/wc-api/v(.*)' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude WooCommerce REST API URL from cache
|
||||
*
|
||||
* @since 2.6.5
|
||||
*
|
||||
* @param array $urls URLs to exclude from cache.
|
||||
* @return array Updated list of URLs to exclude from cache
|
||||
*/
|
||||
public function exclude_wc_rest_api( $urls ) {
|
||||
/**
|
||||
* By default, don't cache the WooCommerce REST API.
|
||||
*
|
||||
* @since 2.6.5
|
||||
*
|
||||
* @param bool false will force to cache the WooCommerce REST API
|
||||
*/
|
||||
if ( apply_filters( 'rocket_cache_reject_wc_rest_api', true ) ) {
|
||||
$urls[] = rocket_clean_exclude_file( $this->get_wc_api_endpoint() );
|
||||
}
|
||||
|
||||
return $urls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves the empty cart cache
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function serve_cache_empty_cart() {
|
||||
if ( ! $this->is_get_refreshed_fragments() || rocket_bypass() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cart = $this->get_cache_empty_cart();
|
||||
|
||||
if ( false !== $cart ) {
|
||||
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
|
||||
echo $cart; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the empty cart cache
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cache_empty_cart() {
|
||||
if ( ! $this->is_get_refreshed_fragments() || rocket_bypass() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cart = $this->get_cache_empty_cart();
|
||||
|
||||
if ( false !== $cart ) {
|
||||
return;
|
||||
}
|
||||
|
||||
ob_start( [ $this, 'save_cache_empty_cart' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the empty cart cache
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_cache_empty_cart() {
|
||||
$lang = rocket_get_current_language();
|
||||
|
||||
if ( $lang ) {
|
||||
return get_transient( 'rocket_get_refreshed_fragments_cache_' . $lang );
|
||||
}
|
||||
|
||||
return get_transient( 'rocket_get_refreshed_fragments_cache' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the empty cart JSON in a transient
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $content Current buffer content.
|
||||
* @return string
|
||||
*/
|
||||
private function save_cache_empty_cart( $content ) {
|
||||
$lang = rocket_get_current_language();
|
||||
|
||||
if ( $lang ) {
|
||||
set_transient( 'rocket_get_refreshed_fragments_cache_' . $lang, $content, 7 * DAY_IN_SECONDS );
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
set_transient( 'rocket_get_refreshed_fragments_cache', $content, 7 * DAY_IN_SECONDS );
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the request is for get_refreshed_fragments and the cart is empty
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function is_get_refreshed_fragments() {
|
||||
if ( ! isset( $_GET['wc-ajax'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( 'get_refreshed_fragments' !== $_GET['wc-ajax'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! empty( $_COOKIE['woocommerce_cart_hash'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! empty( $_COOKIE['woocommerce_items_in_cart'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the empty cart cache
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_cache_empty_cart() {
|
||||
$langs = get_rocket_i18n_code();
|
||||
|
||||
if ( $langs ) {
|
||||
foreach ( $langs as $lang ) {
|
||||
delete_transient( 'rocket_get_refreshed_fragments_cache_' . $lang );
|
||||
}
|
||||
}
|
||||
|
||||
delete_transient( 'rocket_get_refreshed_fragments_cache' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes WC product attributes taxonomies from CPCSS generation
|
||||
*
|
||||
* @since 3.3.5
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param array $excluded_taxonomies Taxonomies excluded from CPCSS generation.
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_product_attributes_cpcss( $excluded_taxonomies ) {
|
||||
if ( ! function_exists( 'wc_get_attribute_taxonomy_names' ) ) {
|
||||
return $excluded_taxonomies;
|
||||
}
|
||||
|
||||
return array_merge( $excluded_taxonomies, wc_get_attribute_taxonomy_names() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $user_id to 0 for certain nonce actions.
|
||||
*
|
||||
* WooCommerce core changes how nonces are used for non-logged customers.
|
||||
* When a user is logged out, but has items in their cart, WC core sets the $uid as a random string customer id.
|
||||
* This is going to mess out nonce validation with WP Rocket and third party plugins which do not bypass WC nonce changes.
|
||||
* WP Rocket caches the page so the nonce $uid will be always different than the session customer $uid.
|
||||
* This function will check the nonce against a UID of 0 because this is how WP Rocket generated the cached page.
|
||||
*
|
||||
* @since 3.5.1
|
||||
* @author Soponar Cristina
|
||||
*
|
||||
* @param string|int $user_id ID of the nonce-owning user.
|
||||
* @param string|int $action The nonce action.
|
||||
*
|
||||
* @return int $uid ID of the nonce-owning user.
|
||||
*/
|
||||
public function maybe_revert_uid_for_nonce_actions( $user_id, $action ) {
|
||||
// User ID is invalid.
|
||||
if ( empty( $user_id ) || 0 === $user_id ) {
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
// The nonce action is not in the list.
|
||||
if ( ! $action || ! in_array( $action, $this->get_nonce_actions(), true ) ) {
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* List with nonce actions which needs to revert the $uid.
|
||||
*
|
||||
* @since 3.5.1
|
||||
* @author Soponar Cristina
|
||||
*
|
||||
* @return array $nonce_actions List with all nonce actions.
|
||||
*/
|
||||
private function get_nonce_actions() {
|
||||
return [
|
||||
'wcmd-subscribe-secret', // WooCommerce MailChimp Discount.
|
||||
'td-block', // "Load more" AJAX functionality of the Newspaper theme.
|
||||
'codevz_selective_refresh', // xtra theme.
|
||||
'xtra_quick_view', // xtra theme quick view.
|
||||
'ajax_search_nonce', // xtra theme AJAX search.
|
||||
'xtra_wishlist_content', // xtra theme wishlist feature.
|
||||
'ajax-login-security', // OneSocial theme pop-up login.
|
||||
'dokan_pageview', // Dokan related pageview.
|
||||
'dokan_report_abuse', // Dokan report abuse popup.
|
||||
'uabb_subscribe_form_submit', // Ultimate Addons for Beaver Builder - MailChimp signup form.
|
||||
'konte-add-to-cart', // Add to cart feature of the Konte theme.
|
||||
'wpuf_form_add', // WP User Frontend Pro.
|
||||
'everest_forms_ajax_form_submission', // Everest forms AJAX submission.
|
||||
'everest-forms_process_submit', // Everest forms submission.
|
||||
'ajax-login-nonce', // Rehub theme login modal.
|
||||
'filter-nonce', // Rehub theme filter.
|
||||
'log-out', // WordPress's log-out action (wp_nonce_ays() function).
|
||||
'ybws123456', // Custom Bookly form.
|
||||
];
|
||||
}
|
||||
}
|
159
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Optimization/AMP.php
vendored
Normal file
159
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Optimization/AMP.php
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
|
||||
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Engine\CDN\Subscriber;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with AMP
|
||||
*
|
||||
* @since 3.5.2
|
||||
*/
|
||||
class AMP implements Subscriber_Interface {
|
||||
const QUERY = 'amp';
|
||||
const AMP_OPTIONS = 'amp-options';
|
||||
|
||||
/**
|
||||
* WP Rocket CDN Subscriber.
|
||||
*
|
||||
* @var Subscriber_Interface
|
||||
*/
|
||||
private $cdn_subscriber;
|
||||
|
||||
/**
|
||||
* WP Rocket Options instance
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Options_Data $options WP Rocket Options instance.
|
||||
* @param Subscriber_Interface $cdn_subscriber WP Rocket CDN Subscriber.
|
||||
*/
|
||||
public function __construct( Options_Data $options, Subscriber_Interface $cdn_subscriber ) {
|
||||
$this->options = $options;
|
||||
$this->cdn_subscriber = $cdn_subscriber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribed events for AMP.
|
||||
*
|
||||
* @since 3.5.2
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
$events = [
|
||||
'activate_amp/amp.php' => 'generate_config_file',
|
||||
'deactivate_amp/amp.php' => 'generate_config_file',
|
||||
'wp' => 'disable_options_on_amp',
|
||||
];
|
||||
if ( function_exists( 'is_amp_endpoint' ) ) {
|
||||
$events['rocket_cache_query_strings'] = 'is_amp_compatible_callback';
|
||||
$events['update_option_amp-options'] = 'generate_config_file';
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate config file on plugin activation / deactivation.
|
||||
*
|
||||
* @since 3.5.2
|
||||
*/
|
||||
public function generate_config_file() {
|
||||
rocket_generate_config_file();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add compatibility with AMP query string by adding it as a cached query string.
|
||||
*
|
||||
* @since 3.5.2
|
||||
*
|
||||
* @param array $value WP Rocket cache_query_strings value.
|
||||
* @return array
|
||||
*/
|
||||
public function is_amp_compatible_callback( $value ) {
|
||||
$options = get_option( self::AMP_OPTIONS, [] );
|
||||
$query_strings = array_diff( $value, [ static::QUERY ] );
|
||||
|
||||
if ( empty( $options['theme_support'] ) ) {
|
||||
return $query_strings;
|
||||
}
|
||||
|
||||
if ( in_array( $options['theme_support'], [ 'transitional', 'reader' ], true ) ) {
|
||||
$query_strings[] = static::QUERY;
|
||||
}
|
||||
|
||||
return $query_strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes Minification, DNS Prefetch, LazyLoad, Defer JS when on an AMP document.
|
||||
*
|
||||
* This covers AMP documents as output by the official AMP plugin for WordPress
|
||||
* (https://amp-wp.org/) as well as Web Stories for WordPress (https://wp.stories.google/),
|
||||
* which both support the `is_amp_endpoint` function checks.
|
||||
*
|
||||
* However, in the case of Web Stories, `is_amp_endpoint` is only defined on
|
||||
* the `wp` action, not earlier. Hence doing the `function_exists` check at this stage
|
||||
* instead of in the `get_subscribed_events()` method.
|
||||
*
|
||||
* @since 3.5.2
|
||||
*/
|
||||
public function disable_options_on_amp() {
|
||||
if ( ! function_exists( 'is_amp_endpoint' ) || ! is_amp_endpoint() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $wp_filter;
|
||||
|
||||
remove_filter( 'wp_resource_hints', 'rocket_dns_prefetch', 10, 2 );
|
||||
add_filter( 'do_rocket_lazyload', '__return_false' );
|
||||
add_filter( 'do_rocket_lazyload_iframes', '__return_false' );
|
||||
unset( $wp_filter['rocket_buffer'] );
|
||||
|
||||
$options = get_option( self::AMP_OPTIONS, [] );
|
||||
|
||||
if ( ! empty( $options['theme_support'] )
|
||||
&&
|
||||
in_array( $options['theme_support'], [ 'transitional', 'reader' ], true ) ) {
|
||||
add_filter( 'rocket_cdn_reject_files', [ $this, 'reject_files' ], PHP_INT_MAX );
|
||||
add_filter( 'rocket_buffer', [ $this->cdn_subscriber, 'rewrite' ] );
|
||||
add_filter( 'rocket_buffer', [ $this->cdn_subscriber, 'rewrite_srcset' ] );
|
||||
}
|
||||
|
||||
if (
|
||||
(bool) $this->options->get( 'do_cloudflare', 0 )
|
||||
&&
|
||||
(
|
||||
(bool) $this->options->get( 'cloudflare_protocol_rewrite', 0 )
|
||||
||
|
||||
// this filter is documented in inc/front/protocol.php.
|
||||
(bool) apply_filters( 'do_rocket_protocol_rewrite', false ) // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
|
||||
)
|
||||
) {
|
||||
remove_filter( 'wp_calculate_image_srcset', 'rocket_protocol_rewrite_srcset', PHP_INT_MAX );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all CSS and JS files to the list of excluded CDN files.
|
||||
*
|
||||
* @since 3.5.5
|
||||
*
|
||||
* @param array $files List of excluded files.
|
||||
* @return array List of excluded files.
|
||||
*/
|
||||
public function reject_files( $files ) {
|
||||
return array_merge(
|
||||
$files,
|
||||
[
|
||||
'(.*).css',
|
||||
'(.*).js',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
295
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Optimization/Hummingbird.php
vendored
Normal file
295
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Optimization/Hummingbird.php
vendored
Normal file
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
|
||||
|
||||
use WP_Hummingbird_Settings;
|
||||
use WP_Hummingbird_Utils;
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Hummingbird compatibility class
|
||||
*/
|
||||
class Hummingbird implements Subscriber_Interface {
|
||||
/**
|
||||
* WP Rocket Options instance
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Array containing the errors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $errors = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Options_Data $options WP Rocket Options instance.
|
||||
*/
|
||||
public function __construct( Options_Data $options ) {
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'admin_notices' => 'warning_notice',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a notice if conflicting options are active
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function warning_notice() {
|
||||
if ( ! current_user_can( 'rocket_manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_plugin_active( 'hummingbird-performance/wp-hummingbird.php' ) && ! is_plugin_active( 'wp-hummingbird/wp-hummingbird.php' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->check_cache();
|
||||
$this->check_assets();
|
||||
$this->check_browser_caching();
|
||||
$this->check_gzip();
|
||||
$this->check_emoji();
|
||||
|
||||
if ( 0 === count( $this->errors ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Translators: %s = Plugin name.
|
||||
$message = '<p>' . sprintf( _nx( 'Please deactivate the following %s option which conflicts with WP Rocket features:', 'Please deactivate the following %s options which conflict with WP Rocket features:', count( $this->errors ), 'Hummingbird notice', 'rocket' ), 'Hummingbird' ) . '</p>';
|
||||
|
||||
$message .= '<ul>';
|
||||
|
||||
foreach ( $this->errors as $error ) {
|
||||
$message .= '<li>' . $error . '</li>';
|
||||
}
|
||||
|
||||
$message .= '</ul>';
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'error',
|
||||
'message' => $message,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Hummingbird Utils class exists
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function is_utils_available() {
|
||||
if ( ! class_exists( 'WP_Hummingbird_Utils' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( 'WP_Hummingbird_Utils', 'get_module' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Hummingbird settings class exists
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function is_settings_available() {
|
||||
if ( ! class_exists( 'WP_Hummingbird_Settings' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( 'WP_Hummingbird_Settings', 'get_setting' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Hummingbird and WP Rocket disable emoji options are active at the same time
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function check_emoji() {
|
||||
if ( ! $this->is_settings_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->options->get( 'emoji' ) && WP_Hummingbird_Settings::get_setting( 'emoji', 'advanced' ) ) {
|
||||
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
|
||||
$this->errors[] = sprintf( _x( '%1$s %2$sdisable emoji%3$s conflicts with WP Rockets %2$sdisable emoji%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Hummingbird Gzip rules are in the htaccess file.
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function check_gzip() {
|
||||
if ( ! $this->is_utils_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$gzip = WP_Hummingbird_Utils::get_module( 'gzip' );
|
||||
|
||||
if ( ! $gzip instanceof \WP_Hummingbird_Module_GZip ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( $gzip, 'is_htaccess_written' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( $gzip, 'get_server_type' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $gzip::is_htaccess_written( 'gzip' ) && 'apache' === $gzip::get_server_type() ) {
|
||||
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
|
||||
$this->errors[] = sprintf( _x( '%1$s %2$sGZIP compression%3$s conflicts with WP Rocket %2$sGZIP compression%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Hummingbird browser caching rules are in the htaccess file
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function check_browser_caching() {
|
||||
if ( ! $this->is_utils_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$caching = WP_Hummingbird_Utils::get_module( 'caching' );
|
||||
|
||||
if ( ! $caching instanceof \WP_Hummingbird_Module_Caching ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( $caching, 'is_htaccess_written' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( $caching, 'get_server_type' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $caching::is_htaccess_written( 'caching' ) && 'apache' === $caching::get_server_type() ) {
|
||||
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
|
||||
$this->errors[] = sprintf( _x( '%1$s %2$sbrowser caching%3$s conflicts with WP Rocket %2$sbrowser caching%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Hummingbird Cache is active
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function check_cache() {
|
||||
if ( ! $this->is_utils_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cache = WP_Hummingbird_Utils::get_module( 'page_cache' );
|
||||
|
||||
if ( ! $cache instanceof \WP_Hummingbird_Module_Page_Cache ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( $cache, 'is_active' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $cache->is_active() ) {
|
||||
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
|
||||
$this->errors[] = sprintf( _x( '%1$s %2$spage caching%3$s conflicts with WP Rocket %2$spage caching%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Hummingbird Assets optimization is active
|
||||
*
|
||||
* Checks against WP Rocket Minify CSS, Minify JS and Defer JS options.
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function check_assets() {
|
||||
if ( ! $this->is_utils_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$minify = WP_Hummingbird_Utils::get_module( 'minify' );
|
||||
|
||||
if ( ! $minify instanceof \WP_Hummingbird_Module_Minify ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( $minify, 'is_active' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $minify->is_active() && ( $this->options->get( 'minify_css' ) || $this->options->get( 'minify_js' ) || $this->options->get( 'defer_all_js' ) ) ) {
|
||||
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
|
||||
$this->errors[] = sprintf( _x( '%1$s %2$sasset optimization%3$s conflicts with WP Rocket %2$sfile optimization%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
98
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/PDFEmbedder.php
vendored
Normal file
98
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/PDFEmbedder.php
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with PDF Embedder Free / Premium / Secure plugin.
|
||||
*
|
||||
* @since 3.6.2
|
||||
*/
|
||||
class PDFEmbedder implements Subscriber_Interface {
|
||||
/**
|
||||
* Subscribed events.
|
||||
*
|
||||
* @since 3.6.2
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
// All 3 plugins use the same core class.
|
||||
if ( ! class_exists( 'core_pdf_embedder' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'rocket_exclude_js' => 'exclude_pdfembedder_scripts',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds PDFEmbedder scripts to defer JS exclusion
|
||||
*
|
||||
* @since 3.6.2
|
||||
*
|
||||
* @param array $excluded_js Array of scripts to exclude.
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_pdfembedder_scripts( $excluded_js ) {
|
||||
if ( class_exists( 'pdfemb_basic_pdf_embedder' ) ) {
|
||||
// Exclude Free version.
|
||||
return array_merge(
|
||||
$excluded_js,
|
||||
$this->pdfembedder_free_scripts()
|
||||
);
|
||||
}
|
||||
|
||||
if ( class_exists( 'pdfemb_premium_mobile_pdf_embedder' ) ) {
|
||||
// Excludes PDFEmbedder-premium.
|
||||
return array_merge(
|
||||
$excluded_js,
|
||||
$this->pdfembedder_premium_scripts()
|
||||
);
|
||||
}
|
||||
|
||||
if ( class_exists( 'pdfemb_premium_secure_pdf_embedder' ) ) {
|
||||
// Excludes PDFEmbedder-premium-secure.
|
||||
return array_merge(
|
||||
$excluded_js,
|
||||
$this->pdfembedder_secure_scripts()
|
||||
);
|
||||
}
|
||||
|
||||
return $excluded_js;
|
||||
}
|
||||
|
||||
/**
|
||||
* PDFEmbedder Free JS scripts.
|
||||
*
|
||||
* @return array JS files to be excluded.
|
||||
*/
|
||||
private function pdfembedder_free_scripts() {
|
||||
return [
|
||||
rocket_clean_exclude_file( plugins_url( '/pdf-embedder/js/(.*).js' ) ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* PDFEmbedder Premium JS scripts.
|
||||
*
|
||||
* @return array JS files to be excluded.
|
||||
*/
|
||||
private function pdfembedder_premium_scripts() {
|
||||
return [
|
||||
rocket_clean_exclude_file( plugins_url( '/PDFEmbedder-premium/js/pdfjs/(.*).js' ) ),
|
||||
rocket_clean_exclude_file( plugins_url( '/PDFEmbedder-premium/js/(.*).js' ) ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* PDFEmbedder Secure JS scripts.
|
||||
*
|
||||
* @return array JS files to be excluded.
|
||||
*/
|
||||
private function pdfembedder_secure_scripts() {
|
||||
return [
|
||||
rocket_clean_exclude_file( plugins_url( '/PDFEmbedder-premium-secure/js/pdfjs/(.*).js' ) ),
|
||||
rocket_clean_exclude_file( plugins_url( '/PDFEmbedder-premium-secure/js/(.*).js' ) ),
|
||||
];
|
||||
}
|
||||
}
|
35
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/PageBuilder/BeaverBuilder.php
vendored
Normal file
35
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/PageBuilder/BeaverBuilder.php
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins\PageBuilder;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class BeaverBuilder implements Subscriber_Interface {
|
||||
/**
|
||||
* Events this subscriber listens to
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! rocket_get_constant( 'FL_BUILDER_VERSION' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'fl_builder_before_save_layout' => 'purge_cache',
|
||||
'fl_builder_cache_cleared' => 'purge_cache',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge the cache when the beaver builder layout is updated to update the minified files content & URL
|
||||
*
|
||||
* Previously rocket_beaver_builder_clean_domain()
|
||||
*
|
||||
* @since 3.6
|
||||
* @author Remy Perona
|
||||
*/
|
||||
public function purge_cache() {
|
||||
rocket_clean_minify();
|
||||
rocket_clean_domain();
|
||||
}
|
||||
}
|
119
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/PageBuilder/Elementor.php
vendored
Normal file
119
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/PageBuilder/Elementor.php
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins\PageBuilder;
|
||||
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Compatibility file for Elementor plugin
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*/
|
||||
class Elementor implements Subscriber_Interface {
|
||||
/**
|
||||
* WP Rocket options.
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param Options_Data $options WP Rocket options.
|
||||
*/
|
||||
public function __construct( Options_Data $options ) {
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! defined( 'ELEMENTOR_VERSION' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'wp_rocket_loaded' => 'remove_widget_callback',
|
||||
'added_post_meta' => [ 'maybe_clear_cache', 10, 3 ],
|
||||
'deleted_post_meta' => [ 'maybe_clear_cache', 10, 3 ],
|
||||
'elementor/core/files/clear_cache' => 'clear_cache',
|
||||
'update_option__elementor_global_css' => 'clear_cache',
|
||||
'delete_option__elementor_global_css' => 'clear_cache',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the callback to clear the cache on widget update
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function remove_widget_callback() {
|
||||
remove_filter( 'widget_update_callback', 'rocket_widget_update_callback' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears WP Rocket caches if the combine CSS option is active.
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param int $meta_id The meta ID.
|
||||
* @param int $object_id Object ID.
|
||||
* @param string $meta_key Meta key.
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_clear_cache( $meta_id, $object_id, $meta_key ) {
|
||||
if ( '_elementor_css' !== $meta_key ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $this->options->get( 'minify_concatenate_css' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->clear_cache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear WP Rocket caches when Elementor changes the CSS
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear_cache() {
|
||||
if ( ! $this->elementor_use_external_file() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
rocket_clean_domain();
|
||||
rocket_clean_minify( 'css' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether elementor is set use external CSS file or not.
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function elementor_use_external_file() {
|
||||
return 'internal' !== get_option( 'elementor_css_print_method' );
|
||||
}
|
||||
}
|
117
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/SimpleCustomCss.php
vendored
Normal file
117
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/SimpleCustomCss.php
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use WP_Rocket\Engine\Optimization\CSSTrait;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with Simple Custom CSS plugin.
|
||||
*
|
||||
* @since 3.6
|
||||
* @author Soponar Cristina
|
||||
*/
|
||||
class SimpleCustomCss implements Subscriber_Interface {
|
||||
use CSSTrait;
|
||||
|
||||
const FILENAME = 'sccss.css';
|
||||
|
||||
/**
|
||||
* Base cache busting folder path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cache_busting_path;
|
||||
|
||||
/**
|
||||
* SCCSS cache busting file path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $filepath;
|
||||
|
||||
/**
|
||||
* SCCSS cache busting file URL
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $file_url;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $cache_busting_path Base cache busting folder path.
|
||||
* @param string $cache_busting_url Base cache busting URL.
|
||||
*/
|
||||
public function __construct( $cache_busting_path, $cache_busting_url ) {
|
||||
$blog_id = get_current_blog_id();
|
||||
$this->cache_busting_path = $cache_busting_path . $blog_id . '/';
|
||||
$this->filepath = $this->cache_busting_path . self::FILENAME;
|
||||
$this->file_url = $cache_busting_url . $blog_id . '/' . self::FILENAME;
|
||||
}
|
||||
/**
|
||||
* Subscribed events for AMP.
|
||||
*
|
||||
* @since 3.5.3
|
||||
* @author Soponar Cristina
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! defined( 'SCCSS_FILE' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'wp_enqueue_scripts' => [ 'cache_sccss', 98 ],
|
||||
'update_option_sccss_settings' => 'update_cache_file',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches SCCSS code & remove the default enqueued URL
|
||||
*
|
||||
* @since 2.9
|
||||
* @author Remy Perona
|
||||
*/
|
||||
public function cache_sccss() {
|
||||
if ( ! rocket_direct_filesystem()->exists( $this->filepath ) ) {
|
||||
$this->create_cache_file();
|
||||
}
|
||||
|
||||
// This filter is documented in inc/Engine/Optimization/CSS/AbstractCSSOptimization.php.
|
||||
wp_enqueue_style( 'scss', apply_filters( 'rocket_css_url', $this->file_url ), '', rocket_direct_filesystem()->mtime( $this->filepath ) );
|
||||
remove_action( 'wp_enqueue_scripts', 'sccss_register_style', 99 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes & recreates cache for SCCSS code
|
||||
*
|
||||
* @since 3.6
|
||||
* @author Remy Perona
|
||||
*/
|
||||
public function update_cache_file() {
|
||||
rocket_clean_domain();
|
||||
$this->create_cache_file();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates cache file for SCCSS code if it does not exist.
|
||||
*
|
||||
* @since 2.9
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool Returns bool if the files exists or could not be created.
|
||||
*/
|
||||
private function create_cache_file() {
|
||||
$options = get_option( 'sccss_settings' );
|
||||
$raw_content = isset( $options['sccss-content'] ) ? $options['sccss-content'] : '';
|
||||
$content = wp_kses( $raw_content, [ '\'', '\"' ] );
|
||||
$content = str_replace( '>', '>', $content );
|
||||
$content = $this->apply_font_display_swap( $content );
|
||||
|
||||
if ( ! rocket_direct_filesystem()->is_dir( $this->cache_busting_path ) ) {
|
||||
rocket_mkdir_p( $this->cache_busting_path );
|
||||
}
|
||||
|
||||
return rocket_put_content( $this->filepath, $content );
|
||||
}
|
||||
}
|
195
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Smush.php
vendored
Normal file
195
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Smush.php
vendored
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use Smush\Core\Settings;
|
||||
use WP_Rocket\Admin\Options;
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with Smush
|
||||
*
|
||||
* @since 3.4.2
|
||||
* @author Soponar Cristina
|
||||
*/
|
||||
class Smush implements Subscriber_Interface {
|
||||
/**
|
||||
* WP Options API instance
|
||||
*
|
||||
* @var Options
|
||||
*/
|
||||
private $options_api;
|
||||
|
||||
/**
|
||||
* Options instance
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Subscribed events for Smush.
|
||||
*
|
||||
* @since 3.4.2
|
||||
* @author Soponar Cristina
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! rocket_has_constant( 'WP_SMUSH_VERSION' ) ) {
|
||||
return [
|
||||
'activate_wp-smushit/wp-smush.php' => [ 'maybe_deactivate_rocket_lazyload', 10 ],
|
||||
];
|
||||
}
|
||||
|
||||
$prefix = rocket_get_constant( 'WP_SMUSH_PREFIX', 'wp-smush-' );
|
||||
|
||||
return [
|
||||
"update_option_{$prefix}settings" => [ 'maybe_deactivate_rocket_lazyload', 11 ],
|
||||
"update_site_option_{$prefix}settings" => [ 'maybe_deactivate_rocket_lazyload', 11 ],
|
||||
"update_option_{$prefix}lazy_load" => [ 'maybe_deactivate_rocket_lazyload', 11 ],
|
||||
"update_site_option_{$prefix}lazy_load" => [ 'maybe_deactivate_rocket_lazyload', 11 ],
|
||||
'rocket_maybe_disable_lazyload_helper' => 'is_smush_lazyload_active',
|
||||
'rocket_maybe_disable_iframes_lazyload_helper' => 'is_smush_iframes_lazyload_active',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 3.5.5
|
||||
*
|
||||
* @param Options $options_api WP Options API instance.
|
||||
* @param Options_Data $options WP Rocket Options instance.
|
||||
*/
|
||||
public function __construct( Options $options_api, Options_Data $options ) {
|
||||
$this->options_api = $options_api;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable WP Rocket lazyload when activating WP Smush and values are already in the database.
|
||||
*
|
||||
* @since 3.4.2
|
||||
* @author Soponar Cristina
|
||||
*/
|
||||
public function maybe_deactivate_rocket_lazyload() {
|
||||
$enabled = $this->is_smush_lazyload_enabled();
|
||||
$updated = false;
|
||||
|
||||
if ( $enabled['images'] && $this->options->get( 'lazyload' ) ) {
|
||||
$this->options->set( 'lazyload', 0 );
|
||||
$updated = true;
|
||||
}
|
||||
|
||||
if ( $enabled['iframes'] && $this->options->get( 'lazyload_iframes' ) ) {
|
||||
$this->options->set( 'lazyload_iframes', 0 );
|
||||
$updated = true;
|
||||
}
|
||||
|
||||
if ( ! $updated ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->options_api->set( 'settings', $this->options->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "Smush" to the provided array if WP Smush lazyload is enabled for images.
|
||||
*
|
||||
* @since 3.4.2
|
||||
* @author Soponar Cristina
|
||||
*
|
||||
* @param array $disable_images_lazyload Array with plugins which disable lazyload functionality.
|
||||
* @return array A list of plugin names.
|
||||
*/
|
||||
public function is_smush_lazyload_active( array $disable_images_lazyload ) {
|
||||
$enabled = $this->is_smush_lazyload_enabled();
|
||||
|
||||
if ( $enabled['images'] ) {
|
||||
$disable_images_lazyload[] = __( 'Smush', 'rocket' );
|
||||
}
|
||||
|
||||
return $disable_images_lazyload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "Smush" to the provided array if WP Smush lazyload is enabled for iframes.
|
||||
*
|
||||
* @since 3.5.5
|
||||
*
|
||||
* @param array $disable_iframes_lazyload Array with plugins which disable lazyload functionality.
|
||||
* @return array A list of plugin names.
|
||||
*/
|
||||
public function is_smush_iframes_lazyload_active( $disable_iframes_lazyload ) {
|
||||
$enabled = $this->is_smush_lazyload_enabled();
|
||||
|
||||
if ( $enabled['iframes'] ) {
|
||||
$disable_iframes_lazyload[] = __( 'Smush', 'rocket' );
|
||||
}
|
||||
|
||||
return $disable_iframes_lazyload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if Smush’s lazyload is enabled for each type of content.
|
||||
*
|
||||
* @since 3.5.5
|
||||
*
|
||||
* @return array {
|
||||
* @var bool $images True when lazyload is enabled for images. False otherwise.
|
||||
* @var bool $iframes True when lazyload is enabled for iframes. False otherwise.
|
||||
* }
|
||||
*/
|
||||
private function is_smush_lazyload_enabled() {
|
||||
$enabled = [
|
||||
'images' => false,
|
||||
'iframes' => false,
|
||||
];
|
||||
|
||||
if ( ! class_exists( '\Smush\Core\Settings' ) ) {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
if ( ! method_exists( '\Smush\Core\Settings', 'get_instance' ) ) {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
$smush_settings = Settings::get_instance();
|
||||
|
||||
if ( ! method_exists( $smush_settings, 'get' ) || ! method_exists( $smush_settings, 'get_setting' ) ) {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
if ( ! $smush_settings->get( 'lazy_load' ) ) {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
$prefix = rocket_get_constant( 'WP_SMUSH_PREFIX', 'wp-smush-' );
|
||||
$formats = $smush_settings->get_setting( $prefix . 'lazy_load' );
|
||||
$formats = ! empty( $formats['format'] ) && is_array( $formats['format'] ) ? array_filter( $formats['format'] ) : [];
|
||||
|
||||
$image_formats = array_intersect_key(
|
||||
$formats,
|
||||
// Allowlist image formats.
|
||||
[
|
||||
'jpeg' => false,
|
||||
'png' => false,
|
||||
'gif' => false,
|
||||
'svg' => false,
|
||||
]
|
||||
);
|
||||
|
||||
if ( ! empty( $image_formats ) ) {
|
||||
// One or several image formats are enabled in Smush.
|
||||
$enabled['images'] = true;
|
||||
}
|
||||
|
||||
if ( ! empty( $formats['iframe'] ) ) {
|
||||
// Iframe is enabled in Smush.
|
||||
$enabled['iframes'] = true;
|
||||
}
|
||||
|
||||
return $enabled;
|
||||
}
|
||||
}
|
50
wp-content/plugins/wp-rocket/inc/ThirdParty/ReturnTypesTrait.php
vendored
Normal file
50
wp-content/plugins/wp-rocket/inc/ThirdParty/ReturnTypesTrait.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty;
|
||||
|
||||
trait ReturnTypesTrait {
|
||||
|
||||
/**
|
||||
* Returns false.
|
||||
*
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function return_false() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true.
|
||||
*
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public function return_true() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty string.
|
||||
*
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @return string Empty string
|
||||
*/
|
||||
public function return_empty_string() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty array.
|
||||
*
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @return array Empty array.
|
||||
*/
|
||||
public function return_empty_array() {
|
||||
return [];
|
||||
}
|
||||
}
|
101
wp-content/plugins/wp-rocket/inc/ThirdParty/ServiceProvider.php
vendored
Normal file
101
wp-content/plugins/wp-rocket/inc/ThirdParty/ServiceProvider.php
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty;
|
||||
|
||||
use WP_Rocket\Engine\Container\ServiceProvider\AbstractServiceProvider;
|
||||
|
||||
/**
|
||||
* Service provider for WP Rocket third party compatibility
|
||||
*
|
||||
* @since 3.3
|
||||
*/
|
||||
class ServiceProvider extends AbstractServiceProvider {
|
||||
|
||||
/**
|
||||
* 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 = [
|
||||
'mobile_subscriber',
|
||||
'woocommerce_subscriber',
|
||||
'syntaxhighlighter_subscriber',
|
||||
'elementor_subscriber',
|
||||
'bridge_subscriber',
|
||||
'ngg_subscriber',
|
||||
'smush_subscriber',
|
||||
'imagify_webp_subscriber',
|
||||
'shortpixel_webp_subscriber',
|
||||
'ewww_webp_subscriber',
|
||||
'optimus_webp_subscriber',
|
||||
'bigcommerce_subscriber',
|
||||
'beaverbuilder_subscriber',
|
||||
'amp_subscriber',
|
||||
'litespeed_subscriber',
|
||||
'simple_custom_css',
|
||||
'pdfembedder',
|
||||
'divi',
|
||||
];
|
||||
|
||||
/**
|
||||
* Registers the subscribers in the container
|
||||
*
|
||||
* @since 3.3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
$options = $this->getContainer()->get( 'options' );
|
||||
|
||||
$this->getContainer()
|
||||
->share( 'mobile_subscriber', 'WP_Rocket\Subscriber\Third_Party\Plugins\Mobile_Subscriber' );
|
||||
$this->getContainer()
|
||||
->share( 'elementor_subscriber', 'WP_Rocket\ThirdParty\Plugins\PageBuilder\Elementor' )
|
||||
->withArgument( $options );
|
||||
$this->getContainer()
|
||||
->share( 'woocommerce_subscriber', 'WP_Rocket\ThirdParty\Plugins\Ecommerce\WooCommerceSubscriber' );
|
||||
$this->getContainer()
|
||||
->share( 'syntaxhighlighter_subscriber', 'WP_Rocket\Subscriber\Third_Party\Plugins\SyntaxHighlighter_Subscriber' );
|
||||
$this->getContainer()
|
||||
->share( 'bridge_subscriber', 'WP_Rocket\ThirdParty\Themes\Bridge' )
|
||||
->withArgument( $options );
|
||||
$this->getContainer()
|
||||
->share( 'divi', 'WP_Rocket\ThirdParty\Themes\Divi' )
|
||||
->withArgument( $this->getContainer()->get( 'options_api' ) )
|
||||
->withArgument( $options );
|
||||
$this->getContainer()
|
||||
->share( 'ngg_subscriber', 'WP_Rocket\Subscriber\Third_Party\Plugins\NGG_Subscriber' );
|
||||
$this->getContainer()
|
||||
->share( 'smush_subscriber', 'WP_Rocket\ThirdParty\Plugins\Smush' )
|
||||
->withArgument( $this->getContainer()->get( 'options_api' ) )
|
||||
->withArgument( $this->getContainer()->get( 'options' ) );
|
||||
$this->getContainer()
|
||||
->share( 'imagify_webp_subscriber', 'WP_Rocket\Subscriber\Third_Party\Plugins\Images\Webp\Imagify_Subscriber' )
|
||||
->withArgument( $options );
|
||||
$this->getContainer()
|
||||
->share( 'shortpixel_webp_subscriber', 'WP_Rocket\Subscriber\Third_Party\Plugins\Images\Webp\ShortPixel_Subscriber' )
|
||||
->withArgument( $options );
|
||||
$this->getContainer()
|
||||
->share( 'ewww_webp_subscriber', 'WP_Rocket\Subscriber\Third_Party\Plugins\Images\Webp\EWWW_Subscriber' )
|
||||
->withArgument( $options );
|
||||
$this->getContainer()
|
||||
->share( 'optimus_webp_subscriber', 'WP_Rocket\Subscriber\Third_Party\Plugins\Images\Webp\Optimus_Subscriber' );
|
||||
$this->getContainer()
|
||||
->share( 'bigcommerce_subscriber', 'WP_Rocket\Subscriber\Third_Party\Plugins\Ecommerce\BigCommerce_Subscriber' );
|
||||
$this->getContainer()
|
||||
->share( 'beaverbuilder_subscriber', 'WP_Rocket\ThirdParty\Plugins\PageBuilder\BeaverBuilder' );
|
||||
$this->getContainer()
|
||||
->share( 'amp_subscriber', 'WP_Rocket\ThirdParty\Plugins\Optimization\AMP' )
|
||||
->withArgument( $options )->withArgument( $this->getContainer()->get( 'cdn_subscriber' ) );
|
||||
$this->getContainer()
|
||||
->share( 'litespeed_subscriber', 'WP_Rocket\Subscriber\Third_Party\Hostings\Litespeed_Subscriber' );
|
||||
$this->getContainer()
|
||||
->share( 'simple_custom_css', 'WP_Rocket\ThirdParty\Plugins\SimpleCustomCss' )
|
||||
->withArgument( WP_ROCKET_CACHE_BUSTING_PATH )->withArgument( WP_ROCKET_CACHE_BUSTING_URL );
|
||||
$this->getContainer()
|
||||
->share( 'pdfembedder', 'WP_Rocket\ThirdParty\Plugins\PDFEmbedder' );
|
||||
}
|
||||
}
|
22
wp-content/plugins/wp-rocket/inc/ThirdParty/SubscriberFactoryInterface.php
vendored
Normal file
22
wp-content/plugins/wp-rocket/inc/ThirdParty/SubscriberFactoryInterface.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Interface for Subscriber Factories
|
||||
*
|
||||
* @since 3.6.3
|
||||
*/
|
||||
interface SubscriberFactoryInterface {
|
||||
|
||||
/**
|
||||
* Get a Subscriber Interface object.
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @return Subscriber_Interface
|
||||
*/
|
||||
public function get_subscriber();
|
||||
}
|
97
wp-content/plugins/wp-rocket/inc/ThirdParty/Themes/Bridge.php
vendored
Normal file
97
wp-content/plugins/wp-rocket/inc/ThirdParty/Themes/Bridge.php
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Themes;
|
||||
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Compatibility class for Bridge theme
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*/
|
||||
class Bridge implements Subscriber_Interface {
|
||||
/**
|
||||
* Options instance
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
$current_theme = wp_get_theme();
|
||||
|
||||
if ( 'Bridge' !== $current_theme->get( 'Name' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'rocket_lazyload_background_images' => 'disable_lazyload_background_images',
|
||||
'update_option_qode_options_proya' => [ 'maybe_clear_cache', 10, 2 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Options_Data $options WP Rocket options instance.
|
||||
*/
|
||||
public function __construct( Options_Data $options ) {
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable lazyload for background images when using Bridge theme
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function disable_lazyload_background_images() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe clear WP Rocket cache when Bridge custom CSS/JS is updated
|
||||
*
|
||||
* @since 3.3.7
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param array $old_value Previous option values.
|
||||
* @param array $new_value New option values.
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_clear_cache( $old_value, $new_value ) {
|
||||
$clear = false;
|
||||
|
||||
if ( $this->options->get( 'minify_css', 0 ) ) {
|
||||
if ( isset( $old_value['custom_css'], $new_value['custom_css'] ) && $old_value['custom_css'] !== $new_value['custom_css'] ) {
|
||||
$clear = true;
|
||||
}
|
||||
|
||||
if ( isset( $old_value['custom_svg_css'], $new_value['custom_svg_css'] ) && $old_value['custom_svg_css'] !== $new_value['custom_svg_css'] ) {
|
||||
$clear = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->options->get( 'minify_js', 0 ) ) {
|
||||
if ( isset( $old_value['custom_js'], $new_value['custom_js'] ) && $old_value['custom_js'] !== $new_value['custom_js'] ) {
|
||||
$clear = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $clear ) {
|
||||
rocket_clean_domain();
|
||||
rocket_clean_minify();
|
||||
}
|
||||
}
|
||||
}
|
123
wp-content/plugins/wp-rocket/inc/ThirdParty/Themes/Divi.php
vendored
Normal file
123
wp-content/plugins/wp-rocket/inc/ThirdParty/Themes/Divi.php
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Themes;
|
||||
|
||||
use WP_Rocket\Admin\Options;
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class Divi implements Subscriber_Interface {
|
||||
/**
|
||||
* Options API instance.
|
||||
*
|
||||
* @var Options
|
||||
*/
|
||||
private $options_api;
|
||||
|
||||
/**
|
||||
* WP Rocket options instance.
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Instantiate the class
|
||||
*
|
||||
* @param Options $options_api Options API instance.
|
||||
* @param Options_Data $options WP Rocket options instance.
|
||||
*/
|
||||
public function __construct( Options $options_api, Options_Data $options ) {
|
||||
$this->options_api = $options_api;
|
||||
$this->options = $options;
|
||||
}
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
$events = [
|
||||
'switch_theme' => [ 'maybe_disable_youtube_preview', PHP_INT_MAX, 2 ],
|
||||
];
|
||||
|
||||
if ( ! self::is_divi() ) {
|
||||
return $events;
|
||||
}
|
||||
|
||||
$events['rocket_exclude_js'] = 'exclude_js';
|
||||
$events['rocket_maybe_disable_youtube_lazyload_helper'] = 'add_divi_to_description';
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes Divi's Salvatorre script from JS minification
|
||||
*
|
||||
* Prevent an error after minification/concatenation
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @param array $excluded_js An array of JS paths to be excluded.
|
||||
* @return array the updated array of paths
|
||||
*/
|
||||
public function exclude_js( $excluded_js ) {
|
||||
if ( ! rocket_get_constant( 'ET_BUILDER_URI' ) ) {
|
||||
return $excluded_js;
|
||||
}
|
||||
|
||||
$excluded_js[] = str_replace( home_url(), '', rocket_get_constant( 'ET_BUILDER_URI' ) . '/scripts/salvattore.min.js' );
|
||||
|
||||
return $excluded_js;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the Replace Youtube iframe by preview thumbnail option if new theme (or parent) is Divi
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @param string $name Name of the new theme.
|
||||
* @param WP_Theme $theme instance of the new theme.
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_disable_youtube_preview( $name, $theme ) {
|
||||
if ( ! self::is_divi( $theme ) ) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->options->set( 'lazyload_youtube', 0 );
|
||||
$this->options_api->set( 'settings', $this->options->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Divi to the array of items disabling Youtube lazyload
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @param array $disable_youtube_lazyload Array of items names.
|
||||
* @return array
|
||||
*/
|
||||
public function add_divi_to_description( $disable_youtube_lazyload ) {
|
||||
if ( ! self::is_divi() ) {
|
||||
return $disable_youtube_lazyload;
|
||||
}
|
||||
|
||||
$disable_youtube_lazyload[] = 'Divi';
|
||||
|
||||
return $disable_youtube_lazyload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current theme (or parent) is Divi
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @param WP_Theme $theme Instance of the theme.
|
||||
*/
|
||||
private static function is_divi( $theme = null ) {
|
||||
$theme = $theme instanceof WP_Theme ? $theme : wp_get_theme();
|
||||
|
||||
return ( 'Divi' === $theme->get( 'Name' ) || 'divi' === $theme->get_template() );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user