home
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Ads;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class Adthrive implements Subscriber_Interface {
|
||||
/**
|
||||
* Returns an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events(): array {
|
||||
return [
|
||||
'wp_rocket_upgrade' => [ 'add_delay_js_exclusion_on_plugin_update', 20, 2 ],
|
||||
'activate_adthrive-ads/adthrive-ads.php' => 'add_delay_js_exclusion',
|
||||
'pre_update_option_wp_rocket_settings' => [ 'maybe_add_delay_js_exclusion', 10, 2 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds adthrive to delay JS exclusion field
|
||||
*
|
||||
* @since 3.9.3
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_delay_js_exclusion() {
|
||||
$options = get_option( 'wp_rocket_settings', [] );
|
||||
|
||||
if (
|
||||
! isset( $options['delay_js'] )
|
||||
||
|
||||
empty( $options['delay_js'] )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$exclusions = $options['delay_js_exclusions'] ?? [];
|
||||
|
||||
if ( in_array( 'adthrive', $exclusions, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$exclusions[] = 'adthrive';
|
||||
|
||||
$options['delay_js_exclusions'] = $exclusions;
|
||||
|
||||
update_option( 'wp_rocket_settings', $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds adthrive to delay JS exclusion field on update to 3.9.3
|
||||
*
|
||||
* @since 3.9.3
|
||||
*
|
||||
* @param string $new_version Plugin new version.
|
||||
* @param string $old_version Plugin old version.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_delay_js_exclusion_on_plugin_update( $new_version, $old_version ) {
|
||||
if ( version_compare( $old_version, '3.9.3', '>' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_plugin_active( 'adthrive-ads/adthrive-ads.php' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->add_delay_js_exclusion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Adthrive pattern when saving WPR options and Adthrive is enabled
|
||||
*
|
||||
* @since 3.9.3
|
||||
*
|
||||
* @param array $value The new, unserialized option value.
|
||||
* @param array $old_value The old option value.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function maybe_add_delay_js_exclusion( $value, $old_value ): array {
|
||||
if ( ! is_plugin_active( 'adthrive-ads/adthrive-ads.php' ) ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ( empty( $value['delay_js'] ) ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (
|
||||
isset( $old_value['delay_js'] )
|
||||
&&
|
||||
$old_value['delay_js'] === $value['delay_js']
|
||||
) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (
|
||||
isset( $value['delay_js_exclusions'] )
|
||||
&&
|
||||
in_array( 'adthrive', $value['delay_js_exclusions'], true )
|
||||
) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$value['delay_js_exclusions'][] = 'adthrive';
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,503 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\CDN;
|
||||
|
||||
use WP_Rocket\Admin\{Options, Options_Data};
|
||||
use WP_Rocket\Engine\Admin\Beacon\Beacon;
|
||||
use WP_Rocket\Engine\Deactivation\DeactivationInterface;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Compatibility class for cloudflare.
|
||||
*/
|
||||
class Cloudflare implements Subscriber_Interface, DeactivationInterface {
|
||||
/**
|
||||
* Options instance.
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Options API instance.
|
||||
*
|
||||
* @var Options
|
||||
*/
|
||||
private $options_api;
|
||||
|
||||
/**
|
||||
* Beacon
|
||||
*
|
||||
* @var Beacon Beacon instance.
|
||||
*/
|
||||
private $beacon;
|
||||
|
||||
/**
|
||||
* CloudflareFacade instance.
|
||||
*
|
||||
* @var CloudflareFacade
|
||||
*/
|
||||
private $facade;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Options_Data $options Options instance.
|
||||
* @param Options $options_api Options API instance.
|
||||
* @param Beacon $beacon Beacon instance.
|
||||
* @param CloudflareFacade $facade CloudflareFacade instance.
|
||||
*/
|
||||
public function __construct( Options_Data $options, Options $options_api, Beacon $beacon, CloudflareFacade $facade ) {
|
||||
$this->options = $options;
|
||||
$this->options_api = $options_api;
|
||||
$this->beacon = $beacon;
|
||||
$this->facade = $facade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'admin_notices' => [
|
||||
[ 'display_server_pushing_mode_notice' ],
|
||||
[ 'display_apo_cookies_notice' ],
|
||||
[ 'display_apo_cache_notice' ],
|
||||
],
|
||||
'rocket_display_input_do_cloudflare' => 'hide_addon_radio',
|
||||
'rocket_cloudflare_field_settings' => 'update_addon_field',
|
||||
'pre_get_rocket_option_do_cloudflare' => 'disable_cloudflare_option',
|
||||
'after_rocket_clean_domain' => 'purge_cloudflare',
|
||||
'after_rocket_clean_files' => 'purge_cloudflare_partial',
|
||||
'rocket_rucss_complete_job_status' => 'purge_cloudflare_after_usedcss',
|
||||
'rocket_rucss_after_clearing_usedcss' => 'purge_cloudflare_after_usedcss',
|
||||
'admin_post_rocket_enable_separate_mobile_cache' => 'enable_separate_mobile_cache',
|
||||
'rocket_cdn_helper_addons' => 'add_cdn_helper_message',
|
||||
'init' => 'unregister_cloudflare_clean_on_post',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Display notice for server pushing mode.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function display_server_pushing_mode_notice() {
|
||||
if ( ! rocket_get_constant( 'CLOUDFLARE_PLUGIN_DIR' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! rocket_get_constant( 'CLOUDFLARE_HTTP2_SERVER_PUSH_ACTIVE' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
// If current screen is wprocket settings.
|
||||
if (
|
||||
isset( $screen->id )
|
||||
&&
|
||||
'settings_page_wprocket' !== $screen->id
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if current user has required capapabilities.
|
||||
if ( ! current_user_can( 'rocket_manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If RUCSS is enabled.
|
||||
if ( ! (bool) $this->options->get( 'remove_unused_css', 0 ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
|
||||
$notice_name = 'cloudflare_server_push';
|
||||
|
||||
if ( in_array( $notice_name, (array) $boxes, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
// translators: %1$s = plugin name.
|
||||
__( '%1$s: Cloudflare\'s HTTP/2 Server Push is incompatible with the features of Remove Unused CSS and Combine CSS files. We strongly recommend disabling it.', 'rocket' ),
|
||||
'<strong>WP Rocket</strong>'
|
||||
);
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'warning',
|
||||
'dismissible' => '',
|
||||
'message' => $message,
|
||||
'id' => 'cloudflare_server_push_notice',
|
||||
'dismiss_button' => $notice_name,
|
||||
'dismiss_button_class' => 'button-primary',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide WP Rocket CF Addon activation button if the official CF plugin is enabled
|
||||
*
|
||||
* @param bool $enable True to display, False otherwise.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hide_addon_radio( $enable ) {
|
||||
if ( ! $this->is_plugin_active() ) {
|
||||
return $enable;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates WP Rocket CF Addon field when the official CF plugin is enabled
|
||||
*
|
||||
* @param array $settings Array of values to populate the field.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function update_addon_field( $settings ) {
|
||||
if ( ! $this->is_plugin_active() ) {
|
||||
return $settings;
|
||||
}
|
||||
|
||||
$settings['do_cloudflare']['title'] = __( 'Your site is using the official Cloudflare plugin. We have enabled Cloudflare auto-purge for compatibility. If you have APO activated, it is also compatible.', 'rocket' );
|
||||
$settings['do_cloudflare']['description'] = __( 'Cloudflare cache will be purged each time WP Rocket clears its cache to ensure content is always up-to-date.', 'rocket' );
|
||||
$settings['do_cloudflare']['helper'] = '';
|
||||
$settings['do_cloudflare']['settings_page'] = '';
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable WP Rocket CF option when Cloudflare plugin is enabled
|
||||
*
|
||||
* @param mixed $value Pre option value.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function disable_cloudflare_option( $value ) {
|
||||
if ( ! $this->is_plugin_active() ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a notice when APO is enabled and mandatory/dynamic cookies exists
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function display_apo_cookies_notice() {
|
||||
if ( ! $this->can_display_notice() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
empty( get_rocket_cache_mandatory_cookies() )
|
||||
&&
|
||||
empty( get_rocket_cache_dynamic_cookies() )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$doc = $this->beacon->get_suggest( 'cloudflare_apo' );
|
||||
|
||||
$message = sprintf(
|
||||
// Translators: %1$s = strong opening tag, %2$s = strong closing tag.
|
||||
__( '%1$sWP Rocket:%2$s You are using "Dynamic Cookies Cache". Cloudflare APO is not yet compatible with that feature.', 'rocket' ) . '<br>',
|
||||
'<strong>',
|
||||
'</strong>'
|
||||
);
|
||||
$message .= sprintf(
|
||||
// Translators:%1$s = opening <a> tag, %2$s = closing </a> tag.
|
||||
__( 'You should either disable Cloudflare APO or check with the theme/plugin requiring the use of “Dynamic Cookies Cache” developers for an alternative way to be page-cache friendly. %1$sMore info%2$s', 'rocket' ),
|
||||
'<a href="' . esc_url( $doc['url'] ) . '" data-beacon-article="' . esc_attr( $doc['id'] ) . '" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
);
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'warning',
|
||||
'dismissible' => '',
|
||||
'message' => $message,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a notice when there is a mismatch between WP Rocket separate cache by mobile value and APO cache by device type
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function display_apo_cache_notice() {
|
||||
if ( ! $this->can_display_notice() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cf_device_type = get_option( 'automatic_platform_optimization_cache_by_device_type', [] );
|
||||
|
||||
if ( ! key_exists( 'value', $cf_device_type ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$mobile_cache = $this->options->get( 'do_caching_mobile_files', 0 );
|
||||
|
||||
if ( (int) $mobile_cache === (int) $cf_device_type['value'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$doc = $this->beacon->get_suggest( 'cloudflare_apo' );
|
||||
|
||||
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
|
||||
|
||||
if (
|
||||
1 === (int) $mobile_cache
|
||||
&&
|
||||
0 === (int) $cf_device_type['value']
|
||||
) {
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'warning',
|
||||
'dismissible' => '',
|
||||
'message' => sprintf(
|
||||
// Translators: %1$s = strong opening tag, %2$s = strong closing tag, %3$s = opening <a> tag, %4$s = closing </a> tag, %5$s = opening <a> tag.
|
||||
__( '%1$sWP Rocket:%2$s You are using "Separate cache files for mobile devices". You need to activate "Cache by Device Type" %3$ssetting%5$s on Cloudflare APO to serve the right version of the cache. %4$sMore info%5$s', 'rocket' ),
|
||||
'<strong>',
|
||||
'</strong>',
|
||||
'<a href="' . esc_url( admin_url( 'options-general.php?page=cloudflare' ) ) . '">',
|
||||
'<a href="' . esc_url( $doc['url'] ) . '" data-beacon-article="' . esc_attr( $doc['id'] ) . '" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
]
|
||||
);
|
||||
} elseif (
|
||||
0 === (int) $mobile_cache
|
||||
&&
|
||||
1 === (int) $cf_device_type['value']
|
||||
&&
|
||||
! in_array( __FUNCTION__, (array) $boxes, true )
|
||||
) {
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'warning',
|
||||
'message' => sprintf(
|
||||
// Translators: %1$s = strong opening tag, %2$s = strong closing tag.
|
||||
__( '%1$sWP Rocket:%2$s You have "Cache by Device Type" enabled on Cloudflare APO. If you judge it necessary for the website to have a different cache on mobile and desktop, we suggest you enable our “Separate Cache Files for Mobiles Devices” to ensure the generated cache is accurate.', 'rocket' ),
|
||||
'<strong>',
|
||||
'</strong>'
|
||||
),
|
||||
'dismiss_button' => __FUNCTION__,
|
||||
'dismissible' => '',
|
||||
'action' => 'enable_separate_mobile_cache',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if APO notices should be displayed
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function can_display_notice(): bool {
|
||||
if ( ! current_user_can( 'rocket_manage_options' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
if (
|
||||
isset( $screen->id )
|
||||
&&
|
||||
'settings_page_wprocket' !== $screen->id
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if ( ! $this->is_plugin_active() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->is_apo_enabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge everything on Cloudflare
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function purge_cloudflare() {
|
||||
if ( ! $this->is_plugin_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->facade->purge_everything();
|
||||
}
|
||||
|
||||
/**
|
||||
* Purges posts when using purge this URL button
|
||||
*
|
||||
* @param array $urls Array of URLs.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function purge_cloudflare_partial( $urls ) {
|
||||
if ( ! $this->is_plugin_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_ids = array_filter( array_map( 'url_to_postid', $urls ) );
|
||||
|
||||
$this->facade->purge_urls( $post_ids );
|
||||
}
|
||||
|
||||
/**
|
||||
* Purges CF after Used CSS generation or clean
|
||||
*
|
||||
* @param string $url URL to purge.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function purge_cloudflare_after_usedcss( $url ) {
|
||||
if ( ! $this->is_plugin_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_id = url_to_postid( $url );
|
||||
|
||||
if ( empty( $post_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->facade->purge_urls( $post_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable separate cache for mobile option
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enable_separate_mobile_cache() {
|
||||
check_admin_referer( 'rocket_enable_separate_mobile_cache' );
|
||||
|
||||
if ( ! current_user_can( 'rocket_manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->options->set( 'cache_mobile', 1 );
|
||||
$this->options->set( 'do_caching_mobile_files', 1 );
|
||||
$this->options_api->set( 'settings', $this->options->get_options() );
|
||||
|
||||
wp_safe_redirect( wp_get_referer() );
|
||||
rocket_get_constant( 'WP_ROCKET_IS_TESTING', false ) ? wp_die() : exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if CF plugin is enabled & credentials saved
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_plugin_active(): bool {
|
||||
if ( ! is_plugin_active( 'cloudflare/cloudflare.php' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
empty( get_option( 'cloudflare_api_email', '' ) )
|
||||
||
|
||||
empty( get_option( 'cloudflare_api_key', '' ) )
|
||||
||
|
||||
empty( get_option( 'cloudflare_cached_domain_name', '' ) )
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if CF APO is enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_apo_enabled(): bool {
|
||||
$is_apo_enabled = get_option( 'automatic_platform_optimization', [] );
|
||||
|
||||
if ( ! key_exists( 'value', $is_apo_enabled ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $is_apo_enabled['value'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the helper message on the CDN settings.
|
||||
*
|
||||
* @param string[] $addons Name from the addon that requires the helper message.
|
||||
* @return string[]
|
||||
*/
|
||||
public function add_cdn_helper_message( array $addons ): array {
|
||||
if ( ! $this->is_plugin_active() ) {
|
||||
return $addons;
|
||||
}
|
||||
$addons[] = 'Cloudflare';
|
||||
return $addons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge Cloudflare on deactivate.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deactivate() {
|
||||
$this->purge_cloudflare();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister Call on clean posts.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unregister_cloudflare_clean_on_post() {
|
||||
$this->unregister_callback( 'deleted_post', 'purgeCacheByRelevantURLs' );
|
||||
$this->unregister_callback( 'transition_post_status', 'purgeCacheOnPostStatusChange', PHP_INT_MAX );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a callback.
|
||||
*
|
||||
* @param string $hook Hook on which to unregister.
|
||||
* @param string $method The callback to unregister.
|
||||
* @param int $priority the priority from the callback.
|
||||
* @return void
|
||||
*/
|
||||
protected function unregister_callback( string $hook, string $method, int $priority = 10 ) {
|
||||
global $wp_filter;
|
||||
|
||||
if ( ! key_exists( $hook, $wp_filter ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$original_wp_filter = $wp_filter[ $hook ]->callbacks;
|
||||
|
||||
if ( ! key_exists( $priority, $original_wp_filter ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $original_wp_filter[ $priority ] as $key => $config ) {
|
||||
|
||||
if ( substr( $key, - strlen( $method ) ) !== $method ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unset( $wp_filter[ $hook ]->callbacks[ $priority ][ $key ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\CDN;
|
||||
|
||||
use CF\WordPress\Hooks;
|
||||
|
||||
class CloudflareFacade {
|
||||
/**
|
||||
* Hooks class instance
|
||||
*
|
||||
* @var Hooks
|
||||
*/
|
||||
private $hooks;
|
||||
|
||||
/**
|
||||
* Instanciate the hooks class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function set_hooks() {
|
||||
$this->hooks = new Hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls purge everything from CF hooks class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function purge_everything() {
|
||||
if ( is_null( $this->hooks ) ) {
|
||||
$this->set_hooks();
|
||||
}
|
||||
|
||||
$this->hooks->purgeCacheEverything();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls purge relevant URLs from CF hooks class
|
||||
*
|
||||
* @param int|array $post_ids Post ID or array of post IDs.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function purge_urls( $post_ids ) {
|
||||
if ( is_null( $this->hooks ) ) {
|
||||
$this->set_hooks();
|
||||
}
|
||||
|
||||
$this->hooks->purgeCacheByRelevantURLs( $post_ids );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with ConvertPlug.
|
||||
*/
|
||||
class ConvertPlug implements Subscriber_Interface {
|
||||
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with ConvertPlug.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
$events = [];
|
||||
if ( ! self::isActivated() ) {
|
||||
return $events;
|
||||
}
|
||||
|
||||
$events['rocket_rucss_inline_atts_exclusions'] = 'excluded_from_rucss';
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the plugin is activated.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isActivated() {
|
||||
return defined( 'CP_VERSION' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude css from RUCSS.
|
||||
*
|
||||
* @param array $excluded excluded css.
|
||||
* @return array
|
||||
*/
|
||||
public function excluded_from_rucss( $excluded ) {
|
||||
$excluded[] = 'cp-form-css';
|
||||
return $excluded;
|
||||
}
|
||||
}
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
<?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 WP_Rocket\Traits\Config_Updater;
|
||||
|
||||
/**
|
||||
* BigCommerce compatibility subscriber
|
||||
*
|
||||
* @since 3.3.7
|
||||
*/
|
||||
class BigCommerce implements Event_Manager_Aware_Subscriber_Interface {
|
||||
use 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_bigcommerce/bigcommerce.php' => [ 'activate_bigcommerce', 11 ],
|
||||
'deactivate_bigcommerce/bigcommerce.php' => [ 'deactivate_bigcommerce', 11 ],
|
||||
];
|
||||
|
||||
if ( function_exists( 'bigcommerce_init' ) ) {
|
||||
$events['update_option_bigcommerce_login_page_id'] = [ 'after_update_single_option', 10, 2 ];
|
||||
$events['update_option_bigcommerce_account_page_id'] = [ 'after_update_single_option', 10, 2 ];
|
||||
$events['update_option_bigcommerce_address_page_id'] = [ 'after_update_single_option', 10, 2 ];
|
||||
$events['update_option_bigcommerce_orders_page_id'] = [ 'after_update_single_option', 10, 2 ];
|
||||
$events['update_option_bigcommerce_cart_page_id'] = [ 'after_update_single_option', 10, 2 ];
|
||||
$events['update_option_bigcommerce_checkout_page_id'] = [ 'after_update_single_option', 10, 2 ];
|
||||
|
||||
$events['shutdown'] = 'maybe_update_config';
|
||||
$events['transition_post_status'] = [ 'maybe_exclude_page', 10, 3 ];
|
||||
$events['rocket_cache_reject_uri'] = [
|
||||
[ 'exclude_pages' ],
|
||||
];
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add exclusions when activating the BigCommerce plugin
|
||||
*
|
||||
* @since 3.3.7
|
||||
*/
|
||||
public function activate_bigcommerce() {
|
||||
$this->event_manager->add_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_pages' ] );
|
||||
|
||||
// Update .htaccess file rules.
|
||||
flush_rocket_htaccess();
|
||||
|
||||
// Regenerate the config file.
|
||||
rocket_generate_config_file();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove exclusions when deactivating the BigCommerce plugin
|
||||
*
|
||||
* @since 3.3.7
|
||||
*/
|
||||
public function deactivate_bigcommerce() {
|
||||
$this->event_manager->remove_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_pages' ] );
|
||||
|
||||
// Update .htaccess file rules.
|
||||
flush_rocket_htaccess();
|
||||
|
||||
// Regenerate the config file.
|
||||
rocket_generate_config_file();
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe regenerate the htaccess & config file if a BigCommerce page is published
|
||||
*
|
||||
* @since 3.3.7
|
||||
*
|
||||
* @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 ( get_option( 'bigcommerce_login_page_id' ) !== $post->ID && get_option( 'bigcommerce_account_page_id' ) !== $post->ID && get_option( 'bigcommerce_address_page_id' ) !== $post->ID && get_option( 'bigcommerce_orders_page_id' ) !== $post->ID && get_option( 'bigcommerce_cart_page_id' ) !== $post->ID && get_option( 'bigcommerce_checkout_page_id' ) !== $post->ID ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update .htaccess file rules.
|
||||
flush_rocket_htaccess();
|
||||
|
||||
// Regenerate the config file.
|
||||
rocket_generate_config_file();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude BigCommerce login, cart, checkout, account, address and orders pages from caching
|
||||
*
|
||||
* @since 3.3.7
|
||||
*
|
||||
* @param array $urls An array of excluded pages.
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_pages( $urls ) {
|
||||
$checkout_urls = $this->exclude_page( get_option( 'bigcommerce_checkout_page_id' ) );
|
||||
$cart_urls = $this->exclude_page( get_option( 'bigcommerce_cart_page_id' ) );
|
||||
$account_urls = $this->exclude_page( get_option( 'bigcommerce_account_page_id' ) );
|
||||
$login_urls = $this->exclude_page( get_option( 'bigcommerce_login_page_id' ) );
|
||||
$address_urls = $this->exclude_page( get_option( 'bigcommerce_address_page_id' ) );
|
||||
$orders_urls = $this->exclude_page( get_option( 'bigcommerce_orders_page_id' ) );
|
||||
|
||||
return array_merge( $urls, $checkout_urls, $cart_urls, $account_urls, $login_urls, $address_urls, $orders_urls );
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes BigCommerce checkout page from cache
|
||||
*
|
||||
* @since 3.3.7
|
||||
*
|
||||
* @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 ) {
|
||||
return $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;
|
||||
}
|
||||
}
|
||||
+633
@@ -0,0 +1,633 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Ecommerce;
|
||||
|
||||
use WP_Rocket\Engine\Optimization\DelayJS\HTML;
|
||||
use WP_Rocket\Event_Management\Event_Manager;
|
||||
use WP_Rocket\Event_Management\Event_Manager_Aware_Subscriber_Interface;
|
||||
use WP_Rocket\Logger\Logger;
|
||||
use WP_Rocket\Traits\Config_Updater;
|
||||
|
||||
/**
|
||||
* WooCommerce compatibility
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
class WooCommerceSubscriber implements Event_Manager_Aware_Subscriber_Interface {
|
||||
use Config_Updater;
|
||||
|
||||
/**
|
||||
* The WordPress Event Manager
|
||||
*
|
||||
* @var Event_Manager;
|
||||
*/
|
||||
protected $event_manager;
|
||||
|
||||
/**
|
||||
* Delay JS HTML class.
|
||||
*
|
||||
* @var HTML
|
||||
*/
|
||||
private $delayjs_html;
|
||||
|
||||
/**
|
||||
* WooCommerceSubscriber constructor.
|
||||
*
|
||||
* @param HTML $delayjs_html DelayJS HTML class.
|
||||
*/
|
||||
public function __construct( HTML $delayjs_html ) {
|
||||
$this->delayjs_html = $delayjs_html;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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_preload_exclude_urls'] = [
|
||||
[ 'exclude_pages' ],
|
||||
];
|
||||
$events['rocket_cache_query_strings'] = 'cache_geolocation_query_string';
|
||||
$events['rocket_cpcss_excluded_taxonomies'] = 'exclude_product_attributes_cpcss';
|
||||
$events['after_rocket_clean_post_urls'] = [ 'reformat_shop_url_for_preload', 10, 2 ];
|
||||
|
||||
$events['rocket_exclude_post_taxonomy'] = 'exclude_product_shipping_taxonomy';
|
||||
|
||||
/**
|
||||
* 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['init'] = [ 'serve_cache_empty_cart', 11 ];
|
||||
$events['template_redirect'] = [ 'cache_empty_cart', -1 ];
|
||||
$events['switch_theme'] = 'delete_cache_empty_cart';
|
||||
}
|
||||
|
||||
$events['wp_head'] = 'show_empty_product_gallery_with_delayJS';
|
||||
$events['rocket_delay_js_exclusions'] = 'show_notempty_product_gallery_with_delayJS';
|
||||
|
||||
$events['wp_ajax_woocommerce_product_ordering'] = [ 'disallow_rocket_clean_post', 9 ];
|
||||
$events['woocommerce_after_product_ordering'] = [ 'allow_rocket_clean_post' ];
|
||||
}
|
||||
|
||||
if ( class_exists( 'WC_API' ) ) {
|
||||
$events['rocket_cache_reject_uri'][] = [ 'exclude_wc_rest_api' ];
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reformat Shop URL to prevent error on preload.
|
||||
*
|
||||
* @param array $urls urls cleared.
|
||||
* @param WP_Post $object post object.
|
||||
* @return array
|
||||
*/
|
||||
public function reformat_shop_url_for_preload( array $urls, $object ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound
|
||||
$post_type = $object->post_type;
|
||||
if ( 'product' !== $post_type ) {
|
||||
return $urls;
|
||||
}
|
||||
$post_type_archive = get_post_type_archive_link( $post_type );
|
||||
if ( ! $post_type_archive ) {
|
||||
return $urls;
|
||||
}
|
||||
|
||||
// Rename the caching filename for SSL URLs.
|
||||
$filename = 'index';
|
||||
if ( is_ssl() ) {
|
||||
$filename .= '-https';
|
||||
}
|
||||
|
||||
$post_type_archive = trailingslashit( $post_type_archive );
|
||||
$index_url = $post_type_archive . $filename . '.html';
|
||||
$index_url_gzip = $post_type_archive . $filename . '.html_gzip';
|
||||
$pagination_url = $post_type_archive . $GLOBALS['wp_rewrite']->pagination_base;
|
||||
|
||||
foreach ( $urls as $index => $url ) {
|
||||
if ( in_array( $url, [ $index_url, $index_url_gzip, $pagination_url ], true ) ) {
|
||||
$urls[ $index ] = $post_type_archive;
|
||||
}
|
||||
}
|
||||
|
||||
return array_unique( $urls );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = '' ) {
|
||||
global $wp_rewrite;
|
||||
$urls = [];
|
||||
|
||||
if ( $page_id <= 0 || (int) get_option( 'page_on_front' ) === $page_id ) {
|
||||
return $urls;
|
||||
}
|
||||
|
||||
if ( 'publish' !== get_post_status( $page_id ) ) {
|
||||
return $urls;
|
||||
}
|
||||
|
||||
if ( $wp_rewrite->use_trailing_slashes ) {
|
||||
$pattern = "?$pattern";
|
||||
}
|
||||
|
||||
$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() );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Exclude product_shipping_class taxonomy from post purge
|
||||
*
|
||||
* @since 3.9.1
|
||||
*
|
||||
* @param array $excluded_taxonomies Array of excluded taxonomies names.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_product_shipping_taxonomy( $excluded_taxonomies ) {
|
||||
$excluded_taxonomies[] = 'product_shipping_class';
|
||||
|
||||
return $excluded_taxonomies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current product page has images in gallery.
|
||||
*
|
||||
* @since 3.9.1
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function product_has_gallery_images() {
|
||||
$product = wc_get_product( get_the_ID() );
|
||||
if ( empty( $product ) ) {
|
||||
return false;
|
||||
}
|
||||
return ! empty( $product->get_gallery_image_ids() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show product gallery main image directly when delay JS is enabled.
|
||||
*
|
||||
* @since 3.9.1
|
||||
*/
|
||||
public function show_empty_product_gallery_with_delayJS() {
|
||||
if ( ! $this->delayjs_html->is_allowed() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_product() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->product_has_gallery_images() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<style>.woocommerce-product-gallery{ opacity: 1 !important; }</style>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude some JS files from delay JS when product gallery has images.
|
||||
*
|
||||
* @since 3.9.1
|
||||
*
|
||||
* @param array $exclusions Exclusions array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function show_notempty_product_gallery_with_delayJS( $exclusions = [] ): array {
|
||||
global $wp_version;
|
||||
|
||||
if ( ! is_array( $exclusions ) ) {
|
||||
$exclusions = (array) $exclusions;
|
||||
}
|
||||
|
||||
if ( ! $this->delayjs_html->is_allowed() ) {
|
||||
return $exclusions;
|
||||
}
|
||||
|
||||
if ( ! is_product() ) {
|
||||
return $exclusions;
|
||||
}
|
||||
|
||||
if ( ! $this->product_has_gallery_images() ) {
|
||||
return $exclusions;
|
||||
}
|
||||
|
||||
$exclusions_gallery = [
|
||||
'/jquery-?[0-9.]*(.min|.slim|.slim.min)?.js',
|
||||
'/woocommerce/assets/js/zoom/jquery.zoom(.min)?.js',
|
||||
'/woocommerce/assets/js/photoswipe/',
|
||||
'/woocommerce/assets/js/flexslider/jquery.flexslider(.min)?.js',
|
||||
'/woocommerce/assets/js/frontend/single-product(.min)?.js',
|
||||
];
|
||||
|
||||
if (
|
||||
isset( $wp_version )
|
||||
&&
|
||||
version_compare( $wp_version, '5.7', '<' )
|
||||
) {
|
||||
$exclusions_gallery[] = '/jquery-migrate(.min)?.js';
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the JS files excluded from delay JS when WC product gallery has images.
|
||||
*
|
||||
* @since 3.10.2
|
||||
*
|
||||
* @param array $exclusions_gallery Array of excluded filepaths.
|
||||
*/
|
||||
$exclusions_gallery = apply_filters( 'rocket_wc_product_gallery_delay_js_exclusions', $exclusions_gallery );
|
||||
|
||||
return array_merge( $exclusions, $exclusions_gallery );
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable post cache clearing during product sorting.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disallow_rocket_clean_post(): void {
|
||||
$this->event_manager->remove_callback( 'clean_post_cache', 'rocket_clean_post' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-enable post cache clearing after product sorting.
|
||||
*
|
||||
* @param integer $product_id ID of sorted product.
|
||||
* @return void
|
||||
*/
|
||||
public function allow_rocket_clean_post( int $product_id ): void {
|
||||
$urls = [];
|
||||
$category_list = wc_get_product_category_list( $product_id );
|
||||
|
||||
if ( preg_match_all( '/<a\s+(?:[^>]*?\s+)?href=(["\'])(?<urls>.*?)\1/i', $category_list, $matches ) ) {
|
||||
$urls = $matches['urls'];
|
||||
}
|
||||
|
||||
$shop_page = get_permalink( wc_get_page_id( 'shop' ) );
|
||||
|
||||
if ( empty( $shop_page ) ) {
|
||||
$shop_page = home_url( 'shop' );
|
||||
}
|
||||
|
||||
$urls[] = $shop_page;
|
||||
|
||||
rocket_clean_files( $urls );
|
||||
$this->event_manager->add_callback( 'clean_post_cache', 'rocket_clean_post' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\I18n;
|
||||
|
||||
use TRP_Translate_Press;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class TranslatePress implements Subscriber_Interface {
|
||||
|
||||
/**
|
||||
* Returns an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! class_exists( 'TRP_Translate_Press' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'rocket_rucss_is_home_url' => [ 'detect_homepage', 10, 2 ],
|
||||
'rocket_has_i18n' => 'is_translatepress',
|
||||
'rocket_i18n_admin_bar_menu' => 'add_langs_to_admin_bar',
|
||||
'rocket_i18n_current_language' => 'set_current_language',
|
||||
'rocket_get_i18n_uri' => 'get_active_languages_uri',
|
||||
'rocket_get_i18n_code' => 'get_active_languages_codes',
|
||||
'rocket_i18n_subdomains' => 'get_active_languages_uri',
|
||||
'rocket_i18n_home_url' => [ 'get_home_url_for_lang', 10, 2 ],
|
||||
'rocket_i18n_translated_post_urls' => [ 'get_translated_post_urls', 10, 4 ],
|
||||
'post_updated' => 'clear_post_languages',
|
||||
'trp_save_editor_translations_regular_strings' => [ 'clear_post_after_updating_translation', 10, 2 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect homepage.
|
||||
*
|
||||
* @param string $home_url home url.
|
||||
* @param string $url url of current page.
|
||||
* @return string
|
||||
*/
|
||||
public function detect_homepage( $home_url, $url ) {
|
||||
$translatepress = TRP_Translate_Press::get_trp_instance();
|
||||
$converter = $translatepress->get_component( 'url_converter' );
|
||||
|
||||
$language = $converter->get_lang_from_url_string( $url );
|
||||
$url_language = $converter->get_url_for_language( $language, home_url() );
|
||||
|
||||
return untrailingslashit( $url ) === untrailingslashit( $url_language ) ? $url : $home_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds TranslatePress as identifier for i18n detection
|
||||
*
|
||||
* @param string|bool $identifier An identifier value, false otherwise.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function is_translatepress( $identifier ) {
|
||||
if (
|
||||
function_exists( 'trp_get_languages' )
|
||||
&&
|
||||
! empty( trp_get_languages( 'nodefault' ) )
|
||||
) {
|
||||
return 'translatepress';
|
||||
}
|
||||
|
||||
return $identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds languages to the admin bar menu
|
||||
*
|
||||
* @param array $langlinks Array of languages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_langs_to_admin_bar( $langlinks ) {
|
||||
$translatepress = TRP_Translate_Press::get_trp_instance();
|
||||
|
||||
$language_switcher = $translatepress->get_component( 'language_switcher' );
|
||||
$settings = $translatepress->get_component( 'settings' );
|
||||
$languages = $translatepress->get_component( 'languages' );
|
||||
$trp_settings = $settings->get_settings();
|
||||
|
||||
$languages_to_display = $trp_settings['publish-languages'];
|
||||
$published_languages = $languages->get_language_names( $languages_to_display );
|
||||
|
||||
foreach ( $published_languages as $code => $name ) {
|
||||
$langlinks[ $code ] = [
|
||||
'code' => $trp_settings['url-slugs'][ $code ],
|
||||
'flag' => $language_switcher->add_flag( $code, $name ),
|
||||
'anchor' => $name,
|
||||
];
|
||||
}
|
||||
|
||||
return $langlinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current language value
|
||||
*
|
||||
* @param string|bool $current_language Current language.
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function set_current_language( $current_language ) {
|
||||
if ( empty( $GLOBALS['TRP_LANGUAGE'] ) ) {
|
||||
return $current_language;
|
||||
}
|
||||
|
||||
return $GLOBALS['TRP_LANGUAGE'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets URLs for active languages
|
||||
*
|
||||
* @param array $urls Array of active languages URI.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_active_languages_uri( $urls ) {
|
||||
if ( ! is_array( $urls ) ) {
|
||||
$urls = (array) $urls;
|
||||
}
|
||||
|
||||
$home_url = home_url();
|
||||
|
||||
$translatepress = TRP_Translate_Press::get_trp_instance();
|
||||
|
||||
$settings = $translatepress->get_component( 'settings' );
|
||||
$languages = $translatepress->get_component( 'languages' );
|
||||
$converter = $translatepress->get_component( 'url_converter' );
|
||||
$trp_settings = $settings->get_settings();
|
||||
|
||||
$languages_to_display = $trp_settings['publish-languages'];
|
||||
$published_languages = $languages->get_language_names( $languages_to_display );
|
||||
|
||||
foreach ( $published_languages as $code => $name ) {
|
||||
$urls[] = $converter->get_url_for_language( $code, $home_url );
|
||||
}
|
||||
|
||||
return $urls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the active languages slugs
|
||||
*
|
||||
* @param Array $codes Array of languages codes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_active_languages_codes( $codes ) {
|
||||
if ( ! is_array( $codes ) ) {
|
||||
$codes = (array) $codes;
|
||||
}
|
||||
|
||||
$translatepress = TRP_Translate_Press::get_trp_instance();
|
||||
|
||||
$settings = $translatepress->get_component( 'settings' );
|
||||
$languages = $translatepress->get_component( 'languages' );
|
||||
$trp_settings = $settings->get_settings();
|
||||
|
||||
$languages_to_display = $trp_settings['publish-languages'];
|
||||
$published_languages = $languages->get_language_names( $languages_to_display );
|
||||
|
||||
foreach ( $published_languages as $code => $name ) {
|
||||
$codes[] = $trp_settings['url-slugs'][ $code ];
|
||||
}
|
||||
|
||||
return $codes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets home URL in given language
|
||||
*
|
||||
* @param string $home_url Home URL.
|
||||
* @param string $lang Language code.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_home_url_for_lang( $home_url, $lang ) {
|
||||
if ( empty( $lang ) ) {
|
||||
return $home_url;
|
||||
}
|
||||
|
||||
$translatepress = TRP_Translate_Press::get_trp_instance();
|
||||
$converter = $translatepress->get_component( 'url_converter' );
|
||||
$settings = $translatepress->get_component( 'settings' );
|
||||
$trp_settings = $settings->get_settings();
|
||||
|
||||
$code = '';
|
||||
|
||||
add_filter( 'trp_add_language_to_home_url_check_for_admin', '__return_false' );
|
||||
|
||||
foreach ( $trp_settings['url-slugs'] as $index => $slug ) {
|
||||
if ( $lang === $slug ) {
|
||||
$code = $index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$url = $converter->get_url_for_language( $code, $home_url );
|
||||
|
||||
remove_filter( 'trp_add_language_to_home_url_check_for_admin', '__return_false' );
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all translations URLs for a post
|
||||
*
|
||||
* @param array $urls Array of translated URLs.
|
||||
* @param string $url URL to use.
|
||||
* @param string $post_type Post type.
|
||||
* @param string $regex Pattern to include at the end.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_translated_post_urls( $urls, $url, $post_type, $regex ) {
|
||||
if ( ! is_array( $urls ) ) {
|
||||
$urls = (array) $urls;
|
||||
}
|
||||
|
||||
$translatepress = TRP_Translate_Press::get_trp_instance();
|
||||
|
||||
$settings = $translatepress->get_component( 'settings' );
|
||||
$languages = $translatepress->get_component( 'languages' );
|
||||
$converter = $translatepress->get_component( 'url_converter' );
|
||||
$trp_settings = $settings->get_settings();
|
||||
|
||||
$languages_to_display = $trp_settings['publish-languages'];
|
||||
$published_languages = $languages->get_language_names( $languages_to_display );
|
||||
|
||||
foreach ( $published_languages as $code => $name ) {
|
||||
$urls[] = wp_parse_url( $converter->get_url_for_language( $code, $url ), PHP_URL_PATH ) . $regex;
|
||||
}
|
||||
|
||||
return $urls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all languages of a specific post
|
||||
*
|
||||
* @param int $post_id Post ID.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear_post_languages( $post_id ) {
|
||||
$translatepress = TRP_Translate_Press::get_trp_instance();
|
||||
|
||||
$converter = $translatepress->get_component( 'url_converter' );
|
||||
$settings = $translatepress->get_component( 'settings' );
|
||||
$trp_settings = $settings->get_settings();
|
||||
|
||||
add_filter( 'trp_add_language_to_home_url_check_for_admin', '__return_false' );
|
||||
|
||||
$clear_urls = [];
|
||||
|
||||
$default_permalink = get_permalink( $post_id );
|
||||
|
||||
foreach ( $trp_settings['translation-languages'] as $language ) {
|
||||
if ( $language === $trp_settings['default-language'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$clear_urls[] = $converter->get_url_for_language( $language, $default_permalink, '' );
|
||||
}
|
||||
|
||||
remove_filter( 'trp_add_language_to_home_url_check_for_admin', '__return_false' );
|
||||
|
||||
if ( empty( $clear_urls ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
rocket_clean_files( $clear_urls );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the post cache when the translation is updated
|
||||
*
|
||||
* @param array $update_strings Array of updated strings.
|
||||
* @param array $settings Array of settings.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear_post_after_updating_translation( $update_strings, $settings ) {
|
||||
$translatepress = TRP_Translate_Press::get_trp_instance();
|
||||
|
||||
$converter = $translatepress->get_component( 'url_converter' );
|
||||
|
||||
if ( empty( $_POST['url'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
return;
|
||||
}
|
||||
|
||||
$url = esc_url_raw( wp_unslash( $_POST['url'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
|
||||
$clear_urls = [];
|
||||
$current_url = remove_query_arg( 'trp-edit-translation', $url );
|
||||
|
||||
foreach ( $settings['translation-languages'] as $language ) {
|
||||
if ( ! empty( $update_strings[ $language ] ) ) {
|
||||
$clear_urls[] = $converter->get_url_for_language( $language, $current_url, '' );
|
||||
}
|
||||
}
|
||||
|
||||
rocket_clean_files( $clear_urls );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\I18n;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
use WP_Filesystem_Direct;
|
||||
use WP_Rocket\ThirdParty\ReturnTypesTrait;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with WPML.
|
||||
*/
|
||||
class WPML implements Subscriber_Interface {
|
||||
use ReturnTypesTrait;
|
||||
|
||||
/**
|
||||
* Filesystem instance.
|
||||
*
|
||||
* @var WP_Filesystem_Direct
|
||||
*/
|
||||
protected $filesystem;
|
||||
|
||||
/**
|
||||
* Instantiate class.
|
||||
*
|
||||
* @param WP_Filesystem_Direct $filesystem Filesystem instance.
|
||||
*/
|
||||
public function __construct( WP_Filesystem_Direct $filesystem = null ) {
|
||||
$this->filesystem = ! empty( $filesystem ) ? $filesystem : rocket_direct_filesystem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Events for subscriber to listen to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
|
||||
$events = [
|
||||
'activate_sitepress-multilingual-cms/sitepress.php' => 'maybe_clear_on_disable',
|
||||
'deactivate_sitepress-multilingual-cms/sitepress.php' => 'maybe_clear_on_disable',
|
||||
];
|
||||
|
||||
if ( ! defined( 'ICL_SITEPRESS_VERSION' ) ) {
|
||||
return $events;
|
||||
}
|
||||
|
||||
$events['rocket_rucss_is_home_url'] = [ 'is_secondary_home', 10, 2 ];
|
||||
$events['rocket_preload_all_to_pending_condition'] = 'clean_only_right_domain';
|
||||
$events['rocket_preload_sitemap_before_queue'] = 'add_languages_sitemaps';
|
||||
$events['after_rocket_clean_home'] = 'remove_root_cached_files';
|
||||
$events['after_rocket_clean_domain'] = 'remove_root_cached_files';
|
||||
$events['pre_update_option_icl_sitepress_settings'] = [ 'on_change_directory_for_default_language_clean_cache', 10, 2 ];
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if page to be processed is secondary homepage.
|
||||
*
|
||||
* @param string $home_url home url.
|
||||
* @param string $url url of current page.
|
||||
* @return string
|
||||
*/
|
||||
public function is_secondary_home( string $home_url, string $url ): string {
|
||||
global $sitepress;
|
||||
|
||||
// Get active languages on site.
|
||||
$languages = $sitepress->get_active_languages();
|
||||
|
||||
foreach ( $languages as $lang ) {
|
||||
$lang_url = $sitepress->language_url( $lang['code'] );
|
||||
|
||||
// Check if current url is a secondary homepage.
|
||||
if ( untrailingslashit( $lang_url ) !== $url ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
return $home_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a condition to clean only urls from the domain when it is the case.
|
||||
*
|
||||
* @param string $condition condition used to clean URLS in the database.
|
||||
* @return string
|
||||
*/
|
||||
public function clean_only_right_domain( $condition ) {
|
||||
global $sitepress;
|
||||
|
||||
$lang = isset( $_GET['lang'] ) && 'all' !== $_GET['lang'] ? sanitize_key( $_GET['lang'] ) : '';// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
if ( ! $lang ) {
|
||||
return $condition;
|
||||
}
|
||||
|
||||
$lang_url = $sitepress->language_url( $lang );
|
||||
|
||||
return ' WHERE url LIKE "' . $lang_url . '%"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add sitemaps from translations.
|
||||
*
|
||||
* @param array $sitemaps list of sitemaps to be fetched.
|
||||
* @return array
|
||||
*/
|
||||
public function add_languages_sitemaps( $sitemaps ) {
|
||||
global $sitepress;
|
||||
|
||||
$new_sitemaps = [];
|
||||
|
||||
// Get active languages on site.
|
||||
$languages = $sitepress->get_active_languages();
|
||||
|
||||
$base_url = home_url();
|
||||
foreach ( $sitemaps as $sitemap ) {
|
||||
$new_sitemaps[] = $sitemap;
|
||||
foreach ( $languages as $lang ) {
|
||||
$lang_url = $sitepress->language_url( $lang['code'] );
|
||||
$new_sitemaps[] = str_replace( $base_url, $lang_url, $sitemap );
|
||||
}
|
||||
}
|
||||
return array_unique( $new_sitemaps );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove root files when WPML is active.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function remove_root_cached_files() {
|
||||
$site_url = home_url();
|
||||
$host_name = wp_parse_url( $site_url, PHP_URL_HOST );
|
||||
$cache_folder_path = _rocket_get_wp_rocket_cache_path() . $host_name . '/';
|
||||
$cache_folder_directory = $this->filesystem->dirlist( $cache_folder_path );
|
||||
|
||||
if ( ! is_array( $cache_folder_directory ) || ! is_array( array_keys( $cache_folder_directory ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( array_keys( $cache_folder_directory ) as $entry ) {
|
||||
if ( $this->filesystem->is_dir( $cache_folder_path . $entry ) ) {
|
||||
continue;
|
||||
}
|
||||
$this->filesystem->delete( $cache_folder_path . $entry );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset cache when changing the option.
|
||||
*
|
||||
* @param array $new new configurations.
|
||||
* @param array $old old configurations.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function on_change_directory_for_default_language_clean_cache( $new, $old ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.newFound
|
||||
if ( ! is_array( $old ) || ! is_array( $new ) ) {
|
||||
return $new;
|
||||
}
|
||||
|
||||
if ( ! key_exists( 'urls', $old ) || ! key_exists( 'directory_for_default_language', $old['urls'] ) || ! key_exists( 'urls', $new ) || ! key_exists( 'directory_for_default_language', $new['urls'] ) || $new['urls']['directory_for_default_language'] === $old['urls']['directory_for_default_language'] ) {
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset WP Rocket Preload.
|
||||
*/
|
||||
do_action( 'rocket_reset_preload' );
|
||||
rocket_clean_domain();
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cache when the option language directory is enabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_clear_on_disable() {
|
||||
$option = get_option( 'icl_sitepress_settings' );
|
||||
if ( ! $option || ! is_array( $option ) || ! key_exists( 'urls', $option ) || ! key_exists( 'directory_for_default_language', $option['urls'] ) || false === $option['urls']['directory_for_default_language'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset WP Rocket Preload.
|
||||
*/
|
||||
do_action( 'rocket_reset_preload' );
|
||||
rocket_clean_cache_dir();
|
||||
rocket_clean_domain();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with Inline Related Posts.
|
||||
*/
|
||||
class InlineRelatedPosts implements Subscriber_Interface {
|
||||
|
||||
|
||||
/**
|
||||
* Subscriber for Inline Related Posts.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! defined( 'IRP_PLUGIN_SLUG' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [ 'rocket_rucss_inline_content_exclusions' => 'exclude_inline_from_rucss' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude inline style from RUCSS.
|
||||
*
|
||||
* @param array $excluded excluded css.
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_inline_from_rucss( $excluded ) {
|
||||
$excluded[] = '.centered-text-area';
|
||||
$excluded[] = '.ctaText';
|
||||
|
||||
return $excluded;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
use WP_Rocket\ThirdParty\ReturnTypesTrait;
|
||||
|
||||
class Jetpack implements Subscriber_Interface {
|
||||
|
||||
use ReturnTypesTrait;
|
||||
|
||||
/**
|
||||
* Option instance.
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
protected $option;
|
||||
|
||||
/**
|
||||
* Instantiate class.
|
||||
*
|
||||
* @param Options_Data $option Option instance.
|
||||
*/
|
||||
public function __construct( Options_Data $option ) {
|
||||
$this->option = $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribed events.
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
$events = [];
|
||||
|
||||
if ( ! class_exists( 'Jetpack' ) ) {
|
||||
return $events;
|
||||
}
|
||||
|
||||
if ( \Jetpack::is_module_active( 'sitemaps' ) ) {
|
||||
$events['rocket_sitemap_preload_list'] = 'add_jetpack_sitemap';
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Jetpack sitemap to preload list
|
||||
*
|
||||
* @param Array $sitemaps Array of sitemaps to preload.
|
||||
* @return Array Updated Array of sitemaps to preload
|
||||
*/
|
||||
public function add_jetpack_sitemap( $sitemaps ) {
|
||||
if ( ! function_exists( 'jetpack_sitemap_uri' ) ) {
|
||||
return $sitemaps;
|
||||
}
|
||||
|
||||
$sitemaps['jetpack'] = jetpack_sitemap_uri();
|
||||
|
||||
return $sitemaps;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with Mod_pagespeed
|
||||
*
|
||||
* @since 3.8.2
|
||||
*/
|
||||
class ModPagespeed implements Subscriber_Interface {
|
||||
|
||||
/**
|
||||
* Subscribed events for Pagespeed module.
|
||||
*
|
||||
* @since 3.8.2
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function get_subscribed_events(): array {
|
||||
return [
|
||||
'admin_notices' => 'show_admin_notice',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mod_pagespeed is enabled on this server with and cache the result on transient.
|
||||
*
|
||||
* @since 3.8.2
|
||||
*
|
||||
* @return bool Status of mod_pagespeed.
|
||||
*/
|
||||
private function has_pagespeed_with_cache() {
|
||||
$has_pagespeed = get_transient( 'rocket_mod_pagespeed_enabled' );
|
||||
|
||||
if ( false === $has_pagespeed ) {
|
||||
$has_pagespeed = $this->has_pagespeed();
|
||||
set_transient( 'rocket_mod_pagespeed_enabled', (int) $has_pagespeed, DAY_IN_SECONDS );
|
||||
}
|
||||
|
||||
return 1 === (int) $has_pagespeed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mod_pagespeed is enabled on this server.
|
||||
*
|
||||
* @since 3.8.2
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function has_pagespeed(): bool {
|
||||
if ( false === strpos( ini_get( 'disable_functions' ), 'apache_get_modules' ) ) {
|
||||
$apache_module_loaded = apache_mod_loaded( 'mod_pagespeed', false );
|
||||
|
||||
if ( $apache_module_loaded ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$home_request = wp_remote_get(
|
||||
home_url(),
|
||||
[
|
||||
'timeout' => 3,
|
||||
'sslverify' => apply_filters( 'https_local_ssl_verify', false ), // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
|
||||
]
|
||||
);
|
||||
|
||||
$headers = wp_remote_retrieve_headers( $home_request );
|
||||
|
||||
if ( empty( $headers ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ( ! empty( $headers['X-Mod-Pagespeed'] ) || ! empty( $headers['X-Page-Speed'] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show admin notice message.
|
||||
*
|
||||
* @since 3.8.2
|
||||
*/
|
||||
public function show_admin_notice() {
|
||||
if ( ! current_user_can( 'rocket_manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'settings_page_wprocket' !== get_current_screen()->id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $this->has_pagespeed_with_cache() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notice_name = 'rocket_error_mod_pagespeed';
|
||||
|
||||
if ( in_array( $notice_name, (array) get_user_meta( get_current_user_id(), 'rocket_boxes', true ), true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// translators: %1$s is WP Rocket plugin name, %2$s is opening <a> tag, %3$s is closing </a> tag.
|
||||
$error_message = sprintf( __( '<strong>%1$s</strong>: Mod PageSpeed is not compatible with this plugin and may cause unexpected results. %2$sMore Info%3$s', 'rocket' ), rocket_get_constant( 'WP_ROCKET_PLUGIN_NAME' ), '<a target="_blank" href="https://docs.wp-rocket.me/article/1376-mod-pagespeed">', '</a>' );
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'error',
|
||||
'message' => $error_message,
|
||||
'dismissible' => '',
|
||||
'dismiss_button' => $notice_name,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<?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', 20 ],
|
||||
'rocket_cache_query_strings' => 'is_amp_compatible_callback',
|
||||
];
|
||||
|
||||
if ( function_exists( 'is_amp_endpoint' ) ) {
|
||||
$events['update_option_amp-options'] = 'generate_config_file';
|
||||
$events['rocket_delay_js_exclusions'] = 'exclude_script_from_delay_js';
|
||||
}
|
||||
|
||||
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 ) {
|
||||
if ( ! function_exists( 'is_amp_endpoint' ) ) {
|
||||
return $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() {
|
||||
// No endpoint function means we're not running amp here.
|
||||
if ( ! function_exists( 'is_amp_endpoint' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We can get a false negative from is_amp_endpoint when web stories is active, so we have to make sure neither is in play.
|
||||
if (
|
||||
! is_amp_endpoint()
|
||||
&&
|
||||
! ( is_singular( 'web-story' ) && ! is_embed() && ! post_password_required() )
|
||||
) {
|
||||
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' );
|
||||
add_filter( 'pre_get_rocket_option_async_css', '__return_false' );
|
||||
add_filter( 'pre_get_rocket_option_delay_js', '__return_false' );
|
||||
add_filter( 'pre_get_rocket_option_preload_links', '__return_false' );
|
||||
add_filter( 'pre_get_rocket_option_minify_js', '__return_false' );
|
||||
add_filter( 'pre_get_rocket_option_minify_google_fonts', '__return_false' );
|
||||
add_filter( 'pre_get_rocket_option_lazyload_css_bg_img', '__return_false' );
|
||||
add_filter( 'pre_get_cloudflare_protocol_rewrite', '__return_false' );
|
||||
add_filter( 'do_rocket_protocol_rewrite', '__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' ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the switching script from AMP to delay JS excluded files
|
||||
*
|
||||
* @since 3.11.1
|
||||
*
|
||||
* @param array $excluded List of excluded files.
|
||||
* @return array List of excluded files.
|
||||
*/
|
||||
public function exclude_script_from_delay_js( $excluded ) {
|
||||
$excluded[] = 'amp-mobile-version-switcher';
|
||||
return $excluded;
|
||||
}
|
||||
}
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
|
||||
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class Autoptimize implements Subscriber_Interface {
|
||||
/**
|
||||
* WP Rocket Options instance
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* 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 listens to.
|
||||
*
|
||||
* @since 3.10.4
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'admin_notices' => [
|
||||
[ 'warn_when_js_aggregation_and_delay_js_active' ],
|
||||
[ 'warn_when_aggregate_inline_css_and_cpcss_active' ],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an admin warning notice when Delay JS and JS Aggregation are both activated.
|
||||
*
|
||||
* @since 3.10.4
|
||||
*/
|
||||
public function warn_when_js_aggregation_and_delay_js_active() {
|
||||
if ( ! $this->can_notify() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
|
||||
|
||||
if ( ! (
|
||||
'on' === get_option( 'autoptimize_js' )
|
||||
&&
|
||||
'on' === get_option( 'autoptimize_js_aggregate' )
|
||||
) || false === (bool) $this->options->get( 'delay_js' )
|
||||
) {
|
||||
if ( ! is_array( $boxes ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->remove_warning_dismissal( $boxes, __FUNCTION__ );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
/* Translators: %1$s is an opening <strong> tag; %2$s is a closing </strong> tag */
|
||||
__(
|
||||
'%1$sWP Rocket: %2$sWe have detected that Autoptimize\'s JavaScript Aggregation feature is enabled. WP Rocket\'s Delay JavaScript Execution will not be applied to the file it creates. We suggest disabling %1$sJavaScript Aggregation%2$s to take full advantage of Delay JavaScript Execution.',
|
||||
'rocket'
|
||||
),
|
||||
'<strong>',
|
||||
'</strong>'
|
||||
);
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'info',
|
||||
'message' => $message,
|
||||
'dismissible' => '',
|
||||
'dismiss_button' => __FUNCTION__,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an admin warning notice when CPCSS and Aggregate Inline CSS are both activated.
|
||||
*
|
||||
* @since 3.10.4
|
||||
*/
|
||||
public function warn_when_aggregate_inline_css_and_cpcss_active() {
|
||||
if ( ! $this->can_notify() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
|
||||
|
||||
if ( ! (
|
||||
'on' === get_option( 'autoptimize_css' )
|
||||
&&
|
||||
'on' === get_option( 'autoptimize_css_aggregate' )
|
||||
&&
|
||||
'on' === get_option( 'autoptimize_css_include_inline' )
|
||||
)
|
||||
||
|
||||
false === (bool) $this->options->get( 'async_css' )
|
||||
) {
|
||||
if ( ! is_array( $boxes ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->remove_warning_dismissal( $boxes, __FUNCTION__ );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
/* Translators: %1$s is an opening <strong> tag; %2$s is a closing </strong> tag */
|
||||
__(
|
||||
'%1$sWP Rocket: %2$sWe have detected that Autoptimize\'s Aggregate Inline CSS feature is enabled. WP Rocket\'s Load CSS Asynchronously will not work correctly. We suggest disabling %1$sAggregate Inline CSS%2$s to take full advantage of Load CSS Asynchronously Execution.',
|
||||
'rocket'
|
||||
),
|
||||
'<strong>',
|
||||
'</strong>'
|
||||
);
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'info',
|
||||
'message' => $message,
|
||||
'dismissible' => '',
|
||||
'dismiss_button' => __FUNCTION__,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this compatibility can use notifications.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function can_notify() {
|
||||
if ( 'settings_page_wprocket' !== get_current_screen()->id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return rocket_get_constant( 'AUTOPTIMIZE_PLUGIN_VERSION', false )
|
||||
&&
|
||||
current_user_can( 'rocket_manage_options' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a warning box dismissal.
|
||||
*
|
||||
* @param array $boxes The rocket_boxes user meta.
|
||||
* @param string $name Slug for the box to be removed.
|
||||
*/
|
||||
private function remove_warning_dismissal( $boxes, $name ) {
|
||||
if ( ! in_array( $name, $boxes, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
unset( $boxes[ array_search( $name, $boxes, true ) ] );
|
||||
update_user_meta( get_current_user_id(), 'rocket_boxes', $boxes );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class Ezoic implements Subscriber_Interface {
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'rocket_plugins_to_deactivate' => 'add_conflict',
|
||||
'rocket_plugins_to_deactivate_explanations' => 'add_conflict_explanations',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Ezoic plugin to plugins to deactivate array
|
||||
*
|
||||
* @param array $plugins List of recommended plugins to deactivate.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_conflict( $plugins ) {
|
||||
$plugins['ezoic'] = 'ezoic-integration/ezoic-integration.php';
|
||||
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds explanation for deactivation recommendation
|
||||
*
|
||||
* @param array $plugins_explanations List of recommended plugins to deactivate explanations.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_conflict_explanations( $plugins_explanations ) {
|
||||
$plugins_explanations['ezoic'] = sprintf(
|
||||
// translators: %1$s = opening <a> tag, %2$s = closing </a> tag.
|
||||
__( 'This plugin blocks WP Rocket\'s caching and optimizations. Deactivate it and use %1$sEzoic\'s nameserver integration%2$s instead.', 'rocket' ),
|
||||
'<a href="https://support.ezoic.com/kb/article/how-can-i-integrate-my-site-with-ezoic" target="_blank" rel="noopener noreferrer">',
|
||||
'</a>'
|
||||
);
|
||||
|
||||
return $plugins_explanations;
|
||||
}
|
||||
}
|
||||
+295
@@ -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;
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class Perfmatters implements Subscriber_Interface {
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber listens to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! defined( 'PERFMATTERS_VERSION' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'rocket_disable_rucss_setting' => 'disable_rucss_setting',
|
||||
'pre_get_rocket_option_remove_unused_css' => 'maybe_disable_rucss',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable RUCSS setting.
|
||||
*
|
||||
* @param array $status RUCSS option status.
|
||||
* @return array
|
||||
*/
|
||||
public function disable_rucss_setting( array $status ): array {
|
||||
if ( ! $this->is_perfmatters_rucss_active() ) {
|
||||
return $status;
|
||||
}
|
||||
|
||||
return [
|
||||
'disable' => true,
|
||||
'text' => __( 'Remove Unused CSS is currently activated in Perfmatters. If you want to use WP Rocket\'s Remove Unused CSS feature, disable this option in Perfmatters.', 'rocket' ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable RUCSS option.
|
||||
*
|
||||
* @return bool|null
|
||||
*/
|
||||
public function maybe_disable_rucss() {
|
||||
return $this->is_perfmatters_rucss_active() ? false : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if perfmatters rucss is active.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_perfmatters_rucss_active(): bool {
|
||||
$perfmatters_options = get_option( 'perfmatters_options' );
|
||||
|
||||
return ! empty( $perfmatters_options['assets']['remove_unused_css'] );
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class RapidLoad implements Subscriber_Interface {
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber listens to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! defined( 'UUCSS_VERSION' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'rocket_disable_rucss_setting' => 'disable_rucss_setting',
|
||||
'pre_get_rocket_option_remove_unused_css' => 'maybe_disable_rucss',
|
||||
'deactivated_plugin' => [ 'rocket_clean_cache_on_deactivation', 12 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable RUCSS setting.
|
||||
*
|
||||
* @param array $status RUCSS option status.
|
||||
* @return array
|
||||
*/
|
||||
public function disable_rucss_setting( array $status ): array {
|
||||
if ( ! $this->is_rapidload_active() ) {
|
||||
return $status;
|
||||
}
|
||||
|
||||
return [
|
||||
'disable' => true,
|
||||
'text' => __( 'Automated unused CSS removal is currently activated in RapidLoad Power-Up for Autoptimize. If you want to use WP Rocket\'s Remove Unused CSS feature, disable the RapidLoad Power-Up for Autoptimize plugin.', 'rocket' ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable RUCSS option.
|
||||
*
|
||||
* @return bool|null
|
||||
*/
|
||||
public function maybe_disable_rucss() {
|
||||
return $this->is_rapidload_active() ? false : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean WP Rocket Cache when Rapidload is deactivated.
|
||||
*
|
||||
* @param string $plugin Plugin file.
|
||||
* @return void
|
||||
*/
|
||||
public function rocket_clean_cache_on_deactivation( string $plugin ): void {
|
||||
if ( ! $this->is_rapidload_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'unusedcss/unusedcss.php' !== $plugin ) {
|
||||
return;
|
||||
}
|
||||
|
||||
rocket_dismiss_box( 'rocket_warning_plugin_modification' );
|
||||
rocket_clean_domain();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if RapidLoad Power-Up for Autoptimize is active.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function is_rapidload_active(): bool {
|
||||
$autoptimize_uucss_settings = get_option( 'autoptimize_uucss_settings' );
|
||||
|
||||
return ( isset( $autoptimize_uucss_settings['uucss_api_key_verified'] ) && 1 === $autoptimize_uucss_settings['uucss_api_key_verified'] && $autoptimize_uucss_settings['valid_domain'] );
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class RocketLazyLoad implements Subscriber_Interface {
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events(): array {
|
||||
if ( ! defined( 'ROCKET_LL_VERSION' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'rocket_delay_js_exclusions' => 'exclude_rocket_lazyload_script',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes rocket lazyload script from delay js.
|
||||
*
|
||||
* @param array $excluded List of excluded files.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_rocket_lazyload_script( $excluded ): array {
|
||||
$excluded[] = 'rocket-lazy-load/assets/js/\d\d\.\d/lazyload.min.js';
|
||||
return $excluded;
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class WPMeteor implements Subscriber_Interface {
|
||||
/**
|
||||
* Returns an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events(): array {
|
||||
return [
|
||||
'rocket_delay_js_settings_field' => 'maybe_disable_delay_js_field',
|
||||
'activate_wp-meteor/wp-meteor.php' => 'disable_delay_js',
|
||||
'wp_rocket_upgrade' => [ 'maybe_disable_delay_js', 10, 2 ],
|
||||
'pre_update_option_wp_rocket_settings' => 'disable_delay_js_on_option_update',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the delay JS field when WP Meteor is active
|
||||
*
|
||||
* @since 3.9.2
|
||||
*
|
||||
* @param array $field Delay JS field data array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function maybe_disable_delay_js_field( $field ): array {
|
||||
if ( ! is_plugin_active( 'wp-meteor/wp-meteor.php' ) ) {
|
||||
return $field;
|
||||
}
|
||||
|
||||
$field['container_class'][] = 'wpr-isDisabled';
|
||||
$field['value'] = 0;
|
||||
$field['input_attr']['disabled'] = 1;
|
||||
$field['helper'] = sprintf(
|
||||
// translators: %1$s = plugin name.
|
||||
__( 'Delay JS is currently activated in %1$s. If you want to use WP Rocket’s delay JS, disable %1$s', 'rocket' ),
|
||||
'WP Meteor'
|
||||
);
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable delay JS option when WP Meteor is activated
|
||||
*
|
||||
* @since 3.9.2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disable_delay_js() {
|
||||
$options = get_option( 'wp_rocket_settings', [] );
|
||||
|
||||
$options['delay_js'] = 0;
|
||||
|
||||
update_option( 'wp_rocket_settings', $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable delay JS when updating to 3.9.2 and above and WP Meteor is active
|
||||
*
|
||||
* @since 3.9.2
|
||||
*
|
||||
* @param string $new_version Plugin new version.
|
||||
* @param string $old_version Plugin old version.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_disable_delay_js( $new_version, $old_version ) {
|
||||
if ( version_compare( $old_version, '3.9.2', '>' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_plugin_active( 'wp-meteor/wp-meteor.php' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->disable_delay_js();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable delay JS on WP Rocket settings update if WP Meteor is active
|
||||
*
|
||||
* @since 3.9.2
|
||||
*
|
||||
* @param mixed $value The new, unserialized option value.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function disable_delay_js_on_option_update( $value ) {
|
||||
if ( ! is_plugin_active( 'wp-meteor/wp-meteor.php' ) ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ( ! isset( $value['delay_js'] ) ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ( 0 === (int) $value['delay_js'] ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$value['delay_js'] = 0;
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?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( 'PDF_Embedder_Basic' )
|
||||
||
|
||||
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' ) ),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class PWA implements Subscriber_Interface {
|
||||
/**
|
||||
* Subscribed events.
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'rocket_cache_reject_uri' => 'exclude_service_worker',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes the PWA service worker URL
|
||||
*
|
||||
* @param array $excluded Array of excluded URLs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_service_worker( $excluded ): array {
|
||||
if ( ! function_exists( 'wp_get_service_worker_url' ) ) {
|
||||
return $excluded;
|
||||
}
|
||||
|
||||
$excluded[] = '/wp.serviceworker/?';
|
||||
|
||||
return $excluded;
|
||||
}
|
||||
}
|
||||
+35
@@ -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();
|
||||
}
|
||||
}
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\PageBuilder;
|
||||
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
use WP_Rocket\Engine\Optimization\DelayJS\HTML;
|
||||
|
||||
/**
|
||||
* Compatibility file for Elementor plugin
|
||||
*/
|
||||
class Elementor implements Subscriber_Interface {
|
||||
/**
|
||||
* WP Rocket options.
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* WP_Filesystem_Direct instance.
|
||||
*
|
||||
* @var \WP_Filesystem_Direct
|
||||
*/
|
||||
private $filesystem;
|
||||
|
||||
/**
|
||||
* Delay JS HTML class.
|
||||
*
|
||||
* @var HTML
|
||||
*/
|
||||
private $delayjs_html;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Options_Data $options WP Rocket options.
|
||||
* @param \WP_Filesystem_Direct $filesystem The Filesystem object.
|
||||
* @param HTML $delayjs_html DelayJS HTML class.
|
||||
*/
|
||||
public function __construct( Options_Data $options, $filesystem, HTML $delayjs_html ) {
|
||||
$this->options = $options;
|
||||
$this->filesystem = $filesystem;
|
||||
$this->delayjs_html = $delayjs_html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! defined( 'ELEMENTOR_VERSION' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'wp_rocket_loaded' => 'remove_widget_callback',
|
||||
'rocket_exclude_css' => 'exclude_post_css',
|
||||
'elementor/core/files/clear_cache' => 'clear_cache',
|
||||
'elementor/maintenance_mode/mode_changed' => 'clear_cache',
|
||||
'update_option__elementor_global_css' => 'clear_cache',
|
||||
'delete_option__elementor_global_css' => 'clear_cache',
|
||||
'rocket_buffer' => [ 'add_fix_animation_script', 28 ],
|
||||
'rocket_exclude_js' => 'exclude_js',
|
||||
'rocket_skip_post_row_actions' => 'remove_rocket_option',
|
||||
'rocket_metabox_options_post_types' => 'remove_rocket_option',
|
||||
'rocket_skip_admin_bar_cache_purge_option' => [ 'skip_admin_bar_option', 1, 2 ],
|
||||
'rocket_submitbox_options_post_types' => 'remove_rocket_option',
|
||||
'rocket_skip_admin_bar_clear_used_css_option' => [ 'skip_admin_bar_option', 1, 2 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the callback to clear the cache on widget update
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function remove_widget_callback() {
|
||||
remove_filter( 'widget_update_callback', 'rocket_widget_update_callback' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear WP Rocket caches when Elementor changes the CSS
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function elementor_use_external_file() {
|
||||
return 'internal' !== get_option( 'elementor_css_print_method' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Fix Elementor Pro animations script.
|
||||
*
|
||||
* @since 3.9.2
|
||||
*
|
||||
* @param string $html HTML content.
|
||||
*
|
||||
* @return string HTML with Fix Elementor Pro animations script.
|
||||
*/
|
||||
public function add_fix_animation_script( $html ) {
|
||||
if ( ! $this->delayjs_html->is_allowed() ) {
|
||||
return $html;
|
||||
}
|
||||
$pattern = '/<\/body*>/i';
|
||||
|
||||
$fix_elementor_animation_script = $this->filesystem->get_contents( rocket_get_constant( 'WP_ROCKET_PATH' ) . 'assets/js/elementor-animation.js' );
|
||||
|
||||
if ( false !== $fix_elementor_animation_script ) {
|
||||
$html = preg_replace( $pattern, "<script>{$fix_elementor_animation_script}</script>$0", $html, 1 );
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes Elementor CSS from minify/combine
|
||||
*
|
||||
* @since 3.10.9
|
||||
*
|
||||
* @param array $excluded Array of excluded patterns.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_post_css( $excluded ): array {
|
||||
if ( ! $this->elementor_use_external_file() ) {
|
||||
return $excluded;
|
||||
}
|
||||
|
||||
$upload = wp_get_upload_dir();
|
||||
$basepath = wp_parse_url( $upload['baseurl'], PHP_URL_PATH );
|
||||
|
||||
if ( empty( $basepath ) ) {
|
||||
return $excluded;
|
||||
}
|
||||
|
||||
$excluded[] = $basepath . '/elementor/css/(.*).css';
|
||||
|
||||
return $excluded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes JS files from minify/combine JS
|
||||
*
|
||||
* @since 3.10.9
|
||||
*
|
||||
* @param array $excluded_files Array of excluded patterns.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_js( $excluded_files ): array {
|
||||
if ( ! $this->options->get( 'minify_concatenate_js', false ) ) {
|
||||
return $excluded_files;
|
||||
}
|
||||
|
||||
$excluded_files[] = '/wp-includes/js/dist/hooks(.min)?.js';
|
||||
|
||||
return $excluded_files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove rocket metabox option from post.
|
||||
*
|
||||
* @param array $cpts Custom post type.
|
||||
* @return array
|
||||
*/
|
||||
public function remove_rocket_option( array $cpts ): array {
|
||||
if ( isset( $cpts['elementor_library'] ) ) {
|
||||
unset( $cpts['elementor_library'] );
|
||||
}
|
||||
|
||||
return $cpts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove cache or purge option from elementor template post.
|
||||
*
|
||||
* @param boolean $should_skip Should skip rocket option to admin bar.
|
||||
* @param mixed $post Post object.
|
||||
* @return boolean
|
||||
*/
|
||||
public function skip_admin_bar_option( bool $should_skip, $post ): bool {
|
||||
if ( null === $post ) {
|
||||
return $should_skip;
|
||||
}
|
||||
|
||||
if ( 'elementor_library' === $post->post_type ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $should_skip;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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 RevolutionSlider.
|
||||
*
|
||||
* @since 3.9.2
|
||||
*/
|
||||
class RevolutionSlider implements Subscriber_Interface {
|
||||
|
||||
/**
|
||||
* Subscribed events for RevolutionSlider.
|
||||
*
|
||||
* @since 3.9.2
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! defined( 'RS_REVISION' ) || version_compare( RS_REVISION, '6.5.5', '<' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'rocket_exclude_defer_js' => 'exclude_defer_js',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes jquery and jquery migrate JS files from defer JS
|
||||
*
|
||||
* @since 3.9.2
|
||||
*
|
||||
* @param array $exclude_defer_js Array of JS file paths to be excluded.
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_defer_js( $exclude_defer_js ) {
|
||||
$exclude_defer_js[] = '/jquery-?[0-9.]*(.min|.slim|.slim.min)?.js';
|
||||
$exclude_defer_js[] = '/jquery-migrate(.min)?.js';
|
||||
|
||||
return $exclude_defer_js;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\SEO;
|
||||
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class AllInOneSEOPack implements Subscriber_Interface {
|
||||
|
||||
/**
|
||||
* Option instance.
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
protected $option;
|
||||
|
||||
/**
|
||||
* Instantiate class.
|
||||
*
|
||||
* @param Options_Data $option Option instance.
|
||||
*/
|
||||
public function __construct( Options_Data $option ) {
|
||||
$this->option = $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribed events.
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
$aioseo_v3 = defined( 'AIOSEOP_VERSION' );
|
||||
$aioseo_v4 = defined( 'AIOSEO_VERSION' ) && function_exists( 'aioseo' );
|
||||
|
||||
if ( ! $aioseo_v3 && ! $aioseo_v4 ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'rocket_sitemap_preload_list' => [ 'add_all_in_one_seo_sitemap', 15 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add All in One SEO Sitemap to the preload list
|
||||
*
|
||||
* @param Array $sitemaps Array of sitemaps to preload.
|
||||
* @return Array Updated array of sitemaps to preload
|
||||
*/
|
||||
public function add_all_in_one_seo_sitemap( $sitemaps ) {
|
||||
|
||||
$aioseo_v3 = defined( 'AIOSEOP_VERSION' );
|
||||
$aioseo_v4 = defined( 'AIOSEO_VERSION' ) && function_exists( 'aioseo' );
|
||||
|
||||
$sitemap_enabled = false;
|
||||
if ( $aioseo_v3 && ! $aioseo_v4 ) {
|
||||
$aioseop_options = get_option( 'aioseop_options' );
|
||||
$sitemap_enabled = ( isset( $aioseop_options['modules']['aiosp_feature_manager_options']['aiosp_feature_manager_enable_sitemap'] ) && 'on' === $aioseop_options['modules']['aiosp_feature_manager_options']['aiosp_feature_manager_enable_sitemap'] ) || ( ! isset( $aioseop_options['modules']['aiosp_feature_manager_options'] ) && isset( $aioseop_options['modules']['aiosp_sitemap_options'] ) );
|
||||
}
|
||||
|
||||
if (
|
||||
( ! $aioseo_v4 && ! $sitemap_enabled ) ||
|
||||
( $aioseo_v4 && ! aioseo()->options->sitemap->general->enable )
|
||||
) {
|
||||
return $sitemaps;
|
||||
}
|
||||
|
||||
if ( $aioseo_v3 ) {
|
||||
$sitemaps[] = trailingslashit( home_url() ) . apply_filters( 'aiosp_sitemap_filename', 'sitemap' ) . '.xml'; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
|
||||
} elseif ( $aioseo_v4 ) {
|
||||
$sitemaps[] = trailingslashit( home_url() ) . apply_filters( 'aioseo_sitemap_filename', 'sitemap' ) . '.xml'; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
|
||||
}
|
||||
|
||||
return $sitemaps;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\SEO;
|
||||
|
||||
use RankMath\Helper;
|
||||
use RankMath\Sitemap\Router;
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class RankMathSEO implements Subscriber_Interface {
|
||||
|
||||
|
||||
/**
|
||||
* Options instance.
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
protected $option;
|
||||
|
||||
/**
|
||||
* Instantiate class.
|
||||
*
|
||||
* @param Options_Data $option Options instance.
|
||||
*/
|
||||
public function __construct( Options_Data $option ) {
|
||||
$this->option = $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribed events.
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! defined( 'RANK_MATH_FILE' ) || ! Helper::is_module_active( 'sitemap' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'rocket_sitemap_preload_list' => [ 'rocket_sitemap', 15 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add SEO sitemap URL to the sitemaps to preload
|
||||
*
|
||||
* @param array $sitemaps Sitemaps to preload.
|
||||
* @return array Updated Sitemaps to preload
|
||||
*/
|
||||
public function rocket_sitemap( $sitemaps ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
|
||||
|
||||
$sitemaps[] = Router::get_base_url( 'sitemap_index.xml' );
|
||||
|
||||
return $sitemaps;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\SEO;
|
||||
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class SEOPress implements Subscriber_Interface {
|
||||
|
||||
/**
|
||||
* Option instance.
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
protected $option;
|
||||
|
||||
/**
|
||||
* Instantiate class.
|
||||
*
|
||||
* @param Options_Data $option Option instance.
|
||||
*/
|
||||
public function __construct( Options_Data $option ) {
|
||||
$this->option = $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribed events.
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! function_exists( 'seopress_get_toggle_option' ) || 1 !== (int) seopress_get_toggle_option( 'xml-sitemap' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ( ! method_exists( seopress_get_service( 'SitemapOption' ), 'isEnabled' ) || 1 !== (int) seopress_get_service( 'SitemapOption' )->isEnabled() ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'rocket_sitemap_preload_list' => [ 'add_seopress_sitemap', 15 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add SEOPress sitemap URL to the sitemaps to preload
|
||||
*
|
||||
* @param array $sitemaps Sitemaps to preload.
|
||||
* @return array Updated Sitemaps to preload
|
||||
*/
|
||||
public function add_seopress_sitemap( $sitemaps ) {
|
||||
$sitemaps[] = get_home_url() . '/sitemaps.xml';
|
||||
|
||||
return $sitemaps;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\SEO;
|
||||
|
||||
use The_SEO_Framework\Bridges\Sitemap;
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class TheSEOFramework implements Subscriber_Interface {
|
||||
|
||||
/**
|
||||
* Option instance.
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
protected $option;
|
||||
|
||||
/**
|
||||
* Instantiate the class.
|
||||
*
|
||||
* @param Options_Data $option Option instance.
|
||||
*/
|
||||
public function __construct( Options_Data $option ) {
|
||||
$this->option = $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribed events.
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! function_exists( 'the_seo_framework' ) ) {
|
||||
return [];
|
||||
}
|
||||
$tsf = the_seo_framework();
|
||||
|
||||
// Either TSF < 3.1, or the plugin's silenced (soft-disabled) via a drop-in.
|
||||
if ( empty( $tsf->loaded ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Performs option & other checks.
|
||||
* 2. Checks for conflicting sitemap plugins that might prevent loading.
|
||||
*
|
||||
* These methods cache their output at runtime.
|
||||
*
|
||||
* @link https://github.com/wp-media/wp-rocket/issues/899
|
||||
*/
|
||||
if ( ! $tsf->can_run_sitemap() ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'rocket_sitemap_preload_list' => [ 'add_tsf_sitemap_to_preload', 15 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds TSF sitemap URLs to preload.
|
||||
*
|
||||
* @param array $sitemaps Sitemaps to preload.
|
||||
* @return array Updated Sitemaps to preload
|
||||
*/
|
||||
public function add_tsf_sitemap_to_preload( $sitemaps ) {
|
||||
|
||||
// The autoloader in TSF doesn't check for file_exists(). So, use version compare instead to prevent fatal errors.
|
||||
if ( version_compare( rocket_get_constant( 'THE_SEO_FRAMEWORK_VERSION', false ), '4.0', '>=' ) ) {
|
||||
// TSF 4.0+. Expect the class to exist indefinitely.
|
||||
$sitemap_bridge = Sitemap::get_instance();
|
||||
|
||||
foreach ( $sitemap_bridge->get_sitemap_endpoint_list() as $id => $data ) {
|
||||
// When the sitemap is good enough for a robots display, we determine it as valid for precaching.
|
||||
// Non-robots display types are among the stylesheet endpoint, or the Yoast SEO-compatible endpoint.
|
||||
// In other words, this enables support for ALL current and future public sitemap endpoints.
|
||||
if ( ! empty( $data['robots'] ) ) {
|
||||
$sitemaps[] = $sitemap_bridge->get_expected_sitemap_endpoint_url( $id );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Deprecated. TSF <4.0.
|
||||
$sitemaps[] = the_seo_framework()->get_sitemap_xml_url();
|
||||
}
|
||||
|
||||
return $sitemaps;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins\SEO;
|
||||
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class Yoast implements Subscriber_Interface {
|
||||
/**
|
||||
* Options Data instance
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Options_Data $options Options_Data instance.
|
||||
*/
|
||||
public function __construct( Options_Data $options ) {
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of events this subscriber listens to
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'rocket_sitemap_preload_list' => [ 'add_sitemap', 15 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Yoast SEO sitemap URL to the sitemaps to preload
|
||||
*
|
||||
* @since 2.8
|
||||
*
|
||||
* @param array $sitemaps An array of sitemaps to preload.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_sitemap( $sitemaps ): array {
|
||||
if ( ! is_array( $sitemaps ) ) {
|
||||
$sitemaps = (array) $sitemaps;
|
||||
}
|
||||
|
||||
if ( ! $this->is_sitemap_enabled() ) {
|
||||
return $sitemaps;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WPSEO_Sitemaps_Router' ) ) {
|
||||
return $sitemaps;
|
||||
}
|
||||
|
||||
$sitemaps[] = \WPSEO_Sitemaps_Router::get_base_url( 'sitemap_index.xml' );
|
||||
|
||||
return $sitemaps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if sitemap is enabled in Yoast SEO
|
||||
*
|
||||
* @since 3.11.1
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_sitemap_enabled(): bool {
|
||||
static $enabled = null;
|
||||
|
||||
if ( ! is_null( $enabled ) ) {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
if ( ! rocket_has_constant( 'WPSEO_VERSION' ) ) {
|
||||
$enabled = false;
|
||||
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
$yoast_seo_xml = get_option( 'wpseo_xml', [] ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
|
||||
|
||||
if ( version_compare( rocket_get_constant( 'WPSEO_VERSION', '' ), '7.0' ) >= 0 ) {
|
||||
$yoast_seo = get_option( 'wpseo', [] ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
|
||||
$yoast_seo_xml['enablexmlsitemap'] = isset( $yoast_seo['enable_xml_sitemap'] ) && $yoast_seo['enable_xml_sitemap']; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
|
||||
}
|
||||
|
||||
$enabled = (bool) $yoast_seo_xml['enablexmlsitemap'];
|
||||
|
||||
return $enabled;
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Security;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
use wordfence;
|
||||
use wfConfig;
|
||||
|
||||
/**
|
||||
* Compatibility file for WordFence plugin
|
||||
*
|
||||
* @since 3.10
|
||||
*/
|
||||
class WordFenceCompatibility implements Subscriber_Interface {
|
||||
|
||||
/**
|
||||
* Whitelisted_IPS.
|
||||
*/
|
||||
const WHITELISTED_IPS = [ '141.94.254.72' ];
|
||||
|
||||
/**
|
||||
* Old Whitelisted IP.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $old_rucss_ip = '135.125.83.227';
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.10
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! defined( 'WORDFENCE_VERSION' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'init' => [ 'whitelist_wordfence_firewall_ips', 11 ],
|
||||
'rocket_deactivation' => 'pop_ip_from_whitelist',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes old ip from whitelist.
|
||||
*
|
||||
* @param string $old_rucss_ip Old RUCSS IP.
|
||||
* @return void
|
||||
*/
|
||||
public function pop_old_ip( string $old_rucss_ip ) {
|
||||
|
||||
$whitelist = $this->can_pop_ip( $old_rucss_ip );
|
||||
|
||||
if ( ! $whitelist ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update whitelist.
|
||||
wfConfig::set( 'whitelisted', implode( ',', $whitelist ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove ip from whitelist.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function pop_ip_from_whitelist() {
|
||||
|
||||
$whitelist = $this->can_pop_ip( self::WHITELISTED_IPS[0] );
|
||||
|
||||
if ( ! $whitelist ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update whitelist.
|
||||
wfConfig::set( 'whitelisted', implode( ',', $whitelist ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if ip can be removed.
|
||||
*
|
||||
* @param string $ip IP.
|
||||
* @return array
|
||||
*/
|
||||
private function can_pop_ip( string $ip ) {
|
||||
// Get all whitelists.
|
||||
$whitelists = wfConfig::get( 'whitelisted', '' );
|
||||
|
||||
// Convert to array.
|
||||
$whitelist_array = explode( ',', $whitelists );
|
||||
|
||||
// Get ip index.
|
||||
$ip = array_search( $ip, $whitelist_array, true );
|
||||
|
||||
if ( false === $ip ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove ip from whitelist.
|
||||
unset( $whitelist_array[ $ip ] );
|
||||
|
||||
return $whitelist_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whitelist wp-rocket ips in wordfence firewall
|
||||
*
|
||||
* @since 3.10
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function whitelist_wordfence_firewall_ips() {
|
||||
// Pop old rucss ip.
|
||||
$this->pop_old_ip( $this->old_rucss_ip );
|
||||
|
||||
/**
|
||||
* Rocket wordfence whitelisted ips filter which adds IPs to wordfence whitelist.
|
||||
*
|
||||
* @since 3.10
|
||||
*
|
||||
* @param array list of IPs should be whitelisted
|
||||
*/
|
||||
$ips = apply_filters( 'rocket_wordfence_whitelisted_ips', self::WHITELISTED_IPS );
|
||||
|
||||
if ( empty( $ips ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $ips as $ip ) {
|
||||
wordfence::whitelistIP( $ip );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
<?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 ],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'update_option_wp-smush-settings' => [ 'maybe_deactivate_rocket_lazyload', 11 ],
|
||||
'update_site_option_wp-smush-settings' => [ 'maybe_deactivate_rocket_lazyload', 11 ],
|
||||
'update_option_wp-smush-lazy_load' => [ 'maybe_deactivate_rocket_lazyload', 11 ],
|
||||
'update_site_option_wp-smush-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;
|
||||
}
|
||||
|
||||
$formats = $smush_settings->get_setting( 'wp-smush-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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with the Events Calendar.
|
||||
*/
|
||||
class TheEventsCalendar implements Subscriber_Interface {
|
||||
|
||||
|
||||
/**
|
||||
* Subscribed events for The Events Calendar.
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! rocket_get_constant( 'TRIBE_EVENTS_FILE', false ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'rocket_preload_exclude_urls' => 'exclude_from_preload_calendars',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude calendars from the preload.
|
||||
*
|
||||
* @param array $excluded excluded urls.
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_from_preload_calendars( $excluded ) {
|
||||
|
||||
if ( ! function_exists( 'tribe_get_option' ) ) {
|
||||
return $excluded;
|
||||
}
|
||||
|
||||
$uri = tribe_get_option( 'eventsSlug', 'event' );
|
||||
|
||||
$excluded[] = "/$uri/20(.*)";
|
||||
|
||||
return $excluded;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class ThirstyAffiliates implements Subscriber_Interface {
|
||||
/**
|
||||
* Returns an array of events this subscriber listens to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'rocket_preload_links_exclusions' => [ 'exclude_link_prefix', PHP_INT_MAX, 2 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes the link prefix from preload links
|
||||
*
|
||||
* @since 3.10.8
|
||||
*
|
||||
* @param string[] $excluded Array of excluded patterns.
|
||||
* @param string[] $default Array of default excluded patterns.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_link_prefix( $excluded, $default ): array {
|
||||
if ( ! is_array( $excluded ) ) {
|
||||
$excluded = (array) $excluded;
|
||||
}
|
||||
|
||||
if ( ! is_plugin_active( 'thirstyaffiliates/thirstyaffiliates.php' ) ) {
|
||||
return $excluded;
|
||||
}
|
||||
|
||||
$excluded = array_diff( $excluded, $default );
|
||||
$link_prefix = get_option( 'ta_link_prefix', 'recommends' );
|
||||
|
||||
if ( 'custom' === $link_prefix ) {
|
||||
$link_prefix = get_option( 'ta_link_prefix_custom', 'recommends' );
|
||||
}
|
||||
|
||||
$excluded[] = '/' . $link_prefix . '/';
|
||||
|
||||
return $excluded;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with Unlimited Elements.
|
||||
*/
|
||||
class UnlimitedElements implements Subscriber_Interface {
|
||||
|
||||
|
||||
/**
|
||||
* Subscriber for Unlimited Elements.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! defined( 'UNLIMITED_ELEMENTS_INC' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [ 'rocket_rucss_inline_content_exclusions' => 'exclude_inline_from_rucss' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude inline style from RUCSS.
|
||||
*
|
||||
* @param array $excluded excluded css.
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_inline_from_rucss( $excluded ) {
|
||||
$excluded[] = '#uc_';
|
||||
|
||||
return $excluded;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
use WP_Rocket\ThirdParty\ReturnTypesTrait;
|
||||
|
||||
class WPGeotargeting implements Subscriber_Interface {
|
||||
|
||||
use ReturnTypesTrait;
|
||||
|
||||
/**
|
||||
* Returns an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
$events = [
|
||||
'geotWP/activated' => [ 'activate_geotargetingwp', 11 ],
|
||||
'geotWP/deactivated' => [ 'deactivate_geotargetingwp', 11 ],
|
||||
];
|
||||
|
||||
if ( ! class_exists( '\GeotWP\GeotargetingWP' ) ) {
|
||||
return $events;
|
||||
}
|
||||
|
||||
$events['rocket_htaccess_mod_rewrite'] = [ 'return_false', 72 ];
|
||||
$events['rocket_cache_dynamic_cookies'] = 'add_geot_cookies';
|
||||
$events['rocket_cache_mandatory_cookies'] = 'add_geot_cookies';
|
||||
$events['geot/pass_basic_rules'] = [ 'maybe_disable_rules', 10, 3 ];
|
||||
|
||||
if ( ! get_option( 'geotWP-deactivated' ) ) {
|
||||
return $events;
|
||||
}
|
||||
|
||||
// Update the WP Rocket rules on the .htaccess file.
|
||||
$events['admin_init'] = [
|
||||
[ 'flush_rocket_htaccess' ],
|
||||
[ 'rocket_generate_config_file' ],
|
||||
];
|
||||
|
||||
delete_option( 'geotWP-deactivated' );
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable rules on nowprocket parameter.
|
||||
*
|
||||
* @param bool $bool Is Disabled.
|
||||
* @param array $opts Options.
|
||||
* @param string $current_url Current URL.
|
||||
* @return bool
|
||||
*/
|
||||
public function maybe_disable_rules( $bool, $opts, $current_url ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.boolFound
|
||||
$query = wp_parse_url( $current_url, PHP_URL_QUERY );
|
||||
return ! str_contains( $query ? $query : '', 'nowprocket' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add cookies when we activate any goetargetingWP plugin.
|
||||
*
|
||||
* @author Damian Logghe
|
||||
*/
|
||||
public function activate_geotargetingwp() {
|
||||
add_filter( 'rocket_htaccess_mod_rewrite', [ $this, 'return_false' ], 72 );
|
||||
add_filter( 'rocket_cache_dynamic_cookies', [ $this, 'add_geot_cookies' ] );
|
||||
add_filter( 'rocket_cache_mandatory_cookies', [ $this, 'add_geot_cookies' ] );
|
||||
|
||||
// Update the WP Rocket rules on the .htaccess file.
|
||||
flush_rocket_htaccess();
|
||||
|
||||
// Regenerate the config file.
|
||||
rocket_generate_config_file();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove cookies when we deactivate the plugin.
|
||||
*
|
||||
* @author Damian Logghe
|
||||
*/
|
||||
public function deactivate_geotargetingwp() {
|
||||
// add into db a record saying we deactivated one of the family plugins.
|
||||
update_option( 'geotWP-deactivated', true );
|
||||
remove_filter( 'rocket_htaccess_mod_rewrite', [ $this, 'return_false' ], 72 );
|
||||
remove_filter( 'rocket_cache_dynamic_cookies', [ $this, 'add_geot_cookies' ] );
|
||||
remove_filter( 'rocket_cache_mandatory_cookies', [ $this, 'add_geot_cookies' ] );
|
||||
|
||||
// Update the WP Rocket rules on the .htaccess file.
|
||||
flush_rocket_htaccess();
|
||||
|
||||
// Regenerate the config file.
|
||||
rocket_generate_config_file();
|
||||
}
|
||||
|
||||
/**
|
||||
* Let users modify cache level by default set to country.
|
||||
*
|
||||
* @author Damian Logghe
|
||||
*
|
||||
* @param array $cookies An array of cookies.
|
||||
* @return array Updated array of cookies
|
||||
*/
|
||||
public function add_geot_cookies( $cookies ) {
|
||||
/**
|
||||
* Geotargeting cookies.
|
||||
*
|
||||
* @param array $types Types from cookies (country, state, city).
|
||||
* @return array
|
||||
*/
|
||||
$enabled_cookies = apply_filters( 'rocket_geotargetingwp_enabled_cookies', [ 'country' ] );
|
||||
foreach ( $enabled_cookies as $enabled_cookie ) {
|
||||
if ( ! in_array( 'geot_rocket_' . $enabled_cookie, $cookies, true ) ) {
|
||||
$cookies[] = 'geot_rocket_' . $enabled_cookie;
|
||||
}
|
||||
}
|
||||
return $cookies;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user