add wp-rocket

This commit is contained in:
nguyen dung
2022-02-18 19:09:35 +07:00
parent 39b8cb3612
commit 3110d00ee7
927 changed files with 271703 additions and 2 deletions

View 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;
}
}

View 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;
}
}

View 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' ] );
}
}

View 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 );
}
}

View 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();
}
}
}

View 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' ] );
}
}

View 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;
}
}

View 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
}
}

View 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() );
}
}
}

View 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' );
}
}

View 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;
}
}

View 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();
}
}