Commit inicial powerservice

This commit is contained in:
Gabriel
2026-10-19 12:45:45 -06:00
commit ad85486fe2
10158 changed files with 2736804 additions and 0 deletions
@@ -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;
}
}
@@ -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;
}
}
@@ -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' ] );
}
}
@@ -0,0 +1,192 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
class Godaddy implements Subscriber_Interface {
use ReturnTypesTrait;
/**
* Godaddy vip url
*
* @var string
*/
private $vip_url = '';
/**
* Godaddy constructor.
*
* @param string $vip_url Godaddy vip url.
*/
public function __construct( $vip_url = '' ) {
$this->vip_url = method_exists( '\WPaas\Plugin', 'vip' ) ? \WPaas\Plugin::vip() : $vip_url;
}
/**
* Returns an array of events that this subscriber wants to listen to.
*
* @see Subscriber_Interface.
*
* @since 3.9.1
*
* @return array
*/
public static function get_subscribed_events() {
return [
'rocket_varnish_field_settings' => 'varnish_field',
'rocket_display_input_varnish_auto_purge' => [ 'return_false' ],
'set_rocket_wp_cache_define' => [ 'return_true' ],
'rocket_cache_mandatory_cookies' => [ 'return_empty_array', PHP_INT_MAX ],
'rocket_htaccess_mod_rewrite' => [ 'return_false' ],
'rocket_htaccess_mod_expires' => [ 'remove_html_expire', 5 ],
'before_rocket_clean_domain' => 'clean_domain',
'before_rocket_clean_file' => 'clean_file',
'before_rocket_clean_home' => [ 'clean_home', 10, 2 ],
];
}
/**
* Changes the text on the Varnish one-click block.
*
* @since 3.9.1
*
* @param array $settings Field settings data.
*
* @return array modified field settings data.
*/
public function varnish_field( $settings ): array {
$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' ),
'GoDaddy'
);
return $settings;
}
/**
* Remove expiration on HTML to prevent issue with Varnish cache.
*
* @since 3.9.1
*
* @param string $rules htaccess rules.
*
* @return string
*/
public function remove_html_expire( $rules ): string {
$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;
}
/**
* Call the Varnish server to purge the cache with GoDaddy.
*
* @since 3.9.1
*
* @return void
*/
public function clean_domain() {
$this->purge_request( 'BAN' );
}
/**
* Call the Varnish server to purge a specific URL with GoDaddy.
*
* @since 3.9.1
*
* @param string $url URL to purge.
*
* @return void
*/
public function clean_file( $url ) {
$this->purge_request( 'BAN', $url );
}
/**
* Call the Varnish server to purge the home with GoDaddy.
*
* @since 3.9.1
*
* @param string $root root URL.
* @param string $lang language code.
*
* @return void
*/
public function clean_home( $root, $lang ) {
$home_url = trailingslashit( get_rocket_i18n_home_url( $lang ) );
$home_pagination_url = $home_url . trailingslashit( $GLOBALS['wp_rewrite']->pagination_base );
$this->purge_request( 'BAN', $home_url );
$this->purge_request( 'BAN', $home_pagination_url );
}
/**
* Perform the call to the Varnish server to purge
*
* @since 3.9.1
* @source WPaaS\Cache
*
* @param string $method can be BAN or PURGE.
* @param string $url URL to purge.
*
* @return void
*/
private function purge_request( string $method, string $url = '' ) {
if ( empty( $this->vip_url ) ) {
return;
}
if ( empty( $url ) ) {
$url = home_url();
}
$host = wp_parse_url( $url, PHP_URL_HOST );
$url = untrailingslashit( set_url_scheme( str_replace( $host, $this->vip_url, $url ), 'http' ) );
wp_cache_flush();
// This forces the APC cache to flush across the server.
update_option( 'gd_system_last_cache_flush', time() );
wp_remote_request(
esc_url_raw( $url ),
[
'method' => $method,
'blocking' => false,
'headers' => [
'Host' => $host,
],
]
);
}
/**
* Performs these actions during the plugin activation
*
* @since 3.9.1
*
* @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.9.1
*
* @return void
*/
public function activate_no_htaccess_html_expire() {
add_filter( 'rocket_htaccess_mod_expires', [ $this, 'remove_htaccess_html_expire' ] );
}
}
@@ -0,0 +1,151 @@
<?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['GROUPONE_BRAND_NAME'] ) ) {
$group_one_brand_name = strtolower( sanitize_text_field( wp_unslash( $_SERVER['GROUPONE_BRAND_NAME'] ) ) );
switch ( $group_one_brand_name ) {
case 'one.com':
self::$hostname = 'onecom';
return 'onecom';
case 'proisp.no':
self::$hostname = 'proisp';
return 'proisp';
}
}
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';
}
if ( isset( $_SERVER['HTTP_WPXCLOUD'] ) ) {
self::$hostname = 'wpxcloud';
return 'wpxcloud';
}
if ( isset( $_SERVER['X-LSCACHE'] ) ) {
self::$hostname = 'litespeed';
return 'litespeed';
}
if ( class_exists( '\WPaas\Plugin' ) ) {
self::$hostname = 'godaddy';
return 'godaddy';
}
if ( isset( $_SERVER['KINSTA_CACHE_ZONE'] ) ) {
self::$hostname = 'kinsta';
return 'kinsta';
}
if ( defined( 'WP_NINUKIS_WP_NAME' ) || class_exists( 'NinukisCaching' ) ) {
self::$hostname = 'pressidium';
return self::$hostname;
}
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 );
}
}
@@ -0,0 +1,60 @@
<?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();
case 'wpxcloud':
return new WPXCloud();
case 'litespeed':
return new LiteSpeed();
case 'godaddy':
return new Godaddy();
case 'kinsta':
return new Kinsta();
case 'onecom':
return new OneCom();
case 'proisp':
return new ProIsp();
case 'pressidium':
return new Pressidium();
default:
return new NullSubscriber();
}
}
}
@@ -0,0 +1,163 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
class Kinsta implements Subscriber_Interface {
use ReturnTypesTrait;
/**
* Subscribed events for Kinsta.
*
* @inheritDoc
*/
public static function get_subscribed_events() {
global $kinsta_cache;
$events = [
'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 ],
];
if ( isset( $kinsta_cache ) ) {
$events['after_rocket_clean_domain'] = 'clean_kinsta_cache';
$events['after_rocket_clean_post'] = 'clean_kinsta_post_cache';
$events['rocket_rucss_after_clearing_usedcss'] = 'clean_kinsta_cache_url';
$events['rocket_rucss_complete_job_status'] = 'clean_kinsta_cache_url';
$events['after_rocket_clean_home'] = [ 'clean_kinsta_cache_home', 10, 2 ];
$events['after_rocket_clean_file'] = 'clean_kinsta_cache_url';
$events['wp_rocket_loaded'] = 'remove_partial_purge_hooks';
return $events;
}
$events['admin_notices'] = 'display_error_notice';
return $events;
}
/**
* Clear Kinsta cache when clearing WP Rocket cache
*
* @since 3.0
*
* @return void
*/
public function clean_kinsta_cache() {
global $kinsta_cache;
if ( ! empty( $kinsta_cache->kinsta_cache_purge ) ) {
$kinsta_cache->kinsta_cache_purge->purge_complete_caches();
}
}
/**
* Partially clear Kinsta cache when partially clearing WP Rocket cache
*
* @since 3.0
*
* @param object $post Post object.
* @return void
*/
public function clean_kinsta_post_cache( $post ) {
global $kinsta_cache;
$kinsta_cache->kinsta_cache_purge->initiate_purge( $post->ID, 'post' );
}
/**
* Clears Kinsta cache for the homepage URL when using "Purge this URL" from the admin bar on the front end
*
* @since 3.0.4
*
* @param string $root WP Rocket root cache path.
* @param string $lang Current language.
* @return void
*/
public function clean_kinsta_cache_home( $root = '', $lang = '' ) {
$url = get_rocket_i18n_home_url( $lang );
$url = trailingslashit( $url ) . 'kinsta-clear-cache/';
wp_safe_remote_get(
$url,
[
'blocking' => false,
'timeout' => 0.01,
]
);
}
/**
* Clears Kinsta cache for a specific URL when using "Purge this URL" from the admin bar on the front end
*
* @since 3.0.4
*
* @param string $url URL to purge.
* @return void
*/
public function clean_kinsta_cache_url( $url ) {
$url = trailingslashit( $url ) . 'kinsta-clear-cache/';
wp_safe_remote_get(
$url,
[
'blocking' => false,
'timeout' => 0.01,
]
);
}
/**
* Remove WP Rocket functions on WP core action hooks to prevent triggering a double cache clear.
*
* @since 3.0
*
* @return void
*/
public function remove_partial_purge_hooks() {
// WP core action hooks clean_post() gets hooked into.
$clean_post_hooks = [
// Disables the refreshing of partial cache when content is edited.
'wp_trash_post',
'delete_post',
'clean_post_cache',
'wp_update_comment_count',
];
// Remove rocket_clean_post() from core action hooks.
array_map(
function ( $hook ) {
remove_action( $hook, 'rocket_clean_post' );
},
$clean_post_hooks
);
remove_filter( 'rocket_clean_files', 'rocket_clean_files_users' );
}
/**
* Display notice when we are on Kinsta but the plugin is not present.
*
* @return void
*/
public function display_error_notice() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$screen = get_current_screen();
if ( 'settings_page_wprocket' !== $screen->id ) {
return;
}
rocket_notice_html(
[
'status' => 'error',
'dismissible' => '',
// translators: %1$s = opening link tag, %2$s = closing link tag.
'message' => sprintf( __( 'Your installation seems to be missing core Kinsta files managing Cache clearing, which will prevent your Kinsta installation and WP Rocket from working correctly. Please get in touch with Kinsta support through your %1$sMyKinsta%2$s account to resolve this issue.', 'rocket' ), '<a href="https://my.kinsta.com/login/" target="_blank">', '</a>' ),
]
);
}
}
@@ -0,0 +1,153 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Event_Management\Subscriber_Interface;
class LiteSpeed implements Subscriber_Interface {
/**
* Litespeed headers
*
* @var array
*/
private $headers = [];
/**
* Subscribed events for Litespeed.
*
* @since 3.9.2
* @inheritDoc
*/
public static function get_subscribed_events() {
return [
'before_rocket_clean_domain' => 'litespeed_clean_domain',
'before_rocket_clean_file' => 'litespeed_clean_file',
'before_rocket_clean_home' => [ 'litespeed_clean_home', 10, 2 ],
];
}
/**
* Add purge headers to the request
*
* @since 3.9.2
*
* @return void
*/
public function litespeed_send_headers() {
if ( empty( $this->headers ) ) {
return;
}
foreach ( $this->headers as $header ) {
@header( "X-LiteSpeed-Purge: {$header}", false ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
}
}
/**
* Purge all pages in LiteSpeed
*
* @since 3.9.2
*
* @return void
*/
public function litespeed_clean_domain() {
$this->litespeed_header_purge_all();
}
/**
* Purge a specific page
*
* @since 3.9.2
*
* @param string $url The url to purge.
*
* @return void
*/
public function litespeed_clean_file( $url ) {
$this->litespeed_header_purge_url( trailingslashit( $url ) );
}
/**
* Purge the homepage and its pagination
*
* @since 3.9.2
*
* @param string $root The path of home cache file.
* @param string $lang The current lang to purge.
*
* @return void
*/
public function litespeed_clean_home( $root, $lang ) {
$home_url = trailingslashit( get_rocket_i18n_home_url( $lang ) );
$urls = [
'home' => trailingslashit( get_rocket_i18n_home_url( $lang ) ),
'pagination' => $home_url . trailingslashit( $GLOBALS['wp_rewrite']->pagination_base ),
];
array_walk(
$urls,
function ( &$url ) {
$url = wp_parse_url( $url, PHP_URL_PATH );
}
);
$urls = array_filter( $urls );
if ( empty( $urls ) ) {
return;
}
$this->send_header( 'X-LiteSpeed-Purge: ' . $urls['home'] );
$this->send_header( 'X-LiteSpeed-Purge: ' . $urls['pagination'] );
}
/**
* Set LiteSpeed header for the URL to purge
*
* @since 3.9.2
*
* @param string $url The URL to purge.
*
* @return void
*/
private function litespeed_header_purge_url( $url ) {
$path = wp_parse_url( $url, PHP_URL_PATH );
if ( ! $path ) {
return;
}
$header = 'X-LiteSpeed-Purge: ' . $path;
$this->send_header( $header );
}
/**
* Set LiteSpeed header to purge all
*
* @since 3.9.2
*
* @return void
*/
private function litespeed_header_purge_all() {
$this->send_header( 'X-LiteSpeed-Purge: *', true );
}
/**
* If header is not in header_list() send it
*
* @since 3.9.2
*
* @param string $header To be sent.
* @param boolean $replace header.
*
* @return void
*/
private function send_header( $header, $replace = false ) {
if ( headers_sent() || in_array( $header, headers_list(), true ) ) {
return;
}
$this->headers[] = $header;
@header( $header, $replace ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
}
}
@@ -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' ] );
}
}
@@ -0,0 +1,170 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
/**
* Subscriber for compatibility with One.com hosting.
*
* @since 3.12.1
*/
class OneCom implements Subscriber_Interface {
use ReturnTypesTrait;
/**
* Array of events this subscriber wants to listen to.
*
* @since 3.6.3
*
* @return array
*/
public static function get_subscribed_events() {
return [
'pre_get_rocket_option_cdn' => 'maybe_enable_cdn_option',
'pre_get_rocket_option_cdn_cnames' => 'maybe_update_cdn_cname',
'pre_get_rocket_option_cdn_zone' => 'maybe_update_cdn_zone',
'rocket_cdn_reject_files' => 'exclude_from_cdn',
'rocket_disable_cdn_option_change' => 'is_oc_cdn_enabled',
'rocket_cdn_settings_fields' => 'disable_cdn_change',
'do_rocket_varnish_http_purge' => 'is_varnish_active',
'rocket_varnish_field_settings' => 'maybe_set_varnish_addon_title',
'rocket_display_input_varnish_auto_purge' => 'should_display_varnish_auto_purge_input',
'rocket_display_rocketcdn_cta' => 'return_false',
'rocket_display_rocketcdn_status' => 'return_false',
'rocket_promote_rocketcdn_notice' => 'return_false',
];
}
/**
* Check if one.com cdn is enabled.
*
* @return boolean
*/
public function is_oc_cdn_enabled(): bool {
return rocket_get_constant( 'vcaching', false ) && rest_sanitize_boolean( get_option( 'oc_cdn_enabled' ) );
}
/**
* Enable CDN option.
*
* @param string|null $cdn CDN Option.
* @return bool|null
*/
public function maybe_enable_cdn_option( ?string $cdn ) {
return $this->is_oc_cdn_enabled() ? true : $cdn;
}
/**
* Update CNAME
*
* @param string|null $cname CDN CNAME.
* @return array|null
*/
public function maybe_update_cdn_cname( ?string $cname ) {
return $this->is_oc_cdn_enabled() ? [ $this->build_cname() ] : $cname;
}
/**
* Update CDN Zones.
*
* @param string|null $zone CDN ZONES.
* @return array|null
*/
public function maybe_update_cdn_zone( ?string $zone ) {
return $this->is_oc_cdn_enabled() ? [ 'all' ] : $zone;
}
/**
* Exclude files from being rewritten.
* From 3.12.5.2 we are excluding new wp-content directory paths if it's not the normal one.
*
* @param array $files Array of files to be excluded.
* @return array
*/
public function exclude_from_cdn( array $files ): array {
if ( ! $this->is_oc_cdn_enabled() ) {
return $files;
}
$files[] = '/wp-includes/(.*)';
return $files;
}
/**
* Disable CDN option change.
*
* @param array $settings CDN field settings data.
* @return array
*/
public function disable_cdn_change( array $settings ): array {
if ( ! $this->is_oc_cdn_enabled() ) {
return $settings;
}
$settings['cdn']['container_class'][] = 'wpr-isDisabled';
$settings['cdn']['input_attr']['disabled'] = 1;
return $settings;
}
/**
* Purge varnish cache.
*
* @return boolean
*/
public function should_display_varnish_auto_purge_input(): bool {
return ! $this->is_varnish_active();
}
/**
* Set varnish addon title
*
* @param array $settings Varnish settings field data.
* @return array
*/
public function maybe_set_varnish_addon_title( array $settings ): array {
// Bail out if varnish is disabled.
if ( ! $this->is_varnish_active() ) {
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' ),
'One.com'
);
return $settings;
}
/**
* Check if varnish option is enabled.
*
* @return boolean
*/
public function is_varnish_active() {
return rocket_get_constant( 'vcaching', false ) && rest_sanitize_boolean( get_option( 'varnish_caching_enable' ) );
}
/**
* Build CDN CNAME.
*
* @return string
*/
public function build_cname(): string {
if ( ! isset( $_SERVER['ONECOM_DOMAIN_NAME'] ) && ! isset( $_SERVER['HTTP_HOST'] ) ) {
return '';
}
$domain_name = sanitize_text_field( wp_unslash( $_SERVER['ONECOM_DOMAIN_NAME'] ) );
$http_host = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) );
$is_subdomain = '' === str_replace( $domain_name, '', $http_host ) ? false : true;
return $is_subdomain ? "usercontent.one/wp/$http_host" : "usercontent.one/wp/www.$http_host";
}
}
@@ -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;
}
}
@@ -0,0 +1,137 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use NinukisCaching;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
class Pressidium extends AbstractNoCacheHost {
use ReturnTypesTrait;
/**
* Returns an array of events that this subscriber wants to listen to.
*
* @see Subscriber_Interface.
*
* @return array
*/
public static function get_subscribed_events() {
$events = [];
if ( defined( 'WP_NINUKIS_WP_NAME' ) ) {
$events['rocket_varnish_field_settings'] = 'pressidium_varnish_field';
$events['rocket_display_input_varnish_auto_purge'] = 'return_false';
$events['rocket_cache_mandatory_cookies'] = [ 'return_empty_array', PHP_INT_MAX ];
$events['admin_init'] = 'clear_cache_after_pressidium';
}
if ( class_exists( 'NinukisCaching' ) ) {
$events['after_rocket_clean_domain'] = 'clean_pressidium';
$events['after_rocket_clean_file'] = [ 'purge_url', 10, 1 ];
$events['after_rocket_clean_post'] = [ 'clean_post', 10, 2 ];
}
return $events;
}
/**
* Changes the text on the Varnish one-click block.
*
* @since 3.0
* @author Remy Perona
*
* @param array $settings Field settings data.
*
* @return array modified field settings data.
*/
public function pressidium_varnish_field( $settings ) {
// Translators: %s = Hosting name.
$settings['varnish_auto_purge']['title'] = sprintf( __( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ), 'Pressidium' );
return $settings;
}
/**
* Clear WP Rocket cache after purged the Varnish cache via Pressidium Hosting
*
* @since 2.5.11
*
* @return void
*/
public function clear_cache_after_pressidium() {
if ( isset( $_POST['purge-all'] ) && current_user_can( 'manage_options' ) && check_admin_referer( WP_NINUKIS_WP_NAME . '-caching' ) ) {
// Clear all caching files.
rocket_clean_domain();
}
}
/**
* Call the cache server to purge the cache with Pressidium hosting.
*
* @since 2.6
*
* @return void
*/
public function clean_pressidium() {
$plugin = NinukisCaching::get_instance();
$plugin->purgeAllCaches();
}
/**
* Returns the path of URLs.
*
* @param array|string $urls Urls we want to get paths.
* @return array|void the path.
*/
private function get_paths( $urls ) {
if ( ! is_array( $urls ) ) {
$urls = (array) $urls;
}
$paths = [];
foreach ( $urls as $url ) {
$parsed_url = get_rocket_parse_url( $url );
$paths[] = $parsed_url['path'];
}
return $paths;
}
/**
* Purge the cache of Pressidium from paths.
*
* @param array $paths Paths of pages we are going to purge cache.
*
* @return void
*/
private function purge_cache( $paths ) {
NinukisCaching::get_instance()->purge_cache( $paths );
}
/**
* Purge the cache for the given URL.
*
* @param string|array $url URL we want to purge.
*
* @return void
*/
public function purge_url( $url ) {
$paths = $this->get_paths( $url );
$this->purge_cache( $paths );
}
/**
* Clean cache of post.
*
* @param WP_Post $post Post that need to be cleaned.
* @param array $purge_urls URLs that need to be purged.
*
* @return void
*/
public function clean_post( $post, $purge_urls ) {
// Purge related urls.
$paths = $this->get_paths( $purge_urls );
$this->purge_cache( $paths );
}
}
@@ -0,0 +1,66 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Subscriber for compatibility with PRO ISP hosting.
*
* @since 3.13.1
*/
class ProIsp implements Subscriber_Interface {
/**
* Array of events this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
return [
'do_rocket_varnish_http_purge' => 'is_varnish_active',
'rocket_varnish_field_settings' => 'maybe_set_varnish_addon_title',
'rocket_display_input_varnish_auto_purge' => 'should_display_varnish_auto_purge_input',
];
}
/**
* Purge varnish cache.
*
* @return boolean
*/
public function should_display_varnish_auto_purge_input(): bool {
return ! $this->is_varnish_active();
}
/**
* Set varnish addon title
*
* @param array $settings Varnish settings field data.
* @return array
*/
public function maybe_set_varnish_addon_title( array $settings ): array {
// Bail out if varnish is disabled.
if ( ! $this->is_varnish_active() ) {
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' ),
'PRO ISP'
);
return $settings;
}
/**
* Check if varnish option is enabled.
*
* @return boolean
*/
public function is_varnish_active() {
return rocket_get_constant( 'vcaching', false ) && rest_sanitize_boolean( get_option( 'varnish_caching_enable' ) );
}
}
@@ -0,0 +1,101 @@
<?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;
}
if ( ! current_user_can( 'rocket_purge_cache' ) ) {
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
}
}
@@ -0,0 +1,52 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
use WP_Rocket\Dependencies\League\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() )
->addTag( 'hosting_subscriber' );
}
}
}
@@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\ThirdParty\{NullSubscriber, 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',
'after_rocket_clean_file' => 'purge_url',
'rocket_rucss_after_clearing_usedcss' => 'purge_url',
'rocket_rucss_complete_job_status' => 'purge_url',
'after_rocket_clean_term' => [ 'purge_term_urls', 10, 2 ],
'rocket_after_clean_terms' => 'purge_urls',
];
}
/**
* Purge SpinUpWP cache after clean domain.
*
* @since 3.6.2
*
* @return void
*/
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
*
* @return void
*/
public function remove_actions() {
remove_action( 'switch_theme', 'rocket_clean_domain' );
}
/**
* Purge URL in SpinUpWP
*
* @param string $url URL.
*
* @return void
*/
public function purge_url( $url ) {
if ( ! function_exists( 'spinupwp_purge_url' ) ) {
return;
}
spinupwp_purge_url( trailingslashit( $url ) );
}
/**
* Purge multiple URLs
*
* @param array $urls Array of URLs.
*
* @return void
*/
public function purge_urls( $urls ) {
foreach ( $urls as $url ) {
$this->purge_url( $url );
}
}
/**
* Purge URLs related to a term
*
* @param WP_Term $term The term object.
* @param array $urls Array of URLs.
*
* @return void
*/
public function purge_term_urls( $term, $urls ) {
$this->purge_urls( $urls );
}
}
@@ -0,0 +1,117 @@
<?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;
}
if ( ! current_user_can( 'rocket_preload_cache' ) ) {
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;
}
}
@@ -0,0 +1,90 @@
<?php
namespace WP_Rocket\ThirdParty\Hostings;
use WP_Rocket\ThirdParty\ReturnTypesTrait;
/**
* Compatibility class for WPX Cloud.
*/
class WPXCloud extends AbstractNoCacheHost {
/**
* Array of events this subscriber wants to listen to.
*
* @return array
*/
public static function get_subscribed_events() {
return [
'rocket_varnish_ip' => 'varnish_ip',
'rocket_display_input_varnish_auto_purge' => 'return_false',
'do_rocket_varnish_http_purge' => 'return_true',
'rocket_varnish_field_settings' => 'varnish_addon_title',
'after_rocket_htaccess_rules' => 'append_cache_control_header',
];
}
/**
* Adds WPX Cloud Varnish IP to varnish IPs array
*
* @param array $varnish_ip Varnish IP.
* @return array
*/
public function varnish_ip( $varnish_ip ) {
if ( ! is_array( $varnish_ip ) ) {
$varnish_ip = (array) $varnish_ip;
}
$varnish_ip[] = '127.0.0.1:6081';
return $varnish_ip;
}
/**
* Displays custom title for the Varnish add-on
*
* @param array $settings Array of settings for Varnish.
* @return array
*/
public function varnish_addon_title( array $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' ),
'WPX'
);
return $settings;
}
/**
* Append cache control header.
*
* @return string
*/
public function append_cache_control_header(): string {
$header = '<IfModule mod_headers.c>' . PHP_EOL;
$header .= 'Header append Cache-Control " s-maxage=3600, stale-while-revalidate=21600" "expr=%{CONTENT_TYPE} =~ m#text/html#"' . PHP_EOL;
$header .= '</IfModule>' . PHP_EOL;
return $header;
}
/**
* Performs these actions during the plugin activation.
*
* @return void
*/
public function activate() {
parent::activate();
add_action( 'rocket_activation', [ $this, 'append_cache_control_header_on_activation' ] );
}
/**
* Append cache control header.
*
* @return void
*/
public function append_cache_control_header_on_activation() {
add_filter( 'after_rocket_htaccess_rules', [ $this, 'append_cache_control_header' ] );
}
}
@@ -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();
}
}