add wp-rocket
This commit is contained in:
483
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Ecommerce/WooCommerceSubscriber.php
vendored
Normal file
483
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Ecommerce/WooCommerceSubscriber.php
vendored
Normal file
@@ -0,0 +1,483 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Ecommerce;
|
||||
|
||||
use WP_Rocket\Event_Management\Event_Manager;
|
||||
use WP_Rocket\Event_Management\Event_Manager_Aware_Subscriber_Interface;
|
||||
use WooCommerce;
|
||||
use WC_API;
|
||||
|
||||
/**
|
||||
* WooCommerce compatibility
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*/
|
||||
class WooCommerceSubscriber implements Event_Manager_Aware_Subscriber_Interface {
|
||||
use \WP_Rocket\Traits\Config_Updater;
|
||||
|
||||
/**
|
||||
* The WordPress Event Manager
|
||||
*
|
||||
* @var Event_Manager;
|
||||
*/
|
||||
protected $event_manager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param Event_Manager $event_manager The WordPress Event Manager.
|
||||
*/
|
||||
public function set_event_manager( Event_Manager $event_manager ) {
|
||||
$this->event_manager = $event_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
$events = [
|
||||
'activate_woocommerce/woocommerce.php' => [ 'activate_woocommerce', 11 ],
|
||||
'deactivate_woocommerce/woocommerce.php' => [ 'deactivate_woocommerce', 11 ],
|
||||
];
|
||||
|
||||
if ( class_exists( 'WooCommerce' ) ) {
|
||||
$events['update_option_woocommerce_cart_page_id'] = [ 'after_update_single_option', 10, 2 ];
|
||||
$events['update_option_woocommerce_checkout_page_id'] = [ 'after_update_single_option', 10, 2 ];
|
||||
$events['update_option_woocommerce_myaccount_page_id'] = [ 'after_update_single_option', 10, 2 ];
|
||||
$events['update_option_woocommerce_default_customer_address'] = [ 'after_update_single_option', 10, 2 ];
|
||||
|
||||
$events['shutdown'] = 'maybe_update_config';
|
||||
$events['woocommerce_save_product_variation'] = 'clean_cache_after_woocommerce_save_product_variation';
|
||||
$events['transition_post_status'] = [ 'maybe_exclude_page', 10, 3 ];
|
||||
$events['rocket_cache_reject_uri'] = [
|
||||
[ 'exclude_pages' ],
|
||||
];
|
||||
$events['rocket_cache_query_strings'] = 'cache_geolocation_query_string';
|
||||
$events['rocket_cpcss_excluded_taxonomies'] = 'exclude_product_attributes_cpcss';
|
||||
$events['nonce_user_logged_out'] = [ 'maybe_revert_uid_for_nonce_actions', PHP_INT_MAX, 2 ];
|
||||
|
||||
/**
|
||||
* Filters activation of WooCommerce empty cart caching
|
||||
*
|
||||
* @since 3.1
|
||||
*
|
||||
* @param bool true to activate, false to deactivate.
|
||||
*/
|
||||
if ( apply_filters( 'rocket_cache_wc_empty_cart', true ) ) {
|
||||
$events['after_setup_theme'] = [ 'serve_cache_empty_cart', 11 ];
|
||||
$events['template_redirect'] = [ 'cache_empty_cart', -1 ];
|
||||
$events['switch_theme'] = 'delete_cache_empty_cart';
|
||||
}
|
||||
}
|
||||
|
||||
if ( class_exists( 'WC_API' ) ) {
|
||||
$events['rocket_cache_reject_uri'][] = [ 'exclude_wc_rest_api' ];
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add query string to exclusion when activating the plugin
|
||||
*
|
||||
* @since 2.8.6
|
||||
* @author Rémy Perona
|
||||
*/
|
||||
public function activate_woocommerce() {
|
||||
$this->event_manager->add_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_pages' ] );
|
||||
$this->event_manager->add_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_wc_rest_api' ] );
|
||||
$this->event_manager->add_callback( 'rocket_cache_query_strings', [ $this, 'cache_geolocation_query_string' ] );
|
||||
|
||||
// Update .htaccess file rules.
|
||||
flush_rocket_htaccess();
|
||||
|
||||
// Regenerate the config file.
|
||||
rocket_generate_config_file();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove query string from exclusion when deactivating the plugin
|
||||
*
|
||||
* @since 2.8.6
|
||||
* @author Rémy Perona
|
||||
*/
|
||||
public function deactivate_woocommerce() {
|
||||
$this->event_manager->remove_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_pages' ] );
|
||||
$this->event_manager->remove_callback( 'rocket_cache_reject_uri', [ $this, 'exclude_wc_rest_api' ] );
|
||||
$this->event_manager->remove_callback( 'rocket_cache_query_strings', [ $this, 'cache_geolocation_query_string' ] );
|
||||
|
||||
// Update .htaccess file rules.
|
||||
flush_rocket_htaccess();
|
||||
|
||||
// Regenerate the config file.
|
||||
rocket_generate_config_file();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean product cache on variation update
|
||||
*
|
||||
* @since 2.9
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param int $variation_id ID of the variation.
|
||||
* @return bool
|
||||
*/
|
||||
public function clean_cache_after_woocommerce_save_product_variation( $variation_id ) {
|
||||
$product_id = wp_get_post_parent_id( $variation_id );
|
||||
|
||||
if ( ! $product_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rocket_clean_post( $product_id );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe regenerate the htaccess & config file if a WooCommerce page is published
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $new_status New post status.
|
||||
* @param string $old_status Old post status.
|
||||
* @param WP_Post $post Post object.
|
||||
* @return bool
|
||||
*/
|
||||
public function maybe_exclude_page( $new_status, $old_status, $post ) {
|
||||
if ( 'publish' === $old_status || 'publish' !== $new_status ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'wc_get_page_id' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( wc_get_page_id( 'checkout' ) !== $post->ID && wc_get_page_id( 'cart' ) !== $post->ID && wc_get_page_id( 'myaccount' ) !== $post->ID ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update .htaccess file rules.
|
||||
flush_rocket_htaccess();
|
||||
|
||||
// Regenerate the config file.
|
||||
rocket_generate_config_file();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude WooCommerce cart, checkout and account pages from caching
|
||||
*
|
||||
* @since 2.11 Moved to 3rd party
|
||||
* @since 2.4
|
||||
*
|
||||
* @param array $urls An array of excluded pages.
|
||||
* @return array Updated array of excluded pages
|
||||
*/
|
||||
public function exclude_pages( $urls ) {
|
||||
if ( ! function_exists( 'wc_get_page_id' ) ) {
|
||||
return $urls;
|
||||
}
|
||||
$checkout_urls = $this->exclude_page( wc_get_page_id( 'checkout' ), 'page', '(.*)' );
|
||||
$cart_urls = $this->exclude_page( wc_get_page_id( 'cart' ) );
|
||||
$account_urls = $this->exclude_page( wc_get_page_id( 'myaccount' ), 'page', '(.*)' );
|
||||
|
||||
return array_merge( $urls, $checkout_urls, $cart_urls, $account_urls );
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes WooCommerce checkout page from cache
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param int $page_id ID of page to exclude.
|
||||
* @param string $post_type Post type of the page.
|
||||
* @param string $pattern Pattern to use for the exclusion.
|
||||
* @return array
|
||||
*/
|
||||
private function exclude_page( $page_id, $post_type = 'page', $pattern = '' ) {
|
||||
$urls = [];
|
||||
|
||||
if ( $page_id <= 0 || (int) get_option( 'page_on_front' ) === $page_id ) {
|
||||
return $urls;
|
||||
}
|
||||
|
||||
if ( 'publish' !== get_post_status( $page_id ) ) {
|
||||
return $urls;
|
||||
}
|
||||
|
||||
$urls = get_rocket_i18n_translated_post_urls( $page_id, $post_type, $pattern );
|
||||
|
||||
return $urls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically cache v query string when WC geolocation with cache compatibility option is active
|
||||
*
|
||||
* @since 2.8.6
|
||||
* @author Rémy Perona
|
||||
*
|
||||
* @param array $query_strings list of query strings to cache.
|
||||
* @return array Updated list of query strings to cache
|
||||
*/
|
||||
public function cache_geolocation_query_string( $query_strings ) {
|
||||
if ( 'geolocation_ajax' !== get_option( 'woocommerce_default_customer_address' ) ) {
|
||||
return $query_strings;
|
||||
}
|
||||
|
||||
$query_strings[] = 'v';
|
||||
|
||||
return $query_strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns WooCommerce API endpoint
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_wc_api_endpoint() {
|
||||
return home_url( '/wc-api/v(.*)' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude WooCommerce REST API URL from cache
|
||||
*
|
||||
* @since 2.6.5
|
||||
*
|
||||
* @param array $urls URLs to exclude from cache.
|
||||
* @return array Updated list of URLs to exclude from cache
|
||||
*/
|
||||
public function exclude_wc_rest_api( $urls ) {
|
||||
/**
|
||||
* By default, don't cache the WooCommerce REST API.
|
||||
*
|
||||
* @since 2.6.5
|
||||
*
|
||||
* @param bool false will force to cache the WooCommerce REST API
|
||||
*/
|
||||
if ( apply_filters( 'rocket_cache_reject_wc_rest_api', true ) ) {
|
||||
$urls[] = rocket_clean_exclude_file( $this->get_wc_api_endpoint() );
|
||||
}
|
||||
|
||||
return $urls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves the empty cart cache
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function serve_cache_empty_cart() {
|
||||
if ( ! $this->is_get_refreshed_fragments() || rocket_bypass() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cart = $this->get_cache_empty_cart();
|
||||
|
||||
if ( false !== $cart ) {
|
||||
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
|
||||
echo $cart; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the empty cart cache
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cache_empty_cart() {
|
||||
if ( ! $this->is_get_refreshed_fragments() || rocket_bypass() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cart = $this->get_cache_empty_cart();
|
||||
|
||||
if ( false !== $cart ) {
|
||||
return;
|
||||
}
|
||||
|
||||
ob_start( [ $this, 'save_cache_empty_cart' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the empty cart cache
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_cache_empty_cart() {
|
||||
$lang = rocket_get_current_language();
|
||||
|
||||
if ( $lang ) {
|
||||
return get_transient( 'rocket_get_refreshed_fragments_cache_' . $lang );
|
||||
}
|
||||
|
||||
return get_transient( 'rocket_get_refreshed_fragments_cache' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the empty cart JSON in a transient
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $content Current buffer content.
|
||||
* @return string
|
||||
*/
|
||||
private function save_cache_empty_cart( $content ) {
|
||||
$lang = rocket_get_current_language();
|
||||
|
||||
if ( $lang ) {
|
||||
set_transient( 'rocket_get_refreshed_fragments_cache_' . $lang, $content, 7 * DAY_IN_SECONDS );
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
set_transient( 'rocket_get_refreshed_fragments_cache', $content, 7 * DAY_IN_SECONDS );
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the request is for get_refreshed_fragments and the cart is empty
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function is_get_refreshed_fragments() {
|
||||
if ( ! isset( $_GET['wc-ajax'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( 'get_refreshed_fragments' !== $_GET['wc-ajax'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! empty( $_COOKIE['woocommerce_cart_hash'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! empty( $_COOKIE['woocommerce_items_in_cart'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the empty cart cache
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_cache_empty_cart() {
|
||||
$langs = get_rocket_i18n_code();
|
||||
|
||||
if ( $langs ) {
|
||||
foreach ( $langs as $lang ) {
|
||||
delete_transient( 'rocket_get_refreshed_fragments_cache_' . $lang );
|
||||
}
|
||||
}
|
||||
|
||||
delete_transient( 'rocket_get_refreshed_fragments_cache' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes WC product attributes taxonomies from CPCSS generation
|
||||
*
|
||||
* @since 3.3.5
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param array $excluded_taxonomies Taxonomies excluded from CPCSS generation.
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_product_attributes_cpcss( $excluded_taxonomies ) {
|
||||
if ( ! function_exists( 'wc_get_attribute_taxonomy_names' ) ) {
|
||||
return $excluded_taxonomies;
|
||||
}
|
||||
|
||||
return array_merge( $excluded_taxonomies, wc_get_attribute_taxonomy_names() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set $user_id to 0 for certain nonce actions.
|
||||
*
|
||||
* WooCommerce core changes how nonces are used for non-logged customers.
|
||||
* When a user is logged out, but has items in their cart, WC core sets the $uid as a random string customer id.
|
||||
* This is going to mess out nonce validation with WP Rocket and third party plugins which do not bypass WC nonce changes.
|
||||
* WP Rocket caches the page so the nonce $uid will be always different than the session customer $uid.
|
||||
* This function will check the nonce against a UID of 0 because this is how WP Rocket generated the cached page.
|
||||
*
|
||||
* @since 3.5.1
|
||||
* @author Soponar Cristina
|
||||
*
|
||||
* @param string|int $user_id ID of the nonce-owning user.
|
||||
* @param string|int $action The nonce action.
|
||||
*
|
||||
* @return int $uid ID of the nonce-owning user.
|
||||
*/
|
||||
public function maybe_revert_uid_for_nonce_actions( $user_id, $action ) {
|
||||
// User ID is invalid.
|
||||
if ( empty( $user_id ) || 0 === $user_id ) {
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
// The nonce action is not in the list.
|
||||
if ( ! $action || ! in_array( $action, $this->get_nonce_actions(), true ) ) {
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* List with nonce actions which needs to revert the $uid.
|
||||
*
|
||||
* @since 3.5.1
|
||||
* @author Soponar Cristina
|
||||
*
|
||||
* @return array $nonce_actions List with all nonce actions.
|
||||
*/
|
||||
private function get_nonce_actions() {
|
||||
return [
|
||||
'wcmd-subscribe-secret', // WooCommerce MailChimp Discount.
|
||||
'td-block', // "Load more" AJAX functionality of the Newspaper theme.
|
||||
'codevz_selective_refresh', // xtra theme.
|
||||
'xtra_quick_view', // xtra theme quick view.
|
||||
'ajax_search_nonce', // xtra theme AJAX search.
|
||||
'xtra_wishlist_content', // xtra theme wishlist feature.
|
||||
'ajax-login-security', // OneSocial theme pop-up login.
|
||||
'dokan_pageview', // Dokan related pageview.
|
||||
'dokan_report_abuse', // Dokan report abuse popup.
|
||||
'uabb_subscribe_form_submit', // Ultimate Addons for Beaver Builder - MailChimp signup form.
|
||||
'konte-add-to-cart', // Add to cart feature of the Konte theme.
|
||||
'wpuf_form_add', // WP User Frontend Pro.
|
||||
'everest_forms_ajax_form_submission', // Everest forms AJAX submission.
|
||||
'everest-forms_process_submit', // Everest forms submission.
|
||||
'ajax-login-nonce', // Rehub theme login modal.
|
||||
'filter-nonce', // Rehub theme filter.
|
||||
'log-out', // WordPress's log-out action (wp_nonce_ays() function).
|
||||
'ybws123456', // Custom Bookly form.
|
||||
];
|
||||
}
|
||||
}
|
159
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Optimization/AMP.php
vendored
Normal file
159
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Optimization/AMP.php
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
|
||||
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Engine\CDN\Subscriber;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with AMP
|
||||
*
|
||||
* @since 3.5.2
|
||||
*/
|
||||
class AMP implements Subscriber_Interface {
|
||||
const QUERY = 'amp';
|
||||
const AMP_OPTIONS = 'amp-options';
|
||||
|
||||
/**
|
||||
* WP Rocket CDN Subscriber.
|
||||
*
|
||||
* @var Subscriber_Interface
|
||||
*/
|
||||
private $cdn_subscriber;
|
||||
|
||||
/**
|
||||
* WP Rocket Options instance
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Options_Data $options WP Rocket Options instance.
|
||||
* @param Subscriber_Interface $cdn_subscriber WP Rocket CDN Subscriber.
|
||||
*/
|
||||
public function __construct( Options_Data $options, Subscriber_Interface $cdn_subscriber ) {
|
||||
$this->options = $options;
|
||||
$this->cdn_subscriber = $cdn_subscriber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribed events for AMP.
|
||||
*
|
||||
* @since 3.5.2
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
$events = [
|
||||
'activate_amp/amp.php' => 'generate_config_file',
|
||||
'deactivate_amp/amp.php' => 'generate_config_file',
|
||||
'wp' => 'disable_options_on_amp',
|
||||
];
|
||||
if ( function_exists( 'is_amp_endpoint' ) ) {
|
||||
$events['rocket_cache_query_strings'] = 'is_amp_compatible_callback';
|
||||
$events['update_option_amp-options'] = 'generate_config_file';
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate config file on plugin activation / deactivation.
|
||||
*
|
||||
* @since 3.5.2
|
||||
*/
|
||||
public function generate_config_file() {
|
||||
rocket_generate_config_file();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add compatibility with AMP query string by adding it as a cached query string.
|
||||
*
|
||||
* @since 3.5.2
|
||||
*
|
||||
* @param array $value WP Rocket cache_query_strings value.
|
||||
* @return array
|
||||
*/
|
||||
public function is_amp_compatible_callback( $value ) {
|
||||
$options = get_option( self::AMP_OPTIONS, [] );
|
||||
$query_strings = array_diff( $value, [ static::QUERY ] );
|
||||
|
||||
if ( empty( $options['theme_support'] ) ) {
|
||||
return $query_strings;
|
||||
}
|
||||
|
||||
if ( in_array( $options['theme_support'], [ 'transitional', 'reader' ], true ) ) {
|
||||
$query_strings[] = static::QUERY;
|
||||
}
|
||||
|
||||
return $query_strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes Minification, DNS Prefetch, LazyLoad, Defer JS when on an AMP document.
|
||||
*
|
||||
* This covers AMP documents as output by the official AMP plugin for WordPress
|
||||
* (https://amp-wp.org/) as well as Web Stories for WordPress (https://wp.stories.google/),
|
||||
* which both support the `is_amp_endpoint` function checks.
|
||||
*
|
||||
* However, in the case of Web Stories, `is_amp_endpoint` is only defined on
|
||||
* the `wp` action, not earlier. Hence doing the `function_exists` check at this stage
|
||||
* instead of in the `get_subscribed_events()` method.
|
||||
*
|
||||
* @since 3.5.2
|
||||
*/
|
||||
public function disable_options_on_amp() {
|
||||
if ( ! function_exists( 'is_amp_endpoint' ) || ! is_amp_endpoint() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $wp_filter;
|
||||
|
||||
remove_filter( 'wp_resource_hints', 'rocket_dns_prefetch', 10, 2 );
|
||||
add_filter( 'do_rocket_lazyload', '__return_false' );
|
||||
add_filter( 'do_rocket_lazyload_iframes', '__return_false' );
|
||||
unset( $wp_filter['rocket_buffer'] );
|
||||
|
||||
$options = get_option( self::AMP_OPTIONS, [] );
|
||||
|
||||
if ( ! empty( $options['theme_support'] )
|
||||
&&
|
||||
in_array( $options['theme_support'], [ 'transitional', 'reader' ], true ) ) {
|
||||
add_filter( 'rocket_cdn_reject_files', [ $this, 'reject_files' ], PHP_INT_MAX );
|
||||
add_filter( 'rocket_buffer', [ $this->cdn_subscriber, 'rewrite' ] );
|
||||
add_filter( 'rocket_buffer', [ $this->cdn_subscriber, 'rewrite_srcset' ] );
|
||||
}
|
||||
|
||||
if (
|
||||
(bool) $this->options->get( 'do_cloudflare', 0 )
|
||||
&&
|
||||
(
|
||||
(bool) $this->options->get( 'cloudflare_protocol_rewrite', 0 )
|
||||
||
|
||||
// this filter is documented in inc/front/protocol.php.
|
||||
(bool) apply_filters( 'do_rocket_protocol_rewrite', false ) // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
|
||||
)
|
||||
) {
|
||||
remove_filter( 'wp_calculate_image_srcset', 'rocket_protocol_rewrite_srcset', PHP_INT_MAX );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all CSS and JS files to the list of excluded CDN files.
|
||||
*
|
||||
* @since 3.5.5
|
||||
*
|
||||
* @param array $files List of excluded files.
|
||||
* @return array List of excluded files.
|
||||
*/
|
||||
public function reject_files( $files ) {
|
||||
return array_merge(
|
||||
$files,
|
||||
[
|
||||
'(.*).css',
|
||||
'(.*).js',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
295
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Optimization/Hummingbird.php
vendored
Normal file
295
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Optimization/Hummingbird.php
vendored
Normal file
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins\Optimization;
|
||||
|
||||
use WP_Hummingbird_Settings;
|
||||
use WP_Hummingbird_Utils;
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Hummingbird compatibility class
|
||||
*/
|
||||
class Hummingbird implements Subscriber_Interface {
|
||||
/**
|
||||
* WP Rocket Options instance
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Array containing the errors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $errors = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Options_Data $options WP Rocket Options instance.
|
||||
*/
|
||||
public function __construct( Options_Data $options ) {
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'admin_notices' => 'warning_notice',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a notice if conflicting options are active
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function warning_notice() {
|
||||
if ( ! current_user_can( 'rocket_manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_plugin_active( 'hummingbird-performance/wp-hummingbird.php' ) && ! is_plugin_active( 'wp-hummingbird/wp-hummingbird.php' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->check_cache();
|
||||
$this->check_assets();
|
||||
$this->check_browser_caching();
|
||||
$this->check_gzip();
|
||||
$this->check_emoji();
|
||||
|
||||
if ( 0 === count( $this->errors ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Translators: %s = Plugin name.
|
||||
$message = '<p>' . sprintf( _nx( 'Please deactivate the following %s option which conflicts with WP Rocket features:', 'Please deactivate the following %s options which conflict with WP Rocket features:', count( $this->errors ), 'Hummingbird notice', 'rocket' ), 'Hummingbird' ) . '</p>';
|
||||
|
||||
$message .= '<ul>';
|
||||
|
||||
foreach ( $this->errors as $error ) {
|
||||
$message .= '<li>' . $error . '</li>';
|
||||
}
|
||||
|
||||
$message .= '</ul>';
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'error',
|
||||
'message' => $message,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Hummingbird Utils class exists
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function is_utils_available() {
|
||||
if ( ! class_exists( 'WP_Hummingbird_Utils' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( 'WP_Hummingbird_Utils', 'get_module' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Hummingbird settings class exists
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function is_settings_available() {
|
||||
if ( ! class_exists( 'WP_Hummingbird_Settings' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( 'WP_Hummingbird_Settings', 'get_setting' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Hummingbird and WP Rocket disable emoji options are active at the same time
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function check_emoji() {
|
||||
if ( ! $this->is_settings_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->options->get( 'emoji' ) && WP_Hummingbird_Settings::get_setting( 'emoji', 'advanced' ) ) {
|
||||
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
|
||||
$this->errors[] = sprintf( _x( '%1$s %2$sdisable emoji%3$s conflicts with WP Rockets %2$sdisable emoji%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Hummingbird Gzip rules are in the htaccess file.
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function check_gzip() {
|
||||
if ( ! $this->is_utils_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$gzip = WP_Hummingbird_Utils::get_module( 'gzip' );
|
||||
|
||||
if ( ! $gzip instanceof \WP_Hummingbird_Module_GZip ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( $gzip, 'is_htaccess_written' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( $gzip, 'get_server_type' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $gzip::is_htaccess_written( 'gzip' ) && 'apache' === $gzip::get_server_type() ) {
|
||||
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
|
||||
$this->errors[] = sprintf( _x( '%1$s %2$sGZIP compression%3$s conflicts with WP Rocket %2$sGZIP compression%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Hummingbird browser caching rules are in the htaccess file
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function check_browser_caching() {
|
||||
if ( ! $this->is_utils_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$caching = WP_Hummingbird_Utils::get_module( 'caching' );
|
||||
|
||||
if ( ! $caching instanceof \WP_Hummingbird_Module_Caching ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( $caching, 'is_htaccess_written' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( $caching, 'get_server_type' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $caching::is_htaccess_written( 'caching' ) && 'apache' === $caching::get_server_type() ) {
|
||||
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
|
||||
$this->errors[] = sprintf( _x( '%1$s %2$sbrowser caching%3$s conflicts with WP Rocket %2$sbrowser caching%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Hummingbird Cache is active
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function check_cache() {
|
||||
if ( ! $this->is_utils_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cache = WP_Hummingbird_Utils::get_module( 'page_cache' );
|
||||
|
||||
if ( ! $cache instanceof \WP_Hummingbird_Module_Page_Cache ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( $cache, 'is_active' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $cache->is_active() ) {
|
||||
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
|
||||
$this->errors[] = sprintf( _x( '%1$s %2$spage caching%3$s conflicts with WP Rocket %2$spage caching%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Hummingbird Assets optimization is active
|
||||
*
|
||||
* Checks against WP Rocket Minify CSS, Minify JS and Defer JS options.
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function check_assets() {
|
||||
if ( ! $this->is_utils_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$minify = WP_Hummingbird_Utils::get_module( 'minify' );
|
||||
|
||||
if ( ! $minify instanceof \WP_Hummingbird_Module_Minify ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! method_exists( $minify, 'is_active' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $minify->is_active() && ( $this->options->get( 'minify_css' ) || $this->options->get( 'minify_js' ) || $this->options->get( 'defer_all_js' ) ) ) {
|
||||
// Translators: %1$s = Plugin name, %2$s = <em>, %3$s = </em>.
|
||||
$this->errors[] = sprintf( _x( '%1$s %2$sasset optimization%3$s conflicts with WP Rocket %2$sfile optimization%3$s', 'Hummingbird notice', 'rocket' ), 'Hummingbird', '<em>', '</em>' );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
98
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/PDFEmbedder.php
vendored
Normal file
98
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/PDFEmbedder.php
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with PDF Embedder Free / Premium / Secure plugin.
|
||||
*
|
||||
* @since 3.6.2
|
||||
*/
|
||||
class PDFEmbedder implements Subscriber_Interface {
|
||||
/**
|
||||
* Subscribed events.
|
||||
*
|
||||
* @since 3.6.2
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
// All 3 plugins use the same core class.
|
||||
if ( ! class_exists( 'core_pdf_embedder' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'rocket_exclude_js' => 'exclude_pdfembedder_scripts',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds PDFEmbedder scripts to defer JS exclusion
|
||||
*
|
||||
* @since 3.6.2
|
||||
*
|
||||
* @param array $excluded_js Array of scripts to exclude.
|
||||
* @return array
|
||||
*/
|
||||
public function exclude_pdfembedder_scripts( $excluded_js ) {
|
||||
if ( class_exists( 'pdfemb_basic_pdf_embedder' ) ) {
|
||||
// Exclude Free version.
|
||||
return array_merge(
|
||||
$excluded_js,
|
||||
$this->pdfembedder_free_scripts()
|
||||
);
|
||||
}
|
||||
|
||||
if ( class_exists( 'pdfemb_premium_mobile_pdf_embedder' ) ) {
|
||||
// Excludes PDFEmbedder-premium.
|
||||
return array_merge(
|
||||
$excluded_js,
|
||||
$this->pdfembedder_premium_scripts()
|
||||
);
|
||||
}
|
||||
|
||||
if ( class_exists( 'pdfemb_premium_secure_pdf_embedder' ) ) {
|
||||
// Excludes PDFEmbedder-premium-secure.
|
||||
return array_merge(
|
||||
$excluded_js,
|
||||
$this->pdfembedder_secure_scripts()
|
||||
);
|
||||
}
|
||||
|
||||
return $excluded_js;
|
||||
}
|
||||
|
||||
/**
|
||||
* PDFEmbedder Free JS scripts.
|
||||
*
|
||||
* @return array JS files to be excluded.
|
||||
*/
|
||||
private function pdfembedder_free_scripts() {
|
||||
return [
|
||||
rocket_clean_exclude_file( plugins_url( '/pdf-embedder/js/(.*).js' ) ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* PDFEmbedder Premium JS scripts.
|
||||
*
|
||||
* @return array JS files to be excluded.
|
||||
*/
|
||||
private function pdfembedder_premium_scripts() {
|
||||
return [
|
||||
rocket_clean_exclude_file( plugins_url( '/PDFEmbedder-premium/js/pdfjs/(.*).js' ) ),
|
||||
rocket_clean_exclude_file( plugins_url( '/PDFEmbedder-premium/js/(.*).js' ) ),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* PDFEmbedder Secure JS scripts.
|
||||
*
|
||||
* @return array JS files to be excluded.
|
||||
*/
|
||||
private function pdfembedder_secure_scripts() {
|
||||
return [
|
||||
rocket_clean_exclude_file( plugins_url( '/PDFEmbedder-premium-secure/js/pdfjs/(.*).js' ) ),
|
||||
rocket_clean_exclude_file( plugins_url( '/PDFEmbedder-premium-secure/js/(.*).js' ) ),
|
||||
];
|
||||
}
|
||||
}
|
35
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/PageBuilder/BeaverBuilder.php
vendored
Normal file
35
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/PageBuilder/BeaverBuilder.php
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins\PageBuilder;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class BeaverBuilder implements Subscriber_Interface {
|
||||
/**
|
||||
* Events this subscriber listens to
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! rocket_get_constant( 'FL_BUILDER_VERSION' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'fl_builder_before_save_layout' => 'purge_cache',
|
||||
'fl_builder_cache_cleared' => 'purge_cache',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge the cache when the beaver builder layout is updated to update the minified files content & URL
|
||||
*
|
||||
* Previously rocket_beaver_builder_clean_domain()
|
||||
*
|
||||
* @since 3.6
|
||||
* @author Remy Perona
|
||||
*/
|
||||
public function purge_cache() {
|
||||
rocket_clean_minify();
|
||||
rocket_clean_domain();
|
||||
}
|
||||
}
|
119
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/PageBuilder/Elementor.php
vendored
Normal file
119
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/PageBuilder/Elementor.php
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins\PageBuilder;
|
||||
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Compatibility file for Elementor plugin
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*/
|
||||
class Elementor implements Subscriber_Interface {
|
||||
/**
|
||||
* WP Rocket options.
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param Options_Data $options WP Rocket options.
|
||||
*/
|
||||
public function __construct( Options_Data $options ) {
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! defined( 'ELEMENTOR_VERSION' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'wp_rocket_loaded' => 'remove_widget_callback',
|
||||
'added_post_meta' => [ 'maybe_clear_cache', 10, 3 ],
|
||||
'deleted_post_meta' => [ 'maybe_clear_cache', 10, 3 ],
|
||||
'elementor/core/files/clear_cache' => 'clear_cache',
|
||||
'update_option__elementor_global_css' => 'clear_cache',
|
||||
'delete_option__elementor_global_css' => 'clear_cache',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the callback to clear the cache on widget update
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function remove_widget_callback() {
|
||||
remove_filter( 'widget_update_callback', 'rocket_widget_update_callback' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears WP Rocket caches if the combine CSS option is active.
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param int $meta_id The meta ID.
|
||||
* @param int $object_id Object ID.
|
||||
* @param string $meta_key Meta key.
|
||||
* @return void
|
||||
*/
|
||||
public function maybe_clear_cache( $meta_id, $object_id, $meta_key ) {
|
||||
if ( '_elementor_css' !== $meta_key ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $this->options->get( 'minify_concatenate_css' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->clear_cache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear WP Rocket caches when Elementor changes the CSS
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear_cache() {
|
||||
if ( ! $this->elementor_use_external_file() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
rocket_clean_domain();
|
||||
rocket_clean_minify( 'css' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether elementor is set use external CSS file or not.
|
||||
*
|
||||
* @since 3.3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function elementor_use_external_file() {
|
||||
return 'internal' !== get_option( 'elementor_css_print_method' );
|
||||
}
|
||||
}
|
117
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/SimpleCustomCss.php
vendored
Normal file
117
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/SimpleCustomCss.php
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use WP_Rocket\Engine\Optimization\CSSTrait;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with Simple Custom CSS plugin.
|
||||
*
|
||||
* @since 3.6
|
||||
* @author Soponar Cristina
|
||||
*/
|
||||
class SimpleCustomCss implements Subscriber_Interface {
|
||||
use CSSTrait;
|
||||
|
||||
const FILENAME = 'sccss.css';
|
||||
|
||||
/**
|
||||
* Base cache busting folder path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cache_busting_path;
|
||||
|
||||
/**
|
||||
* SCCSS cache busting file path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $filepath;
|
||||
|
||||
/**
|
||||
* SCCSS cache busting file URL
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $file_url;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $cache_busting_path Base cache busting folder path.
|
||||
* @param string $cache_busting_url Base cache busting URL.
|
||||
*/
|
||||
public function __construct( $cache_busting_path, $cache_busting_url ) {
|
||||
$blog_id = get_current_blog_id();
|
||||
$this->cache_busting_path = $cache_busting_path . $blog_id . '/';
|
||||
$this->filepath = $this->cache_busting_path . self::FILENAME;
|
||||
$this->file_url = $cache_busting_url . $blog_id . '/' . self::FILENAME;
|
||||
}
|
||||
/**
|
||||
* Subscribed events for AMP.
|
||||
*
|
||||
* @since 3.5.3
|
||||
* @author Soponar Cristina
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! defined( 'SCCSS_FILE' ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'wp_enqueue_scripts' => [ 'cache_sccss', 98 ],
|
||||
'update_option_sccss_settings' => 'update_cache_file',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches SCCSS code & remove the default enqueued URL
|
||||
*
|
||||
* @since 2.9
|
||||
* @author Remy Perona
|
||||
*/
|
||||
public function cache_sccss() {
|
||||
if ( ! rocket_direct_filesystem()->exists( $this->filepath ) ) {
|
||||
$this->create_cache_file();
|
||||
}
|
||||
|
||||
// This filter is documented in inc/Engine/Optimization/CSS/AbstractCSSOptimization.php.
|
||||
wp_enqueue_style( 'scss', apply_filters( 'rocket_css_url', $this->file_url ), '', rocket_direct_filesystem()->mtime( $this->filepath ) );
|
||||
remove_action( 'wp_enqueue_scripts', 'sccss_register_style', 99 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes & recreates cache for SCCSS code
|
||||
*
|
||||
* @since 3.6
|
||||
* @author Remy Perona
|
||||
*/
|
||||
public function update_cache_file() {
|
||||
rocket_clean_domain();
|
||||
$this->create_cache_file();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates cache file for SCCSS code if it does not exist.
|
||||
*
|
||||
* @since 2.9
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool Returns bool if the files exists or could not be created.
|
||||
*/
|
||||
private function create_cache_file() {
|
||||
$options = get_option( 'sccss_settings' );
|
||||
$raw_content = isset( $options['sccss-content'] ) ? $options['sccss-content'] : '';
|
||||
$content = wp_kses( $raw_content, [ '\'', '\"' ] );
|
||||
$content = str_replace( '>', '>', $content );
|
||||
$content = $this->apply_font_display_swap( $content );
|
||||
|
||||
if ( ! rocket_direct_filesystem()->is_dir( $this->cache_busting_path ) ) {
|
||||
rocket_mkdir_p( $this->cache_busting_path );
|
||||
}
|
||||
|
||||
return rocket_put_content( $this->filepath, $content );
|
||||
}
|
||||
}
|
195
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Smush.php
vendored
Normal file
195
wp-content/plugins/wp-rocket/inc/ThirdParty/Plugins/Smush.php
vendored
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\ThirdParty\Plugins;
|
||||
|
||||
use Smush\Core\Settings;
|
||||
use WP_Rocket\Admin\Options;
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Subscriber for compatibility with Smush
|
||||
*
|
||||
* @since 3.4.2
|
||||
* @author Soponar Cristina
|
||||
*/
|
||||
class Smush implements Subscriber_Interface {
|
||||
/**
|
||||
* WP Options API instance
|
||||
*
|
||||
* @var Options
|
||||
*/
|
||||
private $options_api;
|
||||
|
||||
/**
|
||||
* Options instance
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Subscribed events for Smush.
|
||||
*
|
||||
* @since 3.4.2
|
||||
* @author Soponar Cristina
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
if ( ! rocket_has_constant( 'WP_SMUSH_VERSION' ) ) {
|
||||
return [
|
||||
'activate_wp-smushit/wp-smush.php' => [ 'maybe_deactivate_rocket_lazyload', 10 ],
|
||||
];
|
||||
}
|
||||
|
||||
$prefix = rocket_get_constant( 'WP_SMUSH_PREFIX', 'wp-smush-' );
|
||||
|
||||
return [
|
||||
"update_option_{$prefix}settings" => [ 'maybe_deactivate_rocket_lazyload', 11 ],
|
||||
"update_site_option_{$prefix}settings" => [ 'maybe_deactivate_rocket_lazyload', 11 ],
|
||||
"update_option_{$prefix}lazy_load" => [ 'maybe_deactivate_rocket_lazyload', 11 ],
|
||||
"update_site_option_{$prefix}lazy_load" => [ 'maybe_deactivate_rocket_lazyload', 11 ],
|
||||
'rocket_maybe_disable_lazyload_helper' => 'is_smush_lazyload_active',
|
||||
'rocket_maybe_disable_iframes_lazyload_helper' => 'is_smush_iframes_lazyload_active',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 3.5.5
|
||||
*
|
||||
* @param Options $options_api WP Options API instance.
|
||||
* @param Options_Data $options WP Rocket Options instance.
|
||||
*/
|
||||
public function __construct( Options $options_api, Options_Data $options ) {
|
||||
$this->options_api = $options_api;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable WP Rocket lazyload when activating WP Smush and values are already in the database.
|
||||
*
|
||||
* @since 3.4.2
|
||||
* @author Soponar Cristina
|
||||
*/
|
||||
public function maybe_deactivate_rocket_lazyload() {
|
||||
$enabled = $this->is_smush_lazyload_enabled();
|
||||
$updated = false;
|
||||
|
||||
if ( $enabled['images'] && $this->options->get( 'lazyload' ) ) {
|
||||
$this->options->set( 'lazyload', 0 );
|
||||
$updated = true;
|
||||
}
|
||||
|
||||
if ( $enabled['iframes'] && $this->options->get( 'lazyload_iframes' ) ) {
|
||||
$this->options->set( 'lazyload_iframes', 0 );
|
||||
$updated = true;
|
||||
}
|
||||
|
||||
if ( ! $updated ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->options_api->set( 'settings', $this->options->get_options() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "Smush" to the provided array if WP Smush lazyload is enabled for images.
|
||||
*
|
||||
* @since 3.4.2
|
||||
* @author Soponar Cristina
|
||||
*
|
||||
* @param array $disable_images_lazyload Array with plugins which disable lazyload functionality.
|
||||
* @return array A list of plugin names.
|
||||
*/
|
||||
public function is_smush_lazyload_active( array $disable_images_lazyload ) {
|
||||
$enabled = $this->is_smush_lazyload_enabled();
|
||||
|
||||
if ( $enabled['images'] ) {
|
||||
$disable_images_lazyload[] = __( 'Smush', 'rocket' );
|
||||
}
|
||||
|
||||
return $disable_images_lazyload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "Smush" to the provided array if WP Smush lazyload is enabled for iframes.
|
||||
*
|
||||
* @since 3.5.5
|
||||
*
|
||||
* @param array $disable_iframes_lazyload Array with plugins which disable lazyload functionality.
|
||||
* @return array A list of plugin names.
|
||||
*/
|
||||
public function is_smush_iframes_lazyload_active( $disable_iframes_lazyload ) {
|
||||
$enabled = $this->is_smush_lazyload_enabled();
|
||||
|
||||
if ( $enabled['iframes'] ) {
|
||||
$disable_iframes_lazyload[] = __( 'Smush', 'rocket' );
|
||||
}
|
||||
|
||||
return $disable_iframes_lazyload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if Smush’s lazyload is enabled for each type of content.
|
||||
*
|
||||
* @since 3.5.5
|
||||
*
|
||||
* @return array {
|
||||
* @var bool $images True when lazyload is enabled for images. False otherwise.
|
||||
* @var bool $iframes True when lazyload is enabled for iframes. False otherwise.
|
||||
* }
|
||||
*/
|
||||
private function is_smush_lazyload_enabled() {
|
||||
$enabled = [
|
||||
'images' => false,
|
||||
'iframes' => false,
|
||||
];
|
||||
|
||||
if ( ! class_exists( '\Smush\Core\Settings' ) ) {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
if ( ! method_exists( '\Smush\Core\Settings', 'get_instance' ) ) {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
$smush_settings = Settings::get_instance();
|
||||
|
||||
if ( ! method_exists( $smush_settings, 'get' ) || ! method_exists( $smush_settings, 'get_setting' ) ) {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
if ( ! $smush_settings->get( 'lazy_load' ) ) {
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
$prefix = rocket_get_constant( 'WP_SMUSH_PREFIX', 'wp-smush-' );
|
||||
$formats = $smush_settings->get_setting( $prefix . 'lazy_load' );
|
||||
$formats = ! empty( $formats['format'] ) && is_array( $formats['format'] ) ? array_filter( $formats['format'] ) : [];
|
||||
|
||||
$image_formats = array_intersect_key(
|
||||
$formats,
|
||||
// Allowlist image formats.
|
||||
[
|
||||
'jpeg' => false,
|
||||
'png' => false,
|
||||
'gif' => false,
|
||||
'svg' => false,
|
||||
]
|
||||
);
|
||||
|
||||
if ( ! empty( $image_formats ) ) {
|
||||
// One or several image formats are enabled in Smush.
|
||||
$enabled['images'] = true;
|
||||
}
|
||||
|
||||
if ( ! empty( $formats['iframe'] ) ) {
|
||||
// Iframe is enabled in Smush.
|
||||
$enabled['iframes'] = true;
|
||||
}
|
||||
|
||||
return $enabled;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user