add wp-rocket
This commit is contained in:
402
wp-content/plugins/wp-rocket/inc/deprecated/3.2.php
Normal file
402
wp-content/plugins/wp-rocket/inc/deprecated/3.2.php
Normal file
@@ -0,0 +1,402 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Add a message about Imagify on the "Upload New Media" screen and WP Rocket options page.
|
||||
*
|
||||
* @since 2.7
|
||||
* @deprecated 3.2
|
||||
*/
|
||||
function rocket_imagify_notice() {
|
||||
_deprecated_function( __FUNCTION__, '3.2' );
|
||||
$current_screen = get_current_screen();
|
||||
|
||||
// Add the notice only on the "WP Rocket" settings, "Media Library" & "Upload New Media" screens.
|
||||
if ( 'admin_notices' === current_filter() && ( isset( $current_screen ) && 'settings_page_wprocket' !== $current_screen->base ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$boxes = get_user_meta( $GLOBALS['current_user']->ID, 'rocket_boxes', true );
|
||||
|
||||
if ( defined( 'IMAGIFY_VERSION' ) || in_array( __FUNCTION__, (array) $boxes, true ) || 1 === get_option( 'wp_rocket_dismiss_imagify_notice' ) || ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$imagify_plugin = 'imagify/imagify.php';
|
||||
$is_imagify_installed = rocket_is_plugin_installed( $imagify_plugin );
|
||||
|
||||
$action_url = $is_imagify_installed ?
|
||||
rocket_get_plugin_activation_link( $imagify_plugin )
|
||||
:
|
||||
wp_nonce_url( add_query_arg(
|
||||
array(
|
||||
'action' => 'install-plugin',
|
||||
'plugin' => 'imagify',
|
||||
),
|
||||
admin_url( 'update.php' )
|
||||
), 'install-plugin_imagify' );
|
||||
|
||||
$details_url = add_query_arg(
|
||||
array(
|
||||
'tab' => 'plugin-information',
|
||||
'plugin' => 'imagify',
|
||||
'TB_iframe' => true,
|
||||
'width' => 722,
|
||||
'height' => 949,
|
||||
),
|
||||
admin_url( 'plugin-install.php' )
|
||||
);
|
||||
|
||||
$classes = $is_imagify_installed ? '' : ' install-now';
|
||||
$cta_txt = $is_imagify_installed ? esc_html__( 'Activate Imagify', 'rocket' ) : esc_html__( 'Install Imagify for Free', 'rocket' );
|
||||
|
||||
$dismiss_url = wp_nonce_url(
|
||||
admin_url( 'admin-post.php?action=rocket_ignore&box=' . __FUNCTION__ ),
|
||||
'rocket_ignore_' . __FUNCTION__
|
||||
);
|
||||
?>
|
||||
|
||||
<div id="plugin-filter" class="updated plugin-card plugin-card-imagify rkt-imagify-notice">
|
||||
<a href="<?php echo $dismiss_url; ?>" class="rkt-cross"><span class="dashicons dashicons-no"></span></a>
|
||||
|
||||
<p class="rkt-imagify-logo">
|
||||
<img src="<?php echo WP_ROCKET_ASSETS_IMG_URL; ?>logo-imagify.png" srcset="<?php echo WP_ROCKET_ASSETS_IMG_URL; ?>logo-imagify.svg 2x" alt="Imagify" width="150" height="18">
|
||||
</p>
|
||||
<p class="rkt-imagify-msg">
|
||||
<?php _e( 'Speed up your website and boost your SEO by reducing image file sizes without losing quality with Imagify.', 'rocket' ); ?>
|
||||
</p>
|
||||
<p class="rkt-imagify-cta">
|
||||
<a data-slug="imagify" href="<?php echo $action_url; ?>" class="button button-primary<?php echo $classes; ?>"><?php echo $cta_txt; ?></a>
|
||||
<?php if ( ! $is_imagify_installed ) : ?>
|
||||
<br><a data-slug="imagify" data-name="Imagify Image Optimizer" class="thickbox open-plugin-details-modal" href="<?php echo $details_url; ?>"><?php _e( 'More details', 'rocket' ); ?></a>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'run_rocket_preload_cache' ) ) :
|
||||
/**
|
||||
* Launches the preload
|
||||
*
|
||||
* @since 2.8
|
||||
* @author Remy Perona
|
||||
* @deprecated 3.2
|
||||
*
|
||||
* @param string $spider The spider name.
|
||||
* @param bool $do_sitemap_preload Do the sitemap preload.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function run_rocket_preload_cache( $spider, $do_sitemap_preload = true ) {
|
||||
_deprecated_function( __FUNCTION__, '3.2' );
|
||||
|
||||
// Preload cache.
|
||||
run_rocket_bot( $spider );
|
||||
|
||||
if ( $do_sitemap_preload & get_rocket_option( 'sitemap_preload', false ) ) {
|
||||
$rocket_background_process = $GLOBALS['rocket_sitemap_background_process'];
|
||||
|
||||
if ( method_exists( $rocket_background_process, 'cancel_process' ) ) {
|
||||
$rocket_background_process->cancel_process();
|
||||
}
|
||||
|
||||
delete_transient( 'rocket_sitemap_preload_running' );
|
||||
delete_transient( 'rocket_sitemap_preload_complete' );
|
||||
run_rocket_sitemap_preload();
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'do_rocket_bot_cache_json' ) ) :
|
||||
/**
|
||||
* Run WP Rocket Bot when a post is added, updated or deleted
|
||||
*
|
||||
* @since 1.3.2
|
||||
* @deprecated 3.2
|
||||
*/
|
||||
function do_rocket_bot_cache_json() {
|
||||
_deprecated_function( __FUNCTION__, '3.2' );
|
||||
return false;
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_process_sitemap' ) ) {
|
||||
/**
|
||||
* Processes the sitemaps recursively
|
||||
*
|
||||
* @since 2.8
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $sitemap_url URL of the sitemap.
|
||||
* @param array $urls An array of URLs.
|
||||
* @return array Empty array or array containing URLs
|
||||
*/
|
||||
function rocket_process_sitemap( $sitemap_url, $urls = array() ) {
|
||||
_deprecated_function( __FUNCTION__, '3.2' );
|
||||
$tmp_urls = array();
|
||||
|
||||
/**
|
||||
* Filters the arguments for the sitemap preload request
|
||||
*
|
||||
* @since 2.10.8
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param array $args Arguments for the request.
|
||||
*/
|
||||
$args = apply_filters( 'rocket_preload_sitemap_request_args', array(
|
||||
'user-agent' => 'WP Rocket/Sitemaps',
|
||||
'sslverify' => apply_filters( 'https_local_ssl_verify', true ),
|
||||
) );
|
||||
|
||||
$sitemap = wp_remote_get( esc_url( $sitemap_url ), $args );
|
||||
|
||||
if ( is_wp_error( $sitemap ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$xml_data = wp_remote_retrieve_body( $sitemap );
|
||||
|
||||
if ( empty( $xml_data ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
libxml_use_internal_errors( true );
|
||||
|
||||
$xml = simplexml_load_string( $xml_data );
|
||||
|
||||
if ( false === $xml ) {
|
||||
libxml_clear_errors();
|
||||
return array();
|
||||
}
|
||||
|
||||
$url_count = count( $xml->url );
|
||||
|
||||
if ( $url_count > 0 ) {
|
||||
for ( $i = 0; $i < $url_count; $i++ ) {
|
||||
$page_url = (string) $xml->url[ $i ]->loc;
|
||||
$tmp_urls[] = $page_url;
|
||||
}
|
||||
} else {
|
||||
// Sub sitemap?
|
||||
$sitemap_children = count( $xml->sitemap );
|
||||
if ( $sitemap_children > 0 ) {
|
||||
for ( $i = 0; $i < $sitemap_children; $i++ ) {
|
||||
$sub_sitemap_url = (string) $xml->sitemap[ $i ]->loc;
|
||||
$urls = rocket_process_sitemap( $sub_sitemap_url, $urls );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$urls = array_merge( $urls, $tmp_urls );
|
||||
return $urls;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'rocket_sitemap_preload_complete' ) ) {
|
||||
/**
|
||||
* This notice is displayed after the sitemap preload is complete
|
||||
*
|
||||
* @since 2.11
|
||||
* @deprecated 3.2
|
||||
* @author Remy Perona
|
||||
*/
|
||||
function rocket_sitemap_preload_complete() {
|
||||
_deprecated_function( __FUNCTION__, '3.2' );
|
||||
$screen = get_current_screen();
|
||||
|
||||
/** This filter is documented in inc/admin-bar.php */
|
||||
if ( ! current_user_can( apply_filters( 'rocket_capacity', 'manage_options' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'settings_page_wprocket' !== $screen->id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$result = get_transient( 'rocket_sitemap_preload_complete' );
|
||||
if ( false === $result ) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete_transient( 'rocket_sitemap_preload_complete' );
|
||||
|
||||
rocket_notice_html( array(
|
||||
// translators: %d is the number of pages preloaded.
|
||||
'message' => sprintf( __( 'Sitemap preload: %d pages have been cached.', 'rocket' ), $result ),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'rocket_sitemap_preload_running' ) ) {
|
||||
/**
|
||||
* This notice is displayed when the sitemap preload is running
|
||||
*
|
||||
* @since 2.11
|
||||
* @deprecated 3.2
|
||||
* @author Remy Perona
|
||||
*/
|
||||
function rocket_sitemap_preload_running() {
|
||||
_deprecated_function( __FUNCTION__, '3.2' );
|
||||
$screen = get_current_screen();
|
||||
|
||||
// This filter is documented in inc/admin-bar.php.
|
||||
if ( ! current_user_can( apply_filters( 'rocket_capacity', 'manage_options' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'settings_page_wprocket' !== $screen->id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$running = get_transient( 'rocket_sitemap_preload_running' );
|
||||
if ( false === $running ) {
|
||||
return;
|
||||
}
|
||||
|
||||
rocket_notice_html( array(
|
||||
// translators: %d = Number of pages preloaded.
|
||||
'message' => sprintf( __( 'Sitemap preload: %d uncached pages have now been preloaded. (refresh to see progress)', 'rocket' ), $running ),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'run_rocket_bot_after_clean_post' ) ) {
|
||||
/**
|
||||
* Actions to be done after the purge cache files of a post
|
||||
* By Default, this hook call the WP Rocket Bot (cache json)
|
||||
*
|
||||
* @deprecated 3.2
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @param object $post The post object.
|
||||
* @param array $purge_urls An array of URLs to clean.
|
||||
* @param string $lang The language to clean.
|
||||
*/
|
||||
function run_rocket_bot_after_clean_post( $post, $purge_urls, $lang ) {
|
||||
_deprecated_function( __FUNCTION__, '3.2' );
|
||||
// Run robot only if post is published.
|
||||
if ( 'publish' !== $post->post_status ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add Homepage URL to $purge_urls for bot crawl.
|
||||
array_push( $purge_urls, get_rocket_i18n_home_url( $lang ) );
|
||||
|
||||
// Add default WordPress feeds (posts & comments).
|
||||
array_push( $purge_urls, get_feed_link() );
|
||||
array_push( $purge_urls, get_feed_link( 'comments_' ) );
|
||||
|
||||
// Get the author page.
|
||||
$purge_author = array( get_author_posts_url( $post->post_author ) );
|
||||
|
||||
// Get all dates archive page.
|
||||
$purge_dates = get_rocket_post_dates_urls( $post->ID );
|
||||
|
||||
// Remove dates archives page and author page to preload cache.
|
||||
$purge_urls = array_diff( $purge_urls, $purge_dates, $purge_author );
|
||||
|
||||
// Create json file and run WP Rocket Bot.
|
||||
$json_encode_urls = '["' . implode( '","', array_filter( $purge_urls ) ) . '"]';
|
||||
if ( rocket_put_content( WP_ROCKET_PATH . 'cache.json', $json_encode_urls ) ) {
|
||||
global $do_rocket_bot_cache_json;
|
||||
$do_rocket_bot_cache_json = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'run_rocket_bot_after_clean_term' ) ) {
|
||||
/**
|
||||
* Actions to be done after the purge cache files of a term
|
||||
* By Default, this hook call the WP Rocket Bot (cache json)
|
||||
*
|
||||
* @deprecated 3.2
|
||||
* @since 2.6.8
|
||||
*
|
||||
* @param object $post The post object.
|
||||
* @param array $purge_urls An array of URLs to clean.
|
||||
* @param string $lang The language to clean.
|
||||
*/
|
||||
function run_rocket_bot_after_clean_term( $post, $purge_urls, $lang ) {
|
||||
_deprecated_function( __FUNCTION__, '3.2' );
|
||||
// Add Homepage URL to $purge_urls for bot crawl.
|
||||
array_push( $purge_urls, get_rocket_i18n_home_url( $lang ) );
|
||||
|
||||
// Create json file and run WP Rocket Bot.
|
||||
$json_encode_urls = '["' . implode( '","', array_filter( $purge_urls ) ) . '"]';
|
||||
if ( rocket_put_content( WP_ROCKET_PATH . 'cache.json', $json_encode_urls ) ) {
|
||||
global $do_rocket_bot_cache_json;
|
||||
$do_rocket_bot_cache_json = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'rocket_clean_directory_for_default_language_on_wpml' ) ) {
|
||||
/**
|
||||
* Conflict with WPML: Clear the homepage when the "Use directory for default language" option is activated.
|
||||
*
|
||||
* @since 2.6.8
|
||||
* @deprecated 3.2.4
|
||||
*/
|
||||
function rocket_clean_directory_for_default_language_on_wpml() {
|
||||
_deprecated_function( __FUNCTION__, '3.2.4' );
|
||||
$option = get_option( 'icl_sitepress_settings' );
|
||||
|
||||
if ( 1 === $option['language_negotiation_type'] && $option['urls']['directory_for_default_language'] ) {
|
||||
rocket_clean_files( home_url() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'rocket_fetch_and_cache_busting' ) ) {
|
||||
/**
|
||||
* Fetch and save the cache busting file content
|
||||
*
|
||||
* @since 2.10
|
||||
* @deprecated 3.2.5
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $src Original URL of the asset.
|
||||
* @param array $cache_busting_paths Paths used to generated the cache busting file.
|
||||
* @param string $abspath_src Absolute path to the asset.
|
||||
* @param string $current_filter Current filter value.
|
||||
* @return bool true if successful, false otherwise
|
||||
*/
|
||||
function rocket_fetch_and_cache_busting( $src, $cache_busting_paths, $abspath_src, $current_filter ) {
|
||||
_deprecated_function( __FUNCTION__, '3.2.5' );
|
||||
if ( wp_is_stream( $src ) ) {
|
||||
$response = wp_remote_get( $src );
|
||||
$content = wp_remote_retrieve_body( $response );
|
||||
} else {
|
||||
$content = rocket_direct_filesystem()->get_contents( $src );
|
||||
}
|
||||
|
||||
if ( ! $content ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( 'style_loader_src' === $current_filter ) {
|
||||
/**
|
||||
* Filters the Document Root path to use during CSS minification to rewrite paths
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param string The Document Root path.
|
||||
*/
|
||||
$document_root = apply_filters( 'rocket_min_documentRoot', wp_normalize_path( dirname( $_SERVER['SCRIPT_FILENAME'] ) ) );
|
||||
|
||||
// Rewrite import/url in CSS content to add the absolute path to the file.
|
||||
$content = Minify_CSS_UriRewriter::rewrite( $content, dirname( $abspath_src ), $document_root );
|
||||
}
|
||||
|
||||
if ( ! rocket_direct_filesystem()->is_dir( $cache_busting_paths['bustingpath'] ) ) {
|
||||
rocket_mkdir_p( $cache_busting_paths['bustingpath'] );
|
||||
}
|
||||
|
||||
rocket_mkdir_p( dirname( $cache_busting_paths['filepath'] ) );
|
||||
|
||||
return rocket_put_content( $cache_busting_paths['filepath'], $content );
|
||||
}
|
||||
}
|
874
wp-content/plugins/wp-rocket/inc/deprecated/3.3.php
Normal file
874
wp-content/plugins/wp-rocket/inc/deprecated/3.3.php
Normal file
@@ -0,0 +1,874 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
if ( ! function_exists( 'get_rocket_footprint' ) ) :
|
||||
/**
|
||||
* Get WP Rocket footprint
|
||||
*
|
||||
* @deprecated 3.3
|
||||
* @since 3.0.5 White label footprint if WP_ROCKET_WHITE_LABEL_FOOTPRINT is defined.
|
||||
* @since 2.0
|
||||
*
|
||||
* @param bool $debug (default: true) If true, adds the date of generation cache file.
|
||||
* @return string The footprint that will be printed
|
||||
*/
|
||||
function get_rocket_footprint( $debug = true ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3', '\WP_Rocket\Buffer\Cache->get_rocket_footprint()' );
|
||||
$footprint = defined( 'WP_ROCKET_WHITE_LABEL_FOOTPRINT' ) ?
|
||||
"\n" . '<!-- Cached for great performance' :
|
||||
"\n" . '<!-- This website is like a Rocket, isn\'t it? Performance optimized by ' . WP_ROCKET_PLUGIN_NAME . '. Learn more: https://wp-rocket.me';
|
||||
if ( $debug ) {
|
||||
$footprint .= ' - Debug: cached@' . time();
|
||||
}
|
||||
$footprint .= ' -->';
|
||||
return $footprint;
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_lazyload_script' ) ) :
|
||||
/**
|
||||
* Add lazyload options to the footer
|
||||
*
|
||||
* @deprecated 3.3
|
||||
* @since 2.11 load options in the footer and add filter for the treshold
|
||||
* @since 1.3.5 It's possible to exclude LazyLoad process by used do_rocket_lazyload filter
|
||||
* @since 1.1.0 This code is insert in head with inline script for more performance
|
||||
* @since 1.0
|
||||
*/
|
||||
function rocket_lazyload_script() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3', '\RocketLazyload\Assets::insertLazyloadScript()' );
|
||||
if ( ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ( ! get_rocket_option( 'lazyload' ) && ! get_rocket_option( 'lazyload_iframes' ) ) || ( ! apply_filters( 'do_rocket_lazyload', true ) && ! apply_filters( 'do_rocket_lazyload_iframes', true ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
||||
$elements = [];
|
||||
|
||||
if ( get_rocket_option( 'lazyload' ) ) {
|
||||
$elements[] = 'img';
|
||||
}
|
||||
|
||||
if ( get_rocket_option( 'lazyload_iframes' ) ) {
|
||||
$elements[] = 'iframe';
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the threshold at which lazyload is triggered
|
||||
*
|
||||
* @since 2.11
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param int $threshold Threshold value.
|
||||
*/
|
||||
$threshold = apply_filters( 'rocket_lazyload_threshold', 300 );
|
||||
|
||||
echo '<script>(function(w, d){
|
||||
var b = d.getElementsByTagName("body")[0];
|
||||
var s = d.createElement("script"); s.async = true;
|
||||
s.src = !("IntersectionObserver" in w) ? "' . get_rocket_cdn_url( WP_ROCKET_FRONT_JS_URL, array( 'all', 'css_and_js', 'js' ) ) . 'lazyload-8.15.2' . $suffix . '.js" : "' . get_rocket_cdn_url( WP_ROCKET_FRONT_JS_URL, array( 'all', 'css_and_js', 'js' ) ) . 'lazyload-10.17' . $suffix . '.js";
|
||||
w.lazyLoadOptions = {
|
||||
elements_selector: "' . esc_attr( implode( ',', $elements ) ) . '",
|
||||
data_src: "lazy-src",
|
||||
data_srcset: "lazy-srcset",
|
||||
data_sizes: "lazy-sizes",
|
||||
skip_invisible: false,
|
||||
class_loading: "lazyloading",
|
||||
class_loaded: "lazyloaded",
|
||||
threshold: ' . esc_attr( $threshold ) . ',
|
||||
callback_load: function(element) {
|
||||
if ( element.tagName === "IFRAME" && element.dataset.rocketLazyload == "fitvidscompatible" ) {
|
||||
if (element.classList.contains("lazyloaded") ) {
|
||||
if (typeof window.jQuery != "undefined") {
|
||||
if (jQuery.fn.fitVids) {
|
||||
jQuery(element).parent().fitVids();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}; // Your options here. See "recipes" for more information about async.
|
||||
b.appendChild(s);
|
||||
}(window, document));
|
||||
|
||||
// Listen to the Initialized event
|
||||
window.addEventListener(\'LazyLoad::Initialized\', function (e) {
|
||||
// Get the instance and puts it in the lazyLoadInstance variable
|
||||
var lazyLoadInstance = e.detail.instance;
|
||||
|
||||
var observer = new MutationObserver(function(mutations) {
|
||||
mutations.forEach(function(mutation) {
|
||||
lazyLoadInstance.update();
|
||||
} );
|
||||
} );
|
||||
|
||||
var b = document.getElementsByTagName("body")[0];
|
||||
var config = { childList: true, subtree: true };
|
||||
|
||||
observer.observe(b, config);
|
||||
}, false);
|
||||
</script>';
|
||||
|
||||
if ( get_rocket_option( 'lazyload_youtube' ) ) {
|
||||
/**
|
||||
* Filters the resolution of the YouTube thumbnail
|
||||
*
|
||||
* @since 2.11.5
|
||||
* @author Arun Basil Lal
|
||||
*
|
||||
* @param string $thumbnail_resolution The resolution of the thumbnail. Accepted values: default, mqdefault, sddefault, hqdefault, maxresdefault
|
||||
*/
|
||||
$thumbnail_resolution = apply_filters( 'rocket_youtube_thumbnail_resolution', 'hqdefault' );
|
||||
|
||||
echo <<<HTML
|
||||
<script>function lazyLoadThumb(e){var t='<img src="https://i.ytimg.com/vi/ID/$thumbnail_resolution.jpg">',a='<div class="play"></div>';return t.replace("ID",e)+a}function lazyLoadYoutubeIframe(){var e=document.createElement("iframe"),t="https://www.youtube.com/embed/ID?autoplay=1";t+=0===this.dataset.query.length?'':'&'+this.dataset.query;e.setAttribute("src",t.replace("ID",this.dataset.id)),e.setAttribute("frameborder","0"),e.setAttribute("allowfullscreen","1"),this.parentNode.replaceChild(e,this)}document.addEventListener("DOMContentLoaded",function(){var e,t,a=document.getElementsByClassName("rll-youtube-player");for(t=0;t<a.length;t++)e=document.createElement("div"),e.setAttribute("data-id",a[t].dataset.id),e.setAttribute("data-query", a[t].dataset.query),e.innerHTML=lazyLoadThumb(a[t].dataset.id),e.onclick=lazyLoadYoutubeIframe,a[t].appendChild(e)});</script>
|
||||
HTML;
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_lazyload_enqueue' ) ) :
|
||||
/**
|
||||
* Enqueue the CSS code for Youtube lazyload styling
|
||||
*
|
||||
* @deprecated 3.3
|
||||
* @since 2.11
|
||||
* @author Remy Perona
|
||||
*/
|
||||
function rocket_lazyload_enqueue() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3', '\RocketLazyload\Assets::insertYoutubeThumbnailCSS()' );
|
||||
if ( ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ( ! get_rocket_option( 'lazyload_iframes' ) ) || ( ! apply_filters( 'do_rocket_lazyload', true ) && ! apply_filters( 'do_rocket_lazyload_iframes', true ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( get_rocket_option( 'lazyload_youtube' ) ) {
|
||||
$css = '.rll-youtube-player{position:relative;padding-bottom:56.23%;height:0;overflow:hidden;max-width:100%;background:#000;margin:5px}.rll-youtube-player iframe{position:absolute;top:0;left:0;width:100%;height:100%;z-index:100;background:0 0}.rll-youtube-player img{bottom:0;display:block;left:0;margin:auto;max-width:100%;width:100%;position:absolute;right:0;top:0;border:none;height:auto;cursor:pointer;-webkit-transition:.4s all;-moz-transition:.4s all;transition:.4s all}.rll-youtube-player img:hover{-webkit-filter:brightness(75%)}.rll-youtube-player .play{height:72px;width:72px;left:50%;top:50%;margin-left:-36px;margin-top:-36px;position:absolute;background:url(' . WP_ROCKET_FRONT_URL . 'img/youtube.png) no-repeat;cursor:pointer}';
|
||||
|
||||
wp_register_style( 'rocket-lazyload', false );
|
||||
wp_enqueue_style( 'rocket-lazyload' );
|
||||
wp_add_inline_style( 'rocket-lazyload', $css );
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_lazyload_images' ) ) :
|
||||
/**
|
||||
* Replace Gravatar, thumbnails, images in post content and in widget text by LazyLoad
|
||||
*
|
||||
* @deprecated 3.3
|
||||
* @since 2.6 Add the get_image_tag filter
|
||||
* @since 2.2 Better regex pattern in a replace_callback
|
||||
* @since 1.3.5 It's possible to exclude LazyLoad process by used do_rocket_lazyload filter
|
||||
* @since 1.2.0 It's possible to not lazyload an image with data-no-lazy attribute
|
||||
* @since 1.1.0 Don't lazyload if the thumbnail has already been run through previously
|
||||
* @since 1.0.1 Add priority of hooks at maximum later with PHP_INT_MAX
|
||||
* @since 1.0
|
||||
*
|
||||
* @param string $html HTML content.
|
||||
* @return string Modified HTML content
|
||||
*/
|
||||
function rocket_lazyload_images( $html ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3', '\RocketLazyload\Images::lazyloadImages()' );
|
||||
// Don't LazyLoad if process is stopped for these reasons.
|
||||
if ( ! get_rocket_option( 'lazyload' ) || ! apply_filters( 'do_rocket_lazyload', true ) || is_feed() || is_preview() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) || empty( $html ) || ( defined( 'DONOTLAZYLOAD' ) && DONOTLAZYLOAD ) || wp_script_is( 'twentytwenty-twentytwenty', 'enqueued' ) ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
$html = preg_replace_callback( '#<img([^>]*) src=("(?:[^"]+)"|\'(?:[^\']+)\'|(?:[^ >]+))([^>]*)>#', 'rocket_lazyload_replace_callback', $html );
|
||||
|
||||
return $html;
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_lazyload_replace_callback' ) ) :
|
||||
/**
|
||||
* Used to check if we have to LazyLoad this or not
|
||||
*
|
||||
* @deprecated 3.3
|
||||
* @since 2.5.5 Don't apply LazyLoad on images from WP Retina x2
|
||||
* @since 2.5 Don't apply LazyLoad on all images from LayerSlider
|
||||
* @since 2.4.2 Don't apply LazyLoad on all images from Media Grid
|
||||
* @since 2.3.11 Don't apply LazyLoad on all images from Timthumb
|
||||
* @since 2.3.10 Don't apply LazyLoad on all images from Revolution Slider & Justified Image Grid
|
||||
* @since 2.3.8 Don't apply LazyLoad on captcha from Really Simple CAPTCHA
|
||||
* @since 2.2
|
||||
*
|
||||
* @param array $matches Images matching the regex.
|
||||
* @return string Modified HTML content
|
||||
*/
|
||||
function rocket_lazyload_replace_callback( $matches ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3', '\RocketLazyload\Images::lazyloadImages()' );
|
||||
// Don't apply LazyLoad on images from WP Retina x2.
|
||||
if ( function_exists( 'wr2x_picture_rewrite' ) ) {
|
||||
if ( wr2x_get_retina( trailingslashit( ABSPATH ) . wr2x_get_pathinfo_from_image_src( trim( $matches[2], '"' ) ) ) ) {
|
||||
return $matches[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the attributes used to prevent lazylad from being applied
|
||||
*
|
||||
* @since 2.11
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param array $excluded_attributes An array of excluded attributes.
|
||||
*/
|
||||
$excluded_attributes = apply_filters(
|
||||
'rocket_lazyload_excluded_attributes', array(
|
||||
'data-src=',
|
||||
'data-no-lazy=',
|
||||
'data-lazy-original=',
|
||||
'data-lazy-src=',
|
||||
'data-lazysrc=',
|
||||
'data-lazyload=',
|
||||
'data-bgposition=',
|
||||
'data-envira-src=',
|
||||
'fullurl=',
|
||||
'lazy-slider-img=',
|
||||
'data-srcset=',
|
||||
'class="ls-l',
|
||||
'class="ls-bg',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters the src used to prevent lazylad from being applied
|
||||
*
|
||||
* @since 2.11
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param array $excluded_src An array of excluded src.
|
||||
*/
|
||||
$excluded_src = apply_filters(
|
||||
'rocket_lazyload_excluded_src', array(
|
||||
'/wpcf7_captcha/',
|
||||
'timthumb.php?src',
|
||||
)
|
||||
);
|
||||
|
||||
if ( rocket_is_excluded_lazyload( $matches[1] . $matches[3], $excluded_attributes ) || rocket_is_excluded_lazyload( $matches[2], $excluded_src ) ) {
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the LazyLoad placeholder on src attribute
|
||||
*
|
||||
* @since 1.1
|
||||
*
|
||||
* @param string $placeholder Placeholder that will be printed.
|
||||
*/
|
||||
$placeholder = apply_filters( 'rocket_lazyload_placeholder', 'data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=' );
|
||||
|
||||
$html = sprintf( '<img%1$s src="%4$s" data-lazy-src=%2$s%3$s>', $matches[1], $matches[2], $matches[3], $placeholder );
|
||||
|
||||
$html_noscript = sprintf( '<noscript><img%1$s src=%2$s%3$s></noscript>', $matches[1], $matches[2], $matches[3] );
|
||||
|
||||
/**
|
||||
* Filter the LazyLoad HTML output
|
||||
*
|
||||
* @since 1.0.2
|
||||
*
|
||||
* @param array $html Output that will be printed
|
||||
*/
|
||||
$html = apply_filters( 'rocket_lazyload_html', $html, true );
|
||||
|
||||
return $html . $html_noscript;
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_is_excluded_lazyload' ) ) :
|
||||
/**
|
||||
* Determine if the current image should be excluded from lazyload
|
||||
*
|
||||
* @deprecated 3.3
|
||||
* @since 1.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $string String to search.
|
||||
* @param array $excluded_values Array of excluded values to search in the string.
|
||||
* @return bool True if one of the excluded values was found, false otherwise
|
||||
*/
|
||||
function rocket_is_excluded_lazyload( $string, $excluded_values ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3', '\RocketLazyload\Images::isExcluded()' );
|
||||
foreach ( $excluded_values as $excluded_value ) {
|
||||
if ( strpos( $string, $excluded_value ) !== false ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_lazyload_smilies' ) ) :
|
||||
/**
|
||||
* Replace WordPress smilies by Lazy Load
|
||||
*
|
||||
* @since 3.3
|
||||
* @since 2.0 New system for replace smilies by Lazy Load
|
||||
* @since 1.3.5 It's possible to exclude LazyLoad process by used do_rocket_lazyload filter
|
||||
* @since 1.1.0 Don't lazy-load if the thumbnail has already been run through previously
|
||||
* @since 1.0.1 Add priority of hooks at maximum later with PHP_INT_MAX
|
||||
* @since 1.0
|
||||
*/
|
||||
function rocket_lazyload_smilies() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3', '\WP_Rocket\Subscriber\Optimization\Lazyload_Subscriber::lazyload_smilies()' );
|
||||
if ( ! get_rocket_option( 'lazyload' ) || ! apply_filters( 'do_rocket_lazyload', true, 'smilies' ) || ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) || ( defined( 'DONOTLAZYLOAD' ) && DONOTLAZYLOAD ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
remove_filter( 'the_content', 'convert_smilies' );
|
||||
remove_filter( 'the_excerpt', 'convert_smilies' );
|
||||
remove_filter( 'comment_text', 'convert_smilies', 20 );
|
||||
|
||||
add_filter( 'the_content', 'rocket_convert_smilies' );
|
||||
add_filter( 'the_excerpt', 'rocket_convert_smilies' );
|
||||
add_filter( 'comment_text', 'rocket_convert_smilies', 20 );
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_convert_smilies' ) ) :
|
||||
/**
|
||||
* Convert text equivalent of smilies to images.
|
||||
*
|
||||
* @source convert_smilies() in /wp-includes/formattings.php
|
||||
* @since 2.0
|
||||
* @deprecated 3.3
|
||||
* @param string $text Text to process.
|
||||
* @return string Modified text
|
||||
*/
|
||||
function rocket_convert_smilies( $text ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3', '\RocketLazyload\Image::convertSmilies()' );
|
||||
global $wp_smiliessearch;
|
||||
|
||||
if ( ! get_option( 'use_smilies' ) || empty( $wp_smiliessearch ) ) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
$output = '';
|
||||
// HTML loop taken from texturize function, could possible be consolidated.
|
||||
$textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // capture the tags as well as in between.
|
||||
$stop = count( $textarr );// loop stuff.
|
||||
|
||||
// Ignore proessing of specific tags.
|
||||
$tags_to_ignore = 'code|pre|style|script|textarea';
|
||||
$ignore_block_element = '';
|
||||
|
||||
for ( $i = 0; $i < $stop; $i++ ) {
|
||||
$content = $textarr[ $i ];
|
||||
|
||||
// If we're in an ignore block, wait until we find its closing tag.
|
||||
if ( '' === $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')>/', $content, $matches ) ) {
|
||||
$ignore_block_element = $matches[1];
|
||||
}
|
||||
|
||||
// If it's not a tag and not in ignore block.
|
||||
if ( '' === $ignore_block_element && strlen( $content ) > 0 && '<' !== $content[0] ) {
|
||||
$content = preg_replace_callback( $wp_smiliessearch, 'rocket_translate_smiley', $content );
|
||||
}
|
||||
|
||||
// did we exit ignore block.
|
||||
if ( '' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content ) {
|
||||
$ignore_block_element = '';
|
||||
}
|
||||
|
||||
$output .= $content;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_translate_smiley' ) ) :
|
||||
/**
|
||||
* Convert one smiley code to the icon graphic file equivalent.
|
||||
*
|
||||
* @source translate_smiley() in /wp-includes/formattings.php
|
||||
* @since 2.0
|
||||
* @deprecated 3.3
|
||||
*
|
||||
* @param array $matches An array of matching content.
|
||||
* @return string HTML code for smiley
|
||||
*/
|
||||
function rocket_translate_smiley( $matches ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3', '\RocketLazyload\Image::translateSmiley()' );
|
||||
global $wpsmiliestrans;
|
||||
|
||||
if ( count( $matches ) === 0 ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$smiley = trim( reset( $matches ) );
|
||||
$img = $wpsmiliestrans[ $smiley ];
|
||||
|
||||
$matches = array();
|
||||
$ext = preg_match( '/\.([^.]+)$/', $img, $matches ) ? strtolower( $matches[1] ) : false;
|
||||
$image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
|
||||
|
||||
// Don't convert smilies that aren't images - they're probably emoji.
|
||||
if ( ! in_array( $ext, $image_exts, true ) ) {
|
||||
return $img;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the Smiley image URL before it's used in the image element.
|
||||
*
|
||||
* @since 2.9.0
|
||||
*
|
||||
* @param string $smiley_url URL for the smiley image.
|
||||
* @param string $img Filename for the smiley image.
|
||||
* @param string $site_url Site URL, as returned by site_url().
|
||||
*/
|
||||
$src_url = apply_filters( 'smilies_src', includes_url( "images/smilies/$img" ), $img, site_url() );
|
||||
|
||||
// Don't LazyLoad if process is stopped for these reasons.
|
||||
if ( is_feed() || is_preview() ) {
|
||||
return sprintf( ' <img src="%s" alt="%s" class="wp-smiley" /> ', esc_url( $src_url ), esc_attr( $smiley ) );
|
||||
}
|
||||
|
||||
/** This filter is documented in inc/front/lazyload.php */
|
||||
$placeholder = apply_filters( 'rocket_lazyload_placeholder', 'data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=' );
|
||||
|
||||
return sprintf( ' <img src="%s" data-lazy-src="%s" alt="%s" class="wp-smiley" /> ', $placeholder, esc_url( $src_url ), esc_attr( $smiley ) );
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_lazyload_iframes' ) ) :
|
||||
/**
|
||||
* Replace iframes by LazyLoad
|
||||
*
|
||||
* @deprecated 3.3
|
||||
* @since 2.6
|
||||
*
|
||||
* @param string $html HTML content.
|
||||
* @return string Modified HTML content
|
||||
*/
|
||||
function rocket_lazyload_iframes( $html ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3', '\RocketLazyload\Iframe::lazyloadIframes()' );
|
||||
// Don't LazyLoad if process is stopped for these reasons.
|
||||
if ( ! get_rocket_option( 'lazyload_iframes' ) || ! apply_filters( 'do_rocket_lazyload_iframes', true ) || is_feed() || is_preview() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || empty( $html ) || ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) || ( defined( 'DONOTLAZYLOAD' ) && DONOTLAZYLOAD ) ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
preg_match_all( '@<iframe(?<atts>\s.+)>.*</iframe>@iUs', $html, $matches, PREG_SET_ORDER );
|
||||
|
||||
if ( empty( $matches ) ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
foreach ( $matches as $iframe ) {
|
||||
// Don't mess with the Gravity Forms ajax iframe.
|
||||
if ( strpos( $iframe[0], 'gform_ajax_frame' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Don't lazyload if iframe has data-no-lazy attribute.
|
||||
if ( strpos( $iframe[0], 'data-no-lazy=' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Don't lazyload if iframe is google recaptcha fallback.
|
||||
if ( strpos( $iframe[0], 'recaptcha/api/fallback' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Given the previous regex pattern, $iframe['atts'] starts with a whitespace character.
|
||||
if ( ! preg_match( '@\ssrc\s*=\s*(\'|")(?<src>.*)\1@iUs', $iframe['atts'], $atts ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$iframe['src'] = trim( $atts['src'] );
|
||||
|
||||
if ( '' === $iframe['src'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( get_rocket_option( 'lazyload_youtube' ) ) {
|
||||
$youtube_id = rocket_lazyload_get_youtube_id_from_url( $iframe['src'] );
|
||||
|
||||
if ( $youtube_id ) {
|
||||
$query = wp_parse_url( htmlspecialchars_decode( $iframe['src'] ), PHP_URL_QUERY );
|
||||
|
||||
/**
|
||||
* Filter the LazyLoad HTML output on Youtube iframes
|
||||
*
|
||||
* @since 2.11
|
||||
*
|
||||
* @param array $html Output that will be printed.
|
||||
*/
|
||||
$youtube_lazyload = apply_filters( 'rocket_lazyload_youtube_html', '<div class="rll-youtube-player" data-id="' . esc_attr( $youtube_id ) . '" data-query="' . esc_attr( $query ) . '"></div>' );
|
||||
$youtube_lazyload .= '<noscript>' . $iframe[0] . '</noscript>';
|
||||
|
||||
$html = str_replace( $iframe[0], $youtube_lazyload, $html );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the LazyLoad placeholder on src attribute
|
||||
*
|
||||
* @since 2.11
|
||||
*
|
||||
* @param string $placeholder placeholder that will be printed.
|
||||
*/
|
||||
$placeholder = apply_filters( 'rocket_lazyload_placeholder', 'about:blank' );
|
||||
|
||||
$placeholder_atts = str_replace( $iframe['src'], $placeholder, $iframe['atts'] );
|
||||
$iframe_lazyload = str_replace( $iframe['atts'], $placeholder_atts . ' data-rocket-lazyload="fitvidscompatible" data-lazy-src="' . esc_url( $iframe['src'] ) . '"', $iframe[0] );
|
||||
|
||||
/**
|
||||
* Filter the LazyLoad HTML output on iframes
|
||||
*
|
||||
* @since 2.11
|
||||
*
|
||||
* @param array $html Output that will be printed.
|
||||
*/
|
||||
$iframe_lazyload = apply_filters( 'rocket_lazyload_iframe_html', $iframe_lazyload );
|
||||
$iframe_lazyload .= '<noscript>' . $iframe[0] . '</noscript>';
|
||||
|
||||
$html = str_replace( $iframe[0], $iframe_lazyload, $html );
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_deactivate_lazyload_on_specific_posts' ) ) :
|
||||
/**
|
||||
* Check if we need to exclude LazyLoad on specific posts
|
||||
*
|
||||
* @since 3.3
|
||||
* @since 2.5
|
||||
*/
|
||||
function rocket_deactivate_lazyload_on_specific_posts() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3', '\WP_Rocket\Subscriber\Optimization\Lazyload_Subscriber::deactivate_lazyload_on_specific_posts()' );
|
||||
if ( is_rocket_post_excluded_option( 'lazyload' ) ) {
|
||||
add_filter( 'do_rocket_lazyload', '__return_false' );
|
||||
}
|
||||
|
||||
if ( is_rocket_post_excluded_option( 'lazyload_iframes' ) ) {
|
||||
add_filter( 'do_rocket_lazyload_iframes', '__return_false' );
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_lazyload_on_srcset' ) ) :
|
||||
/**
|
||||
* Compatibility with images with srcset attribute
|
||||
*
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @since 3.3
|
||||
* @since 2.8 Also add sizes to the data-lazy-* attributes to prevent error in W3C validator
|
||||
* @since 2.7
|
||||
*
|
||||
* @param string $html HTML content.
|
||||
* @return string Modified HTML content
|
||||
*/
|
||||
function rocket_lazyload_on_srcset( $html ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3', '\RocketLazyload\Image:lazyloadResponsiveAttributes()' );
|
||||
if ( preg_match( '/srcset=("(?:[^"]+)"|\'(?:[^\']+)\'|(?:[^ >]+))/i', $html ) ) {
|
||||
$html = str_replace( 'srcset=', 'data-lazy-srcset=', $html );
|
||||
}
|
||||
|
||||
if ( preg_match( '/sizes=("(?:[^"]+)"|\'(?:[^\']+)\'|(?:[^ >]+))/i', $html ) ) {
|
||||
$html = str_replace( 'sizes=', 'data-lazy-sizes=', $html );
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_lazyload_get_youtube_id_from_url' ) ) :
|
||||
/**
|
||||
* Gets youtube video ID from URL
|
||||
*
|
||||
* @author Remy Perona
|
||||
* @deprecated 3.3
|
||||
* @since 2.11
|
||||
*
|
||||
* @param string $url URL to parse.
|
||||
* @return string Youtube video id or false if none found.
|
||||
*/
|
||||
function rocket_lazyload_get_youtube_id_from_url( $url ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3', '\RocketLazyload\Iframe:getYoutubeIDFromURL()' );
|
||||
$pattern = '#^(?:https?:)?(?://)?(?:www\.)?(?:youtu\.be|youtube\.com|youtube-nocookie\.com)/(?:embed/|v/|watch/?\?v=)([\w-]{11})#iU';
|
||||
$result = preg_match( $pattern, $url, $matches );
|
||||
|
||||
if ( ! $result ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( 'videoseries' === $matches[1] ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $matches[1];
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_user_agent' ) ) :
|
||||
/**
|
||||
* Add Rocket informations into USER_AGENT
|
||||
*
|
||||
* @since 1.1.0
|
||||
* @deprecated 3.3.6
|
||||
*
|
||||
* @param string $user_agent User Agent value.
|
||||
* @return string WP Rocket user agent
|
||||
*/
|
||||
function rocket_user_agent( $user_agent ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3.6', '\WP_Rocket\Subscriber\Plugin\Updater_Api_Common_Subscriber->get_rocket_user_agent()' );
|
||||
|
||||
$consumer_key = '';
|
||||
if ( isset( $_POST[ WP_ROCKET_SLUG ]['consumer_key'] ) ) {
|
||||
$consumer_key = $_POST[ WP_ROCKET_SLUG ]['consumer_key'];
|
||||
} elseif ( '' !== (string) get_rocket_option( 'consumer_key' ) ) {
|
||||
$consumer_key = (string) get_rocket_option( 'consumer_key' );
|
||||
}
|
||||
|
||||
$consumer_email = '';
|
||||
if ( isset( $_POST[ WP_ROCKET_SLUG ]['consumer_email'] ) ) {
|
||||
$consumer_email = $_POST[ WP_ROCKET_SLUG ]['consumer_email'];
|
||||
} elseif ( '' !== (string) get_rocket_option( 'consumer_email' ) ) {
|
||||
$consumer_email = (string) get_rocket_option( 'consumer_email' );
|
||||
}
|
||||
|
||||
$bonus = ! get_rocket_option( 'do_beta' ) ? '' : '+';
|
||||
$php_version = preg_replace( '@^(\d\.\d+).*@', '\1', phpversion() );
|
||||
$new_ua = sprintf( '%s;WP-Rocket|%s%s|%s|%s|%s|%s;', $user_agent, WP_ROCKET_VERSION, $bonus, $consumer_key, $consumer_email, esc_url( home_url() ), $php_version );
|
||||
|
||||
return $new_ua;
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_add_own_ua' ) ) :
|
||||
/**
|
||||
* Force our user agent header when we hit our urls
|
||||
*
|
||||
* @since 2.4
|
||||
* @deprecated 3.3.6
|
||||
*
|
||||
* @param array $request An array of request arguments.
|
||||
* @param string $url Requested URL.
|
||||
* @return array An array of requested arguments
|
||||
*/
|
||||
function rocket_add_own_ua( $request, $url ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3.6', '\WP_Rocket\Subscriber\Plugin\Updater_Api_Common_Subscriber->maybe_set_rocket_user_agent()' );
|
||||
|
||||
if ( ! is_string( $url ) ) {
|
||||
return $request;
|
||||
}
|
||||
|
||||
if ( strpos( $url, 'wp-rocket.me' ) !== false ) {
|
||||
$request['user-agent'] = rocket_user_agent( $request['user-agent'] );
|
||||
}
|
||||
return $request;
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_updates_exclude' ) ) :
|
||||
/**
|
||||
* Excludes WP Rocket from WP updates
|
||||
*
|
||||
* @since 1.0
|
||||
* @deprecated 3.3.6
|
||||
*
|
||||
* @param array $request An array of HTTP request arguments.
|
||||
* @param string $url The request URL.
|
||||
* @return array Updated array of HTTP request arguments.
|
||||
*/
|
||||
function rocket_updates_exclude( $request, $url ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3.6', '\WP_Rocket\Subscriber\Plugin\Updater_Subscriber->exclude_rocket_from_wp_updates()' );
|
||||
|
||||
if ( ! is_string( $url ) ) {
|
||||
return $request;
|
||||
}
|
||||
|
||||
if ( 0 !== strpos( $url, 'http://api.wordpress.org/plugins/update-check' ) || ! isset( $request['body']['plugins'] ) ) {
|
||||
return $request; // Not a plugin update request. Stop immediately.
|
||||
}
|
||||
|
||||
$plugins = maybe_unserialize( $request['body']['plugins'] );
|
||||
|
||||
if ( isset( $plugins->plugins[ plugin_basename( WP_ROCKET_FILE ) ], $plugins->active[ array_search( plugin_basename( WP_ROCKET_FILE ), $plugins->active, true ) ] ) ) {
|
||||
unset( $plugins->plugins[ plugin_basename( WP_ROCKET_FILE ) ] );
|
||||
unset( $plugins->active[ array_search( plugin_basename( WP_ROCKET_FILE ), $plugins->active, true ) ] );
|
||||
}
|
||||
|
||||
$request['body']['plugins'] = maybe_serialize( $plugins );
|
||||
return $request;
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_force_info' ) ) :
|
||||
/**
|
||||
* Hack the returned object
|
||||
*
|
||||
* @since 1.0
|
||||
* @deprecated 3.3.6
|
||||
*
|
||||
* @param false|object|array $bool The result object or array. Default false.
|
||||
* @param string $action The type of information being requested from the Plugin Install API.
|
||||
* @param object $args Plugin API arguments.
|
||||
* @return false|object|array Empty object if slug is WP Rocket, default value otherwise
|
||||
*/
|
||||
function rocket_force_info( $bool, $action, $args ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3.6', '\WP_Rocket\Subscriber\Plugin\Information_Subscriber->exclude_rocket_from_wp_info()' );
|
||||
|
||||
if ( 'plugin_information' === $action && 'wp-rocket' === $args->slug ) {
|
||||
return new stdClass();
|
||||
}
|
||||
return $bool;
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_force_info_result' ) ) :
|
||||
/**
|
||||
* Hack the returned result with our content
|
||||
*
|
||||
* @since 1.0
|
||||
* @deprecated 3.3.6
|
||||
*
|
||||
* @param object|WP_Error $res Response object or WP_Error.
|
||||
* @param string $action The type of information being requested from the Plugin Install API.
|
||||
* @param object $args Plugin API arguments.
|
||||
* @return object|WP_Error Updated response object or WP_Error
|
||||
*/
|
||||
function rocket_force_info_result( $res, $action, $args ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3.6', '\WP_Rocket\Subscriber\Plugin\Information_Subscriber->add_rocket_info()' );
|
||||
|
||||
if ( 'plugin_information' === $action && isset( $args->slug ) && 'wp-rocket' === $args->slug && isset( $res->external ) && $res->external ) {
|
||||
|
||||
$request = wp_remote_post(
|
||||
WP_ROCKET_WEB_INFO, array(
|
||||
'timeout' => 30,
|
||||
'action' => 'plugin_information',
|
||||
'request' => serialize( $args ),
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_wp_error( $request ) ) {
|
||||
// translators: %s is an URL.
|
||||
$res = new WP_Error( 'plugins_api_failed', sprintf( __( 'An unexpected error occurred. Something may be wrong with WP-Rocket.me or this server’s configuration. If you continue to have problems, <a href="%s">contact support</a>.', 'rocket' ), rocket_get_external_url( 'support', array(
|
||||
'utm_source' => 'wp_plugin',
|
||||
'utm_medium' => 'wp_rocket',
|
||||
) ) ), $request->get_error_message() );
|
||||
} else {
|
||||
$res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
|
||||
|
||||
if ( ! is_object( $res ) && ! is_array( $res ) ) {
|
||||
// translators: %s is an URL.
|
||||
$res = new WP_Error( 'plugins_api_failed', sprintf( __( 'An unexpected error occurred. Something may be wrong with WP-Rocket.me or this server’s configuration. If you continue to have problems, <a href="%s">contact support</a>.', 'rocket' ), rocket_get_external_url( 'support', array(
|
||||
'utm_source' => 'wp_plugin',
|
||||
'utm_medium' => 'wp_rocket',
|
||||
) ) ), wp_remote_retrieve_body( $request ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_check_update' ) ) :
|
||||
/**
|
||||
* When WP sets the update_plugins site transient, we set our own transient, then see rocket_add_response_to_updates
|
||||
*
|
||||
* @since 2.6.5
|
||||
* @deprecated 3.3.6
|
||||
*
|
||||
* @param Object $value Site transient object.
|
||||
*/
|
||||
function rocket_check_update( $value ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3.6', '\WP_Rocket\Subscriber\Plugin\Updater_Subscriber->maybe_add_rocket_update_data()' );
|
||||
|
||||
$timer_update_wprocket = (int) get_site_transient( 'update_wprocket' );
|
||||
$temp_object = get_site_transient( 'update_wprocket_response' );
|
||||
if ( ( ! isset( $_GET['rocket_force_update'] ) || defined( 'WP_INSTALLING' ) ) &&
|
||||
( 12 * HOUR_IN_SECONDS ) > ( time() - $timer_update_wprocket ) // retry in 12 hours.
|
||||
) {
|
||||
if ( is_object( $value ) && false !== $temp_object ) {
|
||||
if ( version_compare( $temp_object->new_version, WP_ROCKET_VERSION ) > 0 ) {
|
||||
$value->response[ $temp_object->plugin ] = $temp_object;
|
||||
} else {
|
||||
delete_site_transient( 'update_wprocket_response' );
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ( isset( $_GET['rocket_force_update'] ) ) {
|
||||
$_SERVER['REQUEST_URI'] = remove_query_arg( 'rocket_force_update' );
|
||||
}
|
||||
|
||||
$plugin_folder = plugin_basename( dirname( WP_ROCKET_FILE ) );
|
||||
$plugin_file = basename( WP_ROCKET_FILE );
|
||||
$version = true;
|
||||
if ( ! $value ) {
|
||||
$value = new stdClass();
|
||||
$value->last_checked = time();
|
||||
}
|
||||
|
||||
$response = wp_remote_get(
|
||||
WP_ROCKET_WEB_CHECK, array(
|
||||
'timeout' => 30,
|
||||
)
|
||||
);
|
||||
if ( ! is_a( $response, 'WP_Error' ) && 200 === $response['response']['code'] && strlen( $response['body'] ) > 32 ) {
|
||||
|
||||
set_site_transient( 'update_wprocket', time() );
|
||||
|
||||
list( $version, $url ) = explode( '|', $response['body'] );
|
||||
if ( version_compare( $version, WP_ROCKET_VERSION ) <= 0 ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$temp_array = array(
|
||||
'slug' => $plugin_folder,
|
||||
'plugin' => $plugin_folder . '/' . $plugin_file,
|
||||
'new_version' => $version,
|
||||
'url' => 'https://wp-rocket.me',
|
||||
'package' => $url,
|
||||
);
|
||||
|
||||
$temp_object = (object) $temp_array;
|
||||
$value->response[ $plugin_folder . '/' . $plugin_file ] = $temp_object;
|
||||
|
||||
set_site_transient( 'update_wprocket_response', $temp_object );
|
||||
} else {
|
||||
set_site_transient( 'update_wprocket', ( time() + ( 11 * HOUR_IN_SECONDS ) ) ); // retry in 1 hour in case of error..
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'rocket_reset_check_update_timer' ) ) :
|
||||
/**
|
||||
* When WP deletes the update_plugins site transient or updates the plugins, we delete our own transients to avoid another 12 hours waiting
|
||||
*
|
||||
* @since 2.6.8
|
||||
* @deprecated 3.3.6
|
||||
*
|
||||
* @param string $transient Transient name.
|
||||
* @param object $value Transient object.
|
||||
*/
|
||||
function rocket_reset_check_update_timer( $transient = 'update_plugins', $value = null ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.3.6' );
|
||||
|
||||
// $value used by setted.
|
||||
if ( 'update_plugins' === $transient ) {
|
||||
if ( is_null( $value ) || is_object( $value ) && ! isset( $value->response ) ) {
|
||||
delete_site_transient( 'update_wprocket' );
|
||||
}
|
||||
}
|
||||
}
|
||||
endif;
|
719
wp-content/plugins/wp-rocket/inc/deprecated/3.4.php
Normal file
719
wp-content/plugins/wp-rocket/inc/deprecated/3.4.php
Normal file
@@ -0,0 +1,719 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Get Zones linked to a Cloudflare account
|
||||
*
|
||||
* @since 2.9
|
||||
* @deprecated 3.4.1.2
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return Array List of zones or default no domain
|
||||
*/
|
||||
function get_rocket_cloudflare_zones() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4.1.2' );
|
||||
$cf_api_instance = get_rocket_cloudflare_api_instance();
|
||||
$domains = array(
|
||||
'' => __( 'Choose a domain from the list', 'rocket' ),
|
||||
);
|
||||
|
||||
if ( is_wp_error( $cf_api_instance ) ) {
|
||||
return $domains;
|
||||
}
|
||||
|
||||
try {
|
||||
$cf_zone_instance = new Cloudflare\Zone( $cf_api_instance );
|
||||
$cf_zones = $cf_zone_instance->zones( null, 'active', null, 50 );
|
||||
$cf_zones_list = $cf_zones->result;
|
||||
|
||||
if ( ! (bool) $cf_zones_list ) {
|
||||
$domains[] = __( 'No domain available in your Cloudflare account', 'rocket' );
|
||||
|
||||
return $domains;
|
||||
}
|
||||
|
||||
foreach ( $cf_zones_list as $cf_zone ) {
|
||||
$domains[ $cf_zone->name ] = $cf_zone->name;
|
||||
}
|
||||
|
||||
return $domains;
|
||||
} catch ( Exception $e ) {
|
||||
return $domains;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get CNAMES hosts
|
||||
*
|
||||
* @since 2.3
|
||||
* @deprecated 3.4
|
||||
*
|
||||
* @param string $zones CNAMES zones.
|
||||
* @return array $hosts CNAMES hosts
|
||||
*/
|
||||
function get_rocket_cnames_host( $zones = array( 'all' ) ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4', '\WP_Rocket\Subscriber\CDN\CDNSubscriber::get_cdn_hosts()' );
|
||||
$hosts = array();
|
||||
|
||||
$cnames = get_rocket_cdn_cnames( $zones );
|
||||
if ( $cnames ) {
|
||||
foreach ( $cnames as $cname ) {
|
||||
$cname = rocket_add_url_protocol( $cname );
|
||||
$hosts[] = rocket_extract_url_component( $cname, PHP_URL_HOST );
|
||||
}
|
||||
}
|
||||
|
||||
return $hosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply CDN on CSS properties (background, background-image, @import, src:url (fonts))
|
||||
*
|
||||
* @since 2.6
|
||||
* @since 3.4
|
||||
*
|
||||
* @param string $buffer file content.
|
||||
* @return string modified file content
|
||||
*/
|
||||
function rocket_cdn_css_properties( $buffer ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4', '\WP_Rocket\Subscriber\CDN\CDN::rewrite_css_properties()' );
|
||||
|
||||
$zone = array(
|
||||
'all',
|
||||
'images',
|
||||
'css_and_js',
|
||||
'css',
|
||||
);
|
||||
$cnames = get_rocket_cdn_cnames( $zone );
|
||||
|
||||
/**
|
||||
* Filters the application of the CDN on CSS properties
|
||||
*
|
||||
* @since 2.6
|
||||
*
|
||||
* @param bool true to apply CDN to properties, false otherwise
|
||||
*/
|
||||
$do_rocket_cdn_css_properties = apply_filters( 'do_rocket_cdn_css_properties', true );
|
||||
|
||||
if ( ! get_rocket_option( 'cdn' ) || ! $cnames || ! $do_rocket_cdn_css_properties ) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
preg_match_all( '/url\((?![\'"]?data)([^\)]+)\)/i', $buffer, $matches );
|
||||
|
||||
if ( is_array( $matches ) ) {
|
||||
$i = 0;
|
||||
foreach ( $matches[1] as $url ) {
|
||||
$url = trim( $url, " \t\n\r\0\x0B\"'" );
|
||||
/**
|
||||
* Filters the URL of the CSS property
|
||||
*
|
||||
* @since 2.8
|
||||
*
|
||||
* @param string $url URL of the CSS property
|
||||
*/
|
||||
$url = get_rocket_cdn_url( apply_filters( 'rocket_cdn_css_properties_url', $url ), $zone );
|
||||
$property = str_replace( $matches[1][ $i ], $url, $matches[0][ $i ] );
|
||||
$buffer = str_replace( $matches[0][ $i ], $property, $buffer );
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply CDN on custom data attributes.
|
||||
*
|
||||
* @since 2.5.5
|
||||
* @deprecated 3.4
|
||||
*
|
||||
* @param string $html Original Output.
|
||||
* @return string $html Output that will be printed
|
||||
*/
|
||||
function rocket_add_cdn_on_custom_attr( $html ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
if ( preg_match( '/(data-lazy-src|data-lazyload|data-src|data-retina)=[\'"]?([^\'"\s>]+)[\'"]/i', $html, $matches ) ) {
|
||||
$html = str_replace( $matches[2], get_rocket_cdn_url( $matches[2], array( 'all', 'images' ) ), $html );
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replace URL by CDN of all thumbnails and smilies.
|
||||
*
|
||||
* @since 2.1
|
||||
* @deprecated 3.4
|
||||
*
|
||||
* @param string $url URL of the file to replace the domain with the CDN.
|
||||
* @return string modified URL
|
||||
*/
|
||||
function rocket_cdn_file( $url ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
if ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$ext = pathinfo( $url, PATHINFO_EXTENSION );
|
||||
|
||||
if ( is_admin() || 'php' === $ext ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$filter = current_filter();
|
||||
|
||||
$rejected_files = get_rocket_cdn_reject_files();
|
||||
if ( 'template_directory_uri' === $filter && ! empty( $rejected_files ) ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
switch ( $filter ) {
|
||||
case 'wp_get_attachment_url':
|
||||
case 'wp_calculate_image_srcset':
|
||||
$zone = array( 'all', 'images' );
|
||||
break;
|
||||
case 'smilies_src':
|
||||
$zone = array( 'all', 'images' );
|
||||
break;
|
||||
case 'stylesheet_uri':
|
||||
case 'wp_minify_css_url':
|
||||
case 'wp_minify_js_url':
|
||||
case 'bwp_get_minify_src':
|
||||
$zone = array( 'all', 'css_and_js', $ext );
|
||||
break;
|
||||
default:
|
||||
$zone = array( 'all', $ext );
|
||||
break;
|
||||
}
|
||||
|
||||
$cnames = get_rocket_cdn_cnames( $zone );
|
||||
if ( $cnames ) {
|
||||
$url = get_rocket_cdn_url( $url, $zone );
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace URL by CDN of images displayed using wp_get_attachment_image_src
|
||||
*
|
||||
* @since 2.9.2
|
||||
* @deprecated 3.4
|
||||
* @author Remy Perona
|
||||
* @source https://github.com/wp-media/wp-rocket/issues/271#issuecomment-269849927
|
||||
*
|
||||
* @param array $image An array containing the src, width and height of the image.
|
||||
* @return array Array with updated src URL
|
||||
*/
|
||||
function rocket_cdn_attachment_image_src( $image ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
if ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) {
|
||||
return $image;
|
||||
}
|
||||
|
||||
if ( ! (bool) $image ) {
|
||||
return $image;
|
||||
}
|
||||
|
||||
if ( is_admin() || is_preview() || is_feed() ) {
|
||||
return $image;
|
||||
}
|
||||
|
||||
$zones = array( 'all', 'images' );
|
||||
|
||||
if ( ! (bool) get_rocket_cdn_cnames( $zones ) ) {
|
||||
return $image;
|
||||
}
|
||||
|
||||
$image[0] = get_rocket_cdn_url( $image[0], $zones );
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace srcset URLs by CDN URLs for WP responsive images
|
||||
*
|
||||
* @since WP 4.4
|
||||
* @since 2.6.14
|
||||
* @deprecated 3.4
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param array $sources multidimensional array containing srcset images urls.
|
||||
* @return array $sources
|
||||
*/
|
||||
function rocket_add_cdn_on_srcset( $sources ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
if ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) {
|
||||
return $sources;
|
||||
}
|
||||
|
||||
if ( (bool) $sources ) {
|
||||
foreach ( $sources as $width => $data ) {
|
||||
$sources[ $width ]['url'] = rocket_cdn_file( $data['url'] );
|
||||
}
|
||||
}
|
||||
return $sources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace URL by CDN of all images display in a post content or a widget text.
|
||||
*
|
||||
* @since 2.1
|
||||
* @deprecated 3.4
|
||||
*
|
||||
* @param string $html HTML content to parse.
|
||||
* @return string modified HTML content
|
||||
*/
|
||||
function rocket_cdn_images( $html ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
// Don't use CDN if the image is in admin, a feed or in a post preview.
|
||||
if ( is_admin() || is_feed() || is_preview() || empty( $html ) || defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
$zone = array( 'all', 'images' );
|
||||
$cnames = get_rocket_cdn_cnames( $zone );
|
||||
|
||||
if ( $cnames ) {
|
||||
|
||||
$cnames = array_flip( $cnames );
|
||||
$wp_content_dirname = wp_parse_url( content_url(), PHP_URL_PATH );
|
||||
|
||||
$custom_media_uploads_dirname = '';
|
||||
$uploads_info = wp_upload_dir();
|
||||
|
||||
if ( ! empty( $uploads_info['baseurl'] ) ) {
|
||||
$custom_media_uploads_dirname = '|' . trailingslashit( wp_parse_url( $uploads_info['baseurl'], PHP_URL_PATH ) );
|
||||
}
|
||||
|
||||
// Get all images of the content.
|
||||
preg_match_all( '#<img([^>]+?)src=([\'"\\\]*)([^\'"\s\\\>]+)([\'"\\\]*)([^>]*)>#i', $html, $images_match );
|
||||
|
||||
foreach ( $images_match[3] as $k => $image_url ) {
|
||||
|
||||
$parse_url = get_rocket_parse_url( $image_url );
|
||||
$path = trim( $parse_url['path'] );
|
||||
$host = $parse_url['host'];
|
||||
|
||||
if ( empty( $path ) || ! preg_match( '#(' . $wp_content_dirname . $custom_media_uploads_dirname . '|wp-includes)#', $path ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( isset( $cnames[ $host ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Image path is relative, apply the host to it.
|
||||
if ( empty( $host ) ) {
|
||||
$image_url = home_url( '/' ) . ltrim( $image_url, '/' );
|
||||
$host = rocket_extract_url_component( $image_url, PHP_URL_HOST );
|
||||
}
|
||||
|
||||
// Check if the link isn't external.
|
||||
if ( rocket_extract_url_component( home_url(), PHP_URL_HOST ) !== $host ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if the URL isn't a DATA-URI.
|
||||
if ( false !== strpos( $image_url, 'data:image' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$html = str_replace(
|
||||
$images_match[0][ $k ],
|
||||
/**
|
||||
* Filter the image HTML output with the CDN link
|
||||
*
|
||||
* @since 2.5.5
|
||||
*
|
||||
* @param array $html Output that will be printed.
|
||||
*/
|
||||
apply_filters(
|
||||
'rocket_cdn_images_html',
|
||||
sprintf(
|
||||
'<img %1$s %2$s %3$s>',
|
||||
trim( $images_match[1][ $k ] ),
|
||||
'src=' . $images_match[2][ $k ] . get_rocket_cdn_url( $image_url, $zone ) . $images_match[4][ $k ],
|
||||
trim( $images_match[5][ $k ] )
|
||||
)
|
||||
),
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace URL by CDN of all inline styles containing url()
|
||||
*
|
||||
* @since 2.9
|
||||
* @deprecated 3.4
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $html HTML content of the page.
|
||||
* @return string modified HTML content
|
||||
*/
|
||||
function rocket_cdn_inline_styles( $html ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
if ( is_preview() || empty( $html ) || defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
$zone = array(
|
||||
'all',
|
||||
'images',
|
||||
);
|
||||
|
||||
$cnames = get_rocket_cdn_cnames( $zone );
|
||||
if ( $cnames ) {
|
||||
preg_match_all( '/url\((?![\'\"]?data)[\"\']?([^\)\"\']+)[\"\']?\)/i', $html, $matches );
|
||||
|
||||
if ( (bool) $matches ) {
|
||||
foreach ( $matches[1] as $k => $url ) {
|
||||
$url = str_replace( array( ' ', '\t', '\n', '\r', '\0', '\x0B', '"', "'", '"', ''' ), '', $url );
|
||||
|
||||
if ( '#' === substr( $url, 0, 1 ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$url = get_rocket_cdn_url( $url, $zone );
|
||||
$property = str_replace( $matches[1][ $k ], $url, $matches[0][ $k ] );
|
||||
$html = str_replace( $matches[0][ $k ], $property, $html );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace URL by CDN for custom files
|
||||
*
|
||||
* @since 2.9
|
||||
* @deprecated 3.4
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $html HTML content of the page.
|
||||
* @return string modified HTML content
|
||||
*/
|
||||
function rocket_cdn_custom_files( $html ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
if ( is_preview() || empty( $html ) || defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
$image_types = [
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'jpe',
|
||||
'png',
|
||||
'gif',
|
||||
'webp',
|
||||
'bmp',
|
||||
'tiff',
|
||||
];
|
||||
|
||||
$other_types = [
|
||||
'mp3',
|
||||
'ogg',
|
||||
'mp4',
|
||||
'm4v',
|
||||
'avi',
|
||||
'mov',
|
||||
'flv',
|
||||
'swf',
|
||||
'webm',
|
||||
'pdf',
|
||||
'doc',
|
||||
'docx',
|
||||
'txt',
|
||||
'zip',
|
||||
'tar',
|
||||
'bz2',
|
||||
'tgz',
|
||||
'rar',
|
||||
];
|
||||
|
||||
$zones = array_filter( array_unique( get_rocket_option( 'cdn_zone', [] ) ) );
|
||||
|
||||
if ( empty( $zones ) ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
if ( ! in_array( 'all', $zones, true ) && ! in_array( 'images', $zones, true ) ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
$cdn_zones = [];
|
||||
$file_types = [];
|
||||
|
||||
if ( in_array( 'images', $zones, true ) ) {
|
||||
$cdn_zones[] = 'images';
|
||||
$file_types = array_merge( $file_types, $image_types );
|
||||
}
|
||||
|
||||
if ( in_array( 'all', $zones, true ) ) {
|
||||
$cdn_zones[] = 'all';
|
||||
$file_types = array_merge( $file_types, $image_types, $other_types );
|
||||
}
|
||||
|
||||
$cnames = get_rocket_cdn_cnames( $cdn_zones );
|
||||
|
||||
if ( empty( $cnames ) ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the filetypes allowed for the CDN
|
||||
*
|
||||
* @since 2.9
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param array $filetypes Array of file types.
|
||||
*/
|
||||
$file_types = apply_filters( 'rocket_cdn_custom_filetypes', $file_types );
|
||||
$file_types = implode( '|', $file_types );
|
||||
|
||||
preg_match_all( '#<a[^>]+?href=[\'"]?([^"\'>]+\.(?:' . $file_types . '))[\'"]?[^>]*>#i', $html, $matches );
|
||||
|
||||
if ( ! (bool) $matches ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
foreach ( $matches[1] as $key => $url ) {
|
||||
$url = trim( $url, " \t\n\r\0\x0B\"'" );
|
||||
$url = get_rocket_cdn_url( $url, $cdn_zones );
|
||||
$src = str_replace( $matches[1][ $key ], $url, $matches[0][ $key ] );
|
||||
$html = str_replace( $matches[0][ $key ], $src, $html );
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace URL by CDN of all scripts and styles enqueues with WordPress functions
|
||||
*
|
||||
* @since 2.9 Only add protocol if $src is an absolute url
|
||||
* @since 2.1
|
||||
* @deprecated 3.4
|
||||
*
|
||||
* @param string $src URL of the file.
|
||||
* @return string modified URL
|
||||
*/
|
||||
function rocket_cdn_enqueue( $src ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
// Don't use CDN if in admin, in login page, in register page or in a post preview.
|
||||
if ( is_admin() || is_preview() || in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ), true ) || defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) {
|
||||
return $src;
|
||||
}
|
||||
|
||||
if ( rocket_extract_url_component( $src, PHP_URL_HOST ) !== '' ) {
|
||||
$src = rocket_add_url_protocol( $src );
|
||||
}
|
||||
|
||||
$zone = array( 'all', 'css_and_js' );
|
||||
|
||||
// Add only CSS zone.
|
||||
if ( 'style_loader_src' === current_filter() ) {
|
||||
$zone[] = 'css';
|
||||
}
|
||||
|
||||
// Add only JS zone.
|
||||
if ( 'script_loader_src' === current_filter() ) {
|
||||
$zone[] = 'js';
|
||||
}
|
||||
|
||||
$cnames = get_rocket_cdn_cnames( $zone );
|
||||
if ( $cnames ) {
|
||||
// Check if the path isn't empty.
|
||||
if ( trim( rocket_extract_url_component( $src, PHP_URL_PATH ), '/' ) !== '' ) {
|
||||
$src = get_rocket_cdn_url( $src, $zone );
|
||||
}
|
||||
}
|
||||
|
||||
return $src;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all files we don't allow to get in CDN.
|
||||
*
|
||||
* @since 2.5
|
||||
* @deprecated 3.4
|
||||
*
|
||||
* @return string A pipe-separated list of rejected files.
|
||||
*/
|
||||
function get_rocket_cdn_reject_files() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4', '\WP_Rocket\Subscriber\CDN\CDN::get_excluded_files()' );
|
||||
|
||||
$files = get_rocket_option( 'cdn_reject_files', [] );
|
||||
|
||||
/**
|
||||
* Filter the rejected files.
|
||||
*
|
||||
* @since 2.5
|
||||
*
|
||||
* @param array $files List of rejected files.
|
||||
*/
|
||||
$files = (array) apply_filters( 'rocket_cdn_reject_files', $files );
|
||||
$files = array_filter( $files );
|
||||
$files = array_flip( array_flip( $files ) );
|
||||
|
||||
return implode( '|', $files );
|
||||
}
|
||||
|
||||
/**
|
||||
* Conflict with Envira Gallery: changes the URL argument if using WP Rocket CDN and Envira
|
||||
*
|
||||
* @since 2.6.5
|
||||
* @since 3.4
|
||||
*
|
||||
* @param array $args An array of arguments.
|
||||
* @return array Updated array of arguments
|
||||
*/
|
||||
function rocket_cdn_resize_image_args_on_envira_gallery( $args ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
if ( ! isset( $args['url'] ) || (int) get_rocket_option( 'cdn' ) === 0 ) {
|
||||
return $args;
|
||||
}
|
||||
|
||||
$cnames_host = array_flip( get_rocket_cnames_host() );
|
||||
$url_host = rocket_extract_url_component( $args['url'], PHP_URL_HOST );
|
||||
$home_host = rocket_extract_url_component( home_url(), PHP_URL_HOST );
|
||||
|
||||
if ( isset( $cnames_host[ $url_host ] ) ) {
|
||||
$args['url'] = str_replace( $url_host, $home_host , $args['url'] );
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conflict with Envira Gallery: changes the resized URL if using WP Rocket CDN and Envira
|
||||
*
|
||||
* @since 2.6.5
|
||||
* @since 3.4
|
||||
*
|
||||
* @param string $url Resized image URL.
|
||||
* @return string Resized image URL using the CDN URL
|
||||
*/
|
||||
function rocket_cdn_resized_url_on_envira_gallery( $url ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
if ( (int) get_rocket_option( 'cdn' ) === 0 ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$url = get_rocket_cdn_url( $url, array( 'all', 'images' ) );
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply CDN settings to Beaver Builder parallax.
|
||||
*
|
||||
* @since 3.2.1
|
||||
* @deprecated 3.4
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param array $attrs HTML attributes.
|
||||
* @return array
|
||||
*/
|
||||
function rocket_beaver_builder_add_cdn_to_parallax( $attrs ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
|
||||
if ( ! empty( $attrs['data-parallax-image'] ) ) {
|
||||
$attrs['data-parallax-image'] = get_rocket_cdn_url( $attrs['data-parallax-image'], [ 'all', 'images' ] );
|
||||
}
|
||||
|
||||
return $attrs;
|
||||
}
|
||||
|
||||
if ( class_exists( 'WR2X_Admin' ) ) :
|
||||
/**
|
||||
* Conflict with WP Retina x2: Apply CDN on srcset attribute.
|
||||
*
|
||||
* @since 2.9.1 Use global $wr2x_admin
|
||||
* @since 2.5.5
|
||||
* @deprecated 3.4
|
||||
*
|
||||
* @param string $url URL of the image.
|
||||
* @return string Updated URL with CDN
|
||||
*/
|
||||
function rocket_cdn_on_images_from_wp_retina_x2( $url ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
|
||||
global $wr2x_admin;
|
||||
|
||||
if ( ! method_exists( $wr2x_admin, 'is_pro' ) || ! $wr2x_admin->is_pro() ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$cdn_domain = get_option( 'wr2x_cdn_domain' );
|
||||
|
||||
if ( ! empty( $cdn_domain ) ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
return get_rocket_cdn_url( $url, array( 'all', 'images' ) );
|
||||
}
|
||||
endif;
|
||||
|
||||
/**
|
||||
* Conflict with Avada theme and WP Rocket CDN
|
||||
*
|
||||
* @since 2.6.1
|
||||
* @deprecated 3.4
|
||||
*
|
||||
* @param array $vars An array of variables.
|
||||
* @param string $handle Name of the avada resource.
|
||||
* @return array updated array of variables
|
||||
*/
|
||||
function rocket_fix_cdn_for_avada_theme( $vars, $handle ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
if ( 'avada-dynamic' === $handle && get_rocket_option( 'cdn' ) ) {
|
||||
$src = get_rocket_cdn_url( get_template_directory_uri() . '/assets/less/theme/dynamic.less' );
|
||||
$vars['template-directory'] = sprintf( '~"%s"', dirname( dirname( dirname( dirname( $src ) ) ) ) );
|
||||
$vars['lessurl'] = sprintf( '~"%s"', dirname( $src ) );
|
||||
}
|
||||
return $vars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conflict with Aqua Resizer & IrishMiss Framework: Apply CDN without blank src!!
|
||||
*
|
||||
* @since 2.5.8 Add compatibility with IrishMiss Framework
|
||||
* @since 2.5.5
|
||||
* @deprecated 3.4
|
||||
*/
|
||||
function rocket_cdn_on_aqua_resizer() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
|
||||
if ( function_exists( 'aq_resize' ) || function_exists( 'miss_display_image' ) ) {
|
||||
remove_filter( 'wp_get_attachment_url' , 'rocket_cdn_file', PHP_INT_MAX );
|
||||
add_filter( 'rocket_lazyload_html', 'rocket_add_cdn_on_custom_attr' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Conflict with Revolution Slider & Master Slider: Apply CDN on data-lazyload|data-src attribute.
|
||||
*
|
||||
* @since 2.5.5
|
||||
* @deprecated 3.4
|
||||
*/
|
||||
function rocket_cdn_on_sliders_with_lazyload() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.4' );
|
||||
|
||||
if ( class_exists( 'RevSliderFront' ) || class_exists( 'Master_Slider' ) ) {
|
||||
add_filter( 'rocket_cdn_images_html', 'rocket_add_cdn_on_custom_attr' );
|
||||
}
|
||||
}
|
||||
|
911
wp-content/plugins/wp-rocket/inc/deprecated/3.5.php
Normal file
911
wp-content/plugins/wp-rocket/inc/deprecated/3.5.php
Normal file
@@ -0,0 +1,911 @@
|
||||
<?php
|
||||
// phpcs:ignoreFile
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class aliases.
|
||||
*/
|
||||
class_alias( '\WP_Rocket\Engine\Admin\Settings\Page', '\WP_Rocket\Admin\Settings\Page' );
|
||||
class_alias( '\WP_Rocket\Engine\Admin\Settings\Render', '\WP_Rocket\Admin\Settings\Render' );
|
||||
class_alias( '\WP_Rocket\Engine\Admin\Settings\Settings', '\WP_Rocket\Admin\Settings\Settings' );
|
||||
class_alias( '\WP_Rocket\Engine\Admin\Settings\ServiceProvider', '\WP_Rocket\ServiceProvider\Settings' );
|
||||
class_alias( '\WP_Rocket\Engine\Admin\Settings\Subscriber', '\WP_Rocket\Subscriber\Admin\Settings\Page_Subscriber' );
|
||||
class_alias( '\WP_Rocket\Engine\Preload\AbstractPreload', '\WP_Rocket\Preload\Abstract_Preload' );
|
||||
class_alias( '\WP_Rocket\Engine\Preload\AbstractProcess', '\WP_Rocket\Preload\Process' );
|
||||
class_alias( '\WP_Rocket\Engine\Preload\FullProcess', '\WP_Rocket\Preload\Full_Process' );
|
||||
class_alias( '\WP_Rocket\Engine\Preload\Homepage', '\WP_Rocket\Preload\Homepage' );
|
||||
class_alias( '\WP_Rocket\Engine\Preload\PartialPreloadSubscriber', '\WP_Rocket\Subscriber\Preload\Partial_Preload_Subscriber' );
|
||||
class_alias( '\WP_Rocket\Engine\Preload\PartialProcess', '\WP_Rocket\Preload\Partial_Process' );
|
||||
class_alias( '\WP_Rocket\Engine\Preload\PreloadSubscriber', '\WP_Rocket\Subscriber\Preload\Preload_Subscriber' );
|
||||
class_alias( '\WP_Rocket\Engine\Preload\ServiceProvider', '\WP_Rocket\ServiceProvider\Preload_Subscribers' );
|
||||
class_alias( '\WP_Rocket\Engine\Preload\Sitemap', '\WP_Rocket\Preload\Sitemap' );
|
||||
class_alias( '\WP_Rocket\Engine\Preload\SitemapPreloadSubscriber', '\WP_Rocket\Subscriber\Preload\Sitemap_Preload_Subscriber' );
|
||||
class_alias( '\WP_Rocket\Engine\Optimization\GoogleFonts\Combine', '\WP_Rocket\Optimization\CSS\Combine_Google_Fonts' );
|
||||
class_alias( '\WP_Rocket\Engine\Optimization\GoogleFonts\Subscriber', '\WP_Rocket\Subscriber\Optimization\Combine_Google_Fonts_Subscriber' );
|
||||
|
||||
//RocketCDN Start
|
||||
class_alias('\WP_Rocket\Engine\CDN\RocketCDN\AdminPageSubscriber', '\WP_Rocket\Subscriber\CDN\RocketCDN\AdminPageSubscriber');
|
||||
class_alias('\WP_Rocket\Engine\CDN\RocketCDN\APIClient', '\WP_Rocket\CDN\RocketCDN\APIClient');
|
||||
class_alias('\WP_Rocket\Engine\CDN\RocketCDN\CDNOptionsManager', '\WP_Rocket\CDN\RocketCDN\CDNOptionsManager');
|
||||
class_alias('\WP_Rocket\Engine\CDN\RocketCDN\DataManagerSubscriber', '\WP_Rocket\Subscriber\CDN\RocketCDN\DataManagerSubscriber');
|
||||
class_alias('\WP_Rocket\Engine\CDN\RocketCDN\NoticesSubscriber', '\WP_Rocket\Subscriber\CDN\RocketCDN\NoticesSubscriber');
|
||||
class_alias('\WP_Rocket\Engine\CDN\RocketCDN\RESTSubscriber', '\WP_Rocket\Subscriber\CDN\RocketCDN\RESTSubscriber');
|
||||
class_alias('\WP_Rocket\Engine\CDN\RocketCDN\ServiceProvider', '\WP_Rocket\ServiceProvider\RocketCDN');
|
||||
//RocketCDN End
|
||||
|
||||
/**
|
||||
* Removes Minification, DNS Prefetch, LazyLoad, Defer JS when on an AMP version of a post with the AMP for WordPress plugin from Auttomatic
|
||||
*
|
||||
* @since 2.8.10 Compatibility with wp_resource_hints in WP 4.6
|
||||
* @since 2.7
|
||||
* @deprecated 3.5.2
|
||||
*
|
||||
* @author Remy Perona
|
||||
*/
|
||||
function rocket_disable_options_on_amp() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5.2', '\WP_Rocket\ThirdParty\Plugins\Optimization\AMP::disable_options_on_amp()' );
|
||||
global $wp_filter;
|
||||
|
||||
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
|
||||
remove_filter( 'wp_resource_hints', 'rocket_dns_prefetch', 10, 2 );
|
||||
add_filter( 'do_rocket_lazyload', '__return_false' );
|
||||
unset( $wp_filter['rocket_buffer'] );
|
||||
|
||||
// this filter is documented in inc/front/protocol.php.
|
||||
$do_rocket_protocol_rewrite = apply_filters( 'do_rocket_protocol_rewrite', false ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
|
||||
|
||||
if ( ( get_rocket_option( 'do_cloudflare', 0 ) && get_rocket_option( 'cloudflare_protocol_rewrite', 0 ) || $do_rocket_protocol_rewrite ) ) {
|
||||
remove_filter( 'rocket_buffer', 'rocket_protocol_rewrite', PHP_INT_MAX );
|
||||
remove_filter( 'wp_calculate_image_srcset', 'rocket_protocol_rewrite_srcset', PHP_INT_MAX );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Cloudflare input data
|
||||
*
|
||||
* @since 3.4.1
|
||||
* @deprecated 3.5
|
||||
* @author Soponar Cristina
|
||||
*
|
||||
* @param string $cf_email - Cloudflare email.
|
||||
* @param string $cf_api_key - Cloudflare API key.
|
||||
* @param string $cf_zone_id - Cloudflare zone ID.
|
||||
* @param bool $basic_validation - Bypass Cloudflare API user and zone validation.
|
||||
* @return Object - true if credentials are ok, WP_Error otherwise.
|
||||
*/
|
||||
function rocket_is_api_keys_valid_cloudflare( $cf_email, $cf_api_key, $cf_zone_id, $basic_validation = true ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::is_api_keys_valid()' );
|
||||
if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) {
|
||||
return new WP_Error( 'curl_disabled', __( 'Curl is disabled on your server. Please ask your host to enable it. This is required for the Cloudflare Add-on to work correctly.', 'rocket' ) );
|
||||
}
|
||||
|
||||
if ( ! isset( $cf_email, $cf_api_key ) || empty( $cf_email ) || empty( $cf_api_key ) ) {
|
||||
return new WP_Error(
|
||||
'cloudflare_credentials_empty',
|
||||
sprintf(
|
||||
/* translators: %1$s = opening link; %2$s = closing link */
|
||||
__( 'Cloudflare email, API key and Zone ID are not set. Read the %1$sdocumentation%2$s for further guidance.', 'rocket' ),
|
||||
// translators: Documentation exists in EN, FR; use localized URL if applicable.
|
||||
'<a href="' . esc_url( __( 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on', 'rocket' ) ) . '" rel="noopener noreferrer" target="_blank">',
|
||||
'</a>'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! isset( $cf_zone_id ) || empty( $cf_zone_id ) ) {
|
||||
$msg = __( 'Missing Cloudflare Zone ID.', 'rocket' );
|
||||
|
||||
$msg .= ' ' . sprintf(
|
||||
/* translators: %1$s = opening link; %2$s = closing link */
|
||||
__( 'Read the %1$sdocumentation%2$s for further guidance.', 'rocket' ),
|
||||
// translators: Documentation exists in EN, FR; use localized URL if applicable.
|
||||
'<a href="' . esc_url( __( 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on', 'rocket' ) ) . '" rel="noopener noreferrer" target="_blank">',
|
||||
'</a>'
|
||||
);
|
||||
|
||||
return new WP_Error( 'cloudflare_no_zone_id', $msg );
|
||||
}
|
||||
|
||||
if ( $basic_validation ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
$cf_api_instance = new Cloudflare\Api( $cf_email, $cf_api_key );
|
||||
$cf_zone = $cf_api_instance->get( 'zones/' . $cf_zone_id );
|
||||
|
||||
if ( ! isset( $cf_zone->success ) || empty( $cf_zone->success ) ) {
|
||||
foreach ( $cf_zone->errors as $error ) {
|
||||
if ( 6003 === $error->code ) {
|
||||
$msg = __( 'Incorrect Cloudflare email address or API key.', 'rocket' );
|
||||
|
||||
$msg .= ' ' . sprintf(
|
||||
/* translators: %1$s = opening link; %2$s = closing link */
|
||||
__( 'Read the %1$sdocumentation%2$s for further guidance.', 'rocket' ),
|
||||
// translators: Documentation exists in EN, FR; use localized URL if applicable.
|
||||
'<a href="' . esc_url( __( 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on', 'rocket' ) ) . '" rel="noopener noreferrer" target="_blank">',
|
||||
'</a>'
|
||||
);
|
||||
|
||||
return new WP_Error( 'cloudflare_invalid_auth', $msg );
|
||||
}
|
||||
}
|
||||
$msg = __( 'Incorrect Cloudflare Zone ID.', 'rocket' );
|
||||
|
||||
$msg .= ' ' . sprintf(
|
||||
/* translators: %1$s = opening link; %2$s = closing link */
|
||||
__( 'Read the %1$sdocumentation%2$s for further guidance.', 'rocket' ),
|
||||
// translators: Documentation exists in EN, FR; use localized URL if applicable.
|
||||
'<a href="' . esc_url( __( 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on', 'rocket' ) ) . '" rel="noopener noreferrer" target="_blank">',
|
||||
'</a>'
|
||||
);
|
||||
return new WP_Error( 'cloudflare_invalid_auth', $msg );
|
||||
}
|
||||
|
||||
if ( true === $cf_zone->success ) {
|
||||
$zone_found = false;
|
||||
$site_url = get_site_url();
|
||||
|
||||
if ( function_exists( 'domain_mapping_siteurl' ) ) {
|
||||
$site_url = domain_mapping_siteurl( $site_url );
|
||||
}
|
||||
|
||||
if ( ! empty( $cf_zone->result ) ) {
|
||||
$parsed_url = wp_parse_url( $site_url );
|
||||
if ( false !== strpos( strtolower( $parsed_url['host'] ), $cf_zone->result->name ) ) {
|
||||
$zone_found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $zone_found ) {
|
||||
$msg = __( 'It looks like your domain is not set up on Cloudflare.', 'rocket' );
|
||||
|
||||
$msg .= ' ' . sprintf(
|
||||
/* translators: %1$s = opening link; %2$s = closing link */
|
||||
__( 'Read the %1$sdocumentation%2$s for further guidance.', 'rocket' ),
|
||||
// translators: Documentation exists in EN, FR; use localized URL if applicable.
|
||||
'<a href="' . esc_url( __( 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on', 'rocket' ) ) . '" rel="noopener noreferrer" target="_blank">',
|
||||
'</a>'
|
||||
);
|
||||
|
||||
return new WP_Error( 'cloudflare_wrong_zone_id', $msg );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
$msg = __( 'Incorrect Cloudflare email address or API key.', 'rocket' );
|
||||
|
||||
$msg .= ' ' . sprintf(
|
||||
/* translators: %1$s = opening link; %2$s = closing link */
|
||||
__( 'Read the %1$sdocumentation%2$s for further guidance.', 'rocket' ),
|
||||
// translators: Documentation exists in EN, FR; use localized URL if applicable.
|
||||
'<a href="' . esc_url( __( 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on', 'rocket' ) ) . '" rel="noopener noreferrer" target="_blank">',
|
||||
'</a>'
|
||||
);
|
||||
|
||||
return new WP_Error( 'cloudflare_invalid_auth', $msg );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Cloudflare\Api instance
|
||||
*
|
||||
* @since 2.8.21
|
||||
* @deprecated 3.5
|
||||
* @author Soponar Cristina
|
||||
*
|
||||
* @return Object Cloudflare\Api instance if crendentials are set, WP_Error otherwise
|
||||
*/
|
||||
function get_rocket_cloudflare_api_instance() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5' );
|
||||
if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) {
|
||||
return new WP_Error( 'curl_disabled', __( 'Curl is disabled on your server. Please ask your host to enable it. This is required for the Cloudflare Add-on to work correctly.', 'rocket' ) );
|
||||
}
|
||||
|
||||
$cf_email = get_rocket_option( 'cloudflare_email', null );
|
||||
$cf_api_key = ( defined( 'WP_ROCKET_CF_API_KEY' ) ) ? WP_ROCKET_CF_API_KEY : get_rocket_option( 'cloudflare_api_key', null );
|
||||
|
||||
if ( ! isset( $cf_email, $cf_api_key ) ) {
|
||||
return new WP_Error(
|
||||
'cloudflare_credentials_empty',
|
||||
sprintf(
|
||||
/* translators: %1$s = opening link; %2$s = closing link */
|
||||
__( 'Cloudflare email and API key are not set. Read the %1$sdocumentation%2$s for further guidance.', 'rocket' ),
|
||||
// translators: Documentation exists in EN, FR; use localized URL if applicable.
|
||||
'<a href="' . esc_url( __( 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on', 'rocket' ) ) . '" rel="noopener noreferrer" target="_blank">',
|
||||
'</a>'
|
||||
)
|
||||
);
|
||||
}
|
||||
return new Cloudflare\Api( $cf_email, $cf_api_key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Cloudflare\Api instance & the zone_id corresponding to the domain
|
||||
*
|
||||
* @since 2.8.21 Get the zone ID from the options
|
||||
* @since 2.8.18 Add try/catch to prevent fatal error Uncaugh Exception
|
||||
* @since 2.8.16 Update to Cloudflare API v4
|
||||
* @since 2.5
|
||||
* @deprecated 3.5
|
||||
*
|
||||
* @return Object Cloudflare instance & zone_id if credentials are correct, WP_Error otherwise
|
||||
*/
|
||||
function get_rocket_cloudflare_instance() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::get_instance()' );
|
||||
$cf_email = get_rocket_option( 'cloudflare_email', null );
|
||||
$cf_api_key = ( defined( 'WP_ROCKET_CF_API_KEY' ) ) ? WP_ROCKET_CF_API_KEY : get_rocket_option( 'cloudflare_api_key', null );
|
||||
$cf_zone_id = get_rocket_option( 'cloudflare_zone_id', null );
|
||||
$is_api_keys_valid_cf = rocket_is_api_keys_valid_cloudflare( $cf_email, $cf_api_key, $cf_zone_id, true );
|
||||
|
||||
if ( is_wp_error( $is_api_keys_valid_cf ) ) {
|
||||
return $is_api_keys_valid_cf;
|
||||
}
|
||||
|
||||
$cf_api_instance = get_rocket_cloudflare_api_instance();
|
||||
|
||||
$cf_instance = (object) [
|
||||
'auth' => $cf_api_instance,
|
||||
'zone_id' => $cf_zone_id,
|
||||
];
|
||||
|
||||
return $cf_instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the connection with Cloudflare
|
||||
*
|
||||
* @since 2.9
|
||||
* @deprecated 3.5
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @throws Exception If the connection to Cloudflare failed.
|
||||
* @return Object True if connection is successful, WP_Error otherwise
|
||||
*/
|
||||
function rocket_cloudflare_valid_auth() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5' );
|
||||
$cf_api_instance = get_rocket_cloudflare_api_instance();
|
||||
if ( is_wp_error( $cf_api_instance ) ) {
|
||||
return $cf_api_instance;
|
||||
}
|
||||
|
||||
try {
|
||||
$cf_zone_instance = new Cloudflare\Zone( $cf_api_instance );
|
||||
$cf_zones = $cf_zone_instance->zones();
|
||||
|
||||
if ( ! isset( $cf_zones->success ) || empty( $cf_zones->success ) ) {
|
||||
throw new Exception( __( 'Connection to Cloudflare failed', 'rocket' ) );
|
||||
}
|
||||
|
||||
if ( true === $cf_zones->success ) {
|
||||
return true;
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
return new WP_Error( 'cloudflare_invalid_auth', $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all the current Cloudflare settings for a given domain.
|
||||
*
|
||||
* @since 2.8.16 Update to Cloudflare API v4
|
||||
* @since 2.5
|
||||
* @deprecated 3.5
|
||||
*
|
||||
* @return mixed bool|Array Array of Cloudflare settings, false if any error connection to Cloudflare
|
||||
*/
|
||||
function get_rocket_cloudflare_settings() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::get_settings()' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the Cloudflare Development mode.
|
||||
*
|
||||
* @since 2.9 Now returns a value
|
||||
* @since 2.8.16 Update to Cloudflare API v4
|
||||
* @since 2.5
|
||||
* @deprecated 3.5
|
||||
*
|
||||
* @param string $mode Value for Cloudflare development mode.
|
||||
* @throws Exception If any error occurs when doing the API request.
|
||||
* @return mixed Object|String Mode value if the update is successful, WP_Error otherwise
|
||||
*/
|
||||
function set_rocket_cloudflare_devmode( $mode ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::set_devmode()' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the Cloudflare Caching level.
|
||||
*
|
||||
* @since 2.9 Now returns a value
|
||||
* @since 2.8.16 Update to Cloudflare API v4
|
||||
* @since 2.5
|
||||
* @deprecated 3.5
|
||||
*
|
||||
* @param string $mode Value for Cloudflare caching level.
|
||||
* @throws Exception If any error occurs when doing the API request.
|
||||
* @return mixed Object|String Mode value if the update is successful, WP_Error otherwise
|
||||
*/
|
||||
function set_rocket_cloudflare_cache_level( $mode ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::set_cache_level()' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Cloudflare Minification.
|
||||
*
|
||||
* @since 2.9 Now returns a value
|
||||
* @since 2.8.16 Update to Cloudflare API v4
|
||||
* @since 2.5
|
||||
* @deprecated 3.5
|
||||
*
|
||||
* @param string $mode Value for Cloudflare minification.
|
||||
* @throws Exception If any error occurs when doing the API request.
|
||||
* @return mixed Object|String Mode value if the update is successful, WP_Error otherwise
|
||||
*/
|
||||
function set_rocket_cloudflare_minify( $mode ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::set_minify()' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the Cloudflare Rocket Loader.
|
||||
*
|
||||
* @since 2.9 Now returns value
|
||||
* @since 2.8.16 Update to Cloudflare API v4
|
||||
* @since 2.5
|
||||
* @deprecated 3.5
|
||||
*
|
||||
* @param string $mode Value for Cloudflare Rocket Loader.
|
||||
* @throws Exception If any error occurs when doing the API request.
|
||||
* @return mixed Object|String Mode value if the update is successful, WP_Error otherwise
|
||||
*/
|
||||
function set_rocket_cloudflare_rocket_loader( $mode ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::set_rocket_loader()' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the Browser Cache TTL in Cloudflare.
|
||||
*
|
||||
* @since 2.9 Now returns value
|
||||
* @since 2.8.16
|
||||
* @deprecated 3.5
|
||||
*
|
||||
* @param string $mode Value for Cloudflare browser cache TTL.
|
||||
* @throws Exception If any error occurs when doing the API request.
|
||||
* @return mixed Object|String Mode value if the update is successful, WP_Error otherwise
|
||||
*/
|
||||
function set_rocket_cloudflare_browser_cache_ttl( $mode ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::set_browser_cache_ttl()' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Purge Cloudflare cache.
|
||||
*
|
||||
* @since 2.9 Now returns value
|
||||
* @since 2.8.16 Update to Cloudflare API v4
|
||||
* @since 2.5
|
||||
* @deprecated 3.5
|
||||
*
|
||||
* @throws Exception If any error occurs when doing the API request.
|
||||
* @return mixed Object|bool true if the purge is successful, WP_Error otherwise
|
||||
*/
|
||||
function rocket_purge_cloudflare() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::purge_cloudflare()' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Cloudflare IPs.
|
||||
*
|
||||
* @since 2.8.21 Save IPs in a transient to prevent calling the API everytime
|
||||
* @since 2.8.16
|
||||
* @deprecated 3.5
|
||||
*
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @throws Exception If any error occurs when doing the API request.
|
||||
* @return Object Result of API request if successful, WP_Error otherwise
|
||||
*/
|
||||
function rocket_get_cloudflare_ips() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::get_cloudflare_ips()' );
|
||||
$cf_instance = get_rocket_cloudflare_api_instance();
|
||||
if ( is_wp_error( $cf_instance ) ) {
|
||||
return $cf_instance;
|
||||
}
|
||||
|
||||
$cf_ips = get_transient( 'rocket_cloudflare_ips' );
|
||||
if ( false === $cf_ips ) {
|
||||
try {
|
||||
$cf_ips_instance = new Cloudflare\IPs( $cf_instance );
|
||||
$cf_ips = $cf_ips_instance->ips();
|
||||
|
||||
if ( ! isset( $cf_ips->success ) || ! $cf_ips->success ) {
|
||||
throw new Exception( 'Error connecting to Cloudflare' );
|
||||
}
|
||||
|
||||
set_transient( 'rocket_cloudflare_ips', $cf_ips, 2 * WEEK_IN_SECONDS );
|
||||
} catch ( Exception $e ) {
|
||||
$cf_ips = (object) [
|
||||
'success' => true,
|
||||
'result' => (object) [],
|
||||
];
|
||||
|
||||
$cf_ips->result->ipv4_cidrs = [
|
||||
'103.21.244.0/22',
|
||||
'103.22.200.0/22',
|
||||
'103.31.4.0/22',
|
||||
'104.16.0.0/12',
|
||||
'108.162.192.0/18',
|
||||
'131.0.72.0/22',
|
||||
'141.101.64.0/18',
|
||||
'162.158.0.0/15',
|
||||
'172.64.0.0/13',
|
||||
'173.245.48.0/20',
|
||||
'188.114.96.0/20',
|
||||
'190.93.240.0/20',
|
||||
'197.234.240.0/22',
|
||||
'198.41.128.0/17',
|
||||
];
|
||||
|
||||
$cf_ips->result->ipv6_cidrs = [
|
||||
'2400:cb00::/32',
|
||||
'2405:8100::/32',
|
||||
'2405:b500::/32',
|
||||
'2606:4700::/32',
|
||||
'2803:f800::/32',
|
||||
'2c0f:f248::/32',
|
||||
'2a06:98c0::/29',
|
||||
];
|
||||
|
||||
set_transient( 'rocket_cloudflare_ips', $cf_ips, 2 * WEEK_IN_SECONDS );
|
||||
return $cf_ips;
|
||||
}
|
||||
}
|
||||
|
||||
return $cf_ips;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Real IP from CloudFlare
|
||||
*
|
||||
* @since 2.8.16 Uses CloudFlare API v4 to get CloudFlare IPs
|
||||
* @since 2.5.4
|
||||
*
|
||||
* @deprecated 3.5
|
||||
*
|
||||
* @source cloudflare.php - https://wordpress.org/plugins/cloudflare/
|
||||
*/
|
||||
function rocket_set_real_ip_cloudflare() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::set_real_ip()' );
|
||||
global $is_cf;
|
||||
|
||||
$is_cf = ( isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) ? true : false;
|
||||
|
||||
if ( ! $is_cf ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// only run this logic if the REMOTE_ADDR is populated, to avoid causing notices in CLI mode.
|
||||
if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
|
||||
$cf_ips_values = rocket_get_cloudflare_ips();
|
||||
|
||||
if ( is_wp_error( $cf_ips_values ) || ! isset( $cf_ips_values->success ) || ! $cf_ips_values->success ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( strpos( $_SERVER['REMOTE_ADDR'], ':' ) === false ) {
|
||||
$cf_ip_ranges = $cf_ips_values->result->ipv4_cidrs;
|
||||
|
||||
// IPV4: Update the REMOTE_ADDR value if the current REMOTE_ADDR value is in the specified range.
|
||||
foreach ( $cf_ip_ranges as $range ) {
|
||||
if ( rocket_ipv4_in_range( $_SERVER['REMOTE_ADDR'], $range ) ) {
|
||||
if ( $_SERVER['HTTP_CF_CONNECTING_IP'] ) {
|
||||
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$cf_ip_ranges = $cf_ips_values->result->ipv6_cidrs;
|
||||
|
||||
$ipv6 = get_rocket_ipv6_full( $_SERVER['REMOTE_ADDR'] );
|
||||
foreach ( $cf_ip_ranges as $range ) {
|
||||
if ( rocket_ipv6_in_range( $ipv6, $range ) ) {
|
||||
if ( $_SERVER['HTTP_CF_CONNECTING_IP'] ) {
|
||||
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Let people know that the CF WP plugin is turned on.
|
||||
if ( ! headers_sent() ) {
|
||||
header( 'X-CF-Powered-By: WP Rocket ' . WP_ROCKET_VERSION );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This notice is displayed after purging the CloudFlare cache
|
||||
*
|
||||
* @since 2.9
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @deprecated 3.5
|
||||
*
|
||||
*/
|
||||
function rocket_cloudflare_purge_result() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::maybe_print_notice()' );
|
||||
global $current_user;
|
||||
if ( ! current_user_can( 'rocket_purge_cloudflare_cache' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notice = get_transient( $current_user->ID . '_cloudflare_purge_result' );
|
||||
if ( ! $notice ) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete_transient( $current_user->ID . '_cloudflare_purge_result' );
|
||||
|
||||
rocket_notice_html( [
|
||||
'status' => $notice['result'],
|
||||
'message' => $notice['message'],
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge CloudFlare cache
|
||||
*
|
||||
* @since 2.5
|
||||
*
|
||||
* @deprecated 3.5
|
||||
*
|
||||
*/
|
||||
function do_admin_post_rocket_purge_cloudflare() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::do_purge_cloudflare()' );
|
||||
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'rocket_purge_cloudflare' ) ) {
|
||||
wp_nonce_ays( '' );
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'rocket_purge_cloudflare_cache' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Purge CloudFlare.
|
||||
$cf_purge = rocket_purge_cloudflare();
|
||||
|
||||
if ( is_wp_error( $cf_purge ) ) {
|
||||
$cf_purge_result = [
|
||||
'result' => 'error',
|
||||
// translators: %s = CloudFare API return message.
|
||||
'message' => sprintf( __( '<strong>WP Rocket:</strong> %s', 'rocket' ), $cf_purge->get_error_message() ),
|
||||
];
|
||||
} else {
|
||||
$cf_purge_result = [
|
||||
'result' => 'success',
|
||||
'message' => __( '<strong>WP Rocket:</strong> Cloudflare cache successfully purged.', 'rocket' ),
|
||||
];
|
||||
}
|
||||
|
||||
set_transient( get_current_user_id() . '_cloudflare_purge_result', $cf_purge_result );
|
||||
|
||||
wp_safe_redirect( esc_url_raw( wp_get_referer() ) );
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* This notice is displayed after modifying the CloudFlare settings
|
||||
*
|
||||
* @since 2.9
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @deprecated 3.5
|
||||
*/
|
||||
function rocket_cloudflare_update_settings() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', '\WP_Rocket\Subscriber\Tools\Cloudflare_Subscriber::maybe_print_update_settings_notice()' );
|
||||
global $current_user;
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ( ! current_user_can( 'rocket_manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'settings_page_wprocket' !== $screen->id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notices = get_transient( $current_user->ID . '_cloudflare_update_settings' );
|
||||
if ( $notices ) {
|
||||
$errors = '';
|
||||
$success = '';
|
||||
delete_transient( $current_user->ID . '_cloudflare_update_settings' );
|
||||
foreach ( $notices as $notice ) {
|
||||
if ( 'error' === $notice['result'] ) {
|
||||
$errors .= $notice['message'] . '<br>';
|
||||
} elseif ( 'success' === $notice['result'] ) {
|
||||
$success .= $notice['message'] . '<br>';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $success ) ) {
|
||||
rocket_notice_html( [
|
||||
'message' => $success,
|
||||
] );
|
||||
}
|
||||
|
||||
if ( ! empty( $errors ) ) {
|
||||
rocket_notice_html( [
|
||||
'status' => 'error',
|
||||
'message' => $success,
|
||||
] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge all the domain
|
||||
*
|
||||
* @since 2.6.8
|
||||
* @deprecated 3.5
|
||||
*
|
||||
* @param string $root The path of home cache file.
|
||||
* @param string $lang The current lang to purge.
|
||||
* @param string $url The home url.
|
||||
*/
|
||||
function rocket_varnish_clean_domain( $root, $lang, $url ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', 'WP_Rocket\Subscriber\Addons\Varnish\VarnishSubscriber::clean_domain()' );
|
||||
rocket_varnish_http_purge( trailingslashit( $url ) . '?vregex' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge a specific page
|
||||
*
|
||||
* @since 2.6.8
|
||||
* @deprecated 3.5
|
||||
*
|
||||
* @param string $url The url to purge.
|
||||
*/
|
||||
function rocket_varnish_clean_file( $url ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', 'WP_Rocket\Subscriber\Addons\Varnish\VarnishSubscriber::clean_file()' );
|
||||
rocket_varnish_http_purge( trailingslashit( $url ) . '?vregex' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge the homepage and its pagination
|
||||
*
|
||||
* @since 2.6.8
|
||||
* @deprecated 3.5
|
||||
*
|
||||
* @param string $root The path of home cache file.
|
||||
* @param string $lang The current lang to purge.
|
||||
*/
|
||||
function rocket_varnish_clean_home( $root, $lang ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', 'WP_Rocket\Subscriber\Addons\Varnish\VarnishSubscriber::clean_home()' );
|
||||
$home_url = trailingslashit( get_rocket_i18n_home_url( $lang ) );
|
||||
$home_pagination_url = $home_url . trailingslashit( $GLOBALS['wp_rewrite']->pagination_base ) . '?vregex';
|
||||
|
||||
rocket_varnish_http_purge( $home_url );
|
||||
rocket_varnish_http_purge( $home_pagination_url );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Varnish IP to localhost if Cloudflare is active
|
||||
*
|
||||
* @since 3.3.5
|
||||
* @deprecated 3.5
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function rocket_varnish_proxy_host() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', 'WP_Rocket\Subscriber\Addons\Cloudflare\CloudflareSubscriber::set_varnish_localhost()' );
|
||||
return 'localhost';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Host header to the website domain if Cloudflare is active
|
||||
*
|
||||
* @since 3.3.5
|
||||
* @deprecated 3.5
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function rocket_varnish_proxy_request_host() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', 'WP_Rocket\Subscriber\Addons\Cloudflare\CloudflareSubscriber::set_varnish_purge_request_host()' );
|
||||
return wp_parse_url( home_url(), PHP_URL_HOST );
|
||||
}
|
||||
|
||||
/**
|
||||
* Send data to Varnish
|
||||
*
|
||||
* @since 2.6.8
|
||||
* @deprecated 3.5
|
||||
*
|
||||
* @param string $url The URL to purge.
|
||||
* @return void
|
||||
*/
|
||||
function rocket_varnish_http_purge( $url ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5', 'WP_Rocket\Addons\Varnish\Varnish::purge()' );
|
||||
$parse_url = get_rocket_parse_url( $url );
|
||||
|
||||
$varnish_x_purgemethod = 'default';
|
||||
$regex = '';
|
||||
|
||||
if ( 'vregex' === $parse_url['query'] ) {
|
||||
$varnish_x_purgemethod = 'regex';
|
||||
$regex = '.*';
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the Varnish IP to call
|
||||
*
|
||||
* @since 2.6.8
|
||||
* @param string The Varnish IP
|
||||
*/
|
||||
$varnish_ip = apply_filters( 'rocket_varnish_ip', '' );
|
||||
|
||||
if ( defined( 'WP_ROCKET_VARNISH_IP' ) && ! $varnish_ip ) {
|
||||
$varnish_ip = WP_ROCKET_VARNISH_IP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the HTTP protocol (scheme)
|
||||
*
|
||||
* @since 2.7.3
|
||||
* @param string The HTTP protocol
|
||||
*/
|
||||
$scheme = apply_filters( 'rocket_varnish_http_purge_scheme', 'http' );
|
||||
|
||||
$parse_url['host'] = ( $varnish_ip ) ? $varnish_ip : $parse_url['host'];
|
||||
$purgeme = $scheme . '://' . $parse_url['host'] . $parse_url['path'] . $regex;
|
||||
|
||||
wp_remote_request(
|
||||
$purgeme,
|
||||
array(
|
||||
'method' => 'PURGE',
|
||||
'blocking' => false,
|
||||
'redirection' => 0,
|
||||
/**
|
||||
* Filters the headers to send with the Varnish purge request
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param array $headers Headers to send.
|
||||
*/
|
||||
'headers' => apply_filters(
|
||||
'rocket_varnish_purge_headers',
|
||||
[
|
||||
/**
|
||||
* Filters the host value passed in the request headers
|
||||
*
|
||||
* @since 2.8.15
|
||||
* @param string The host
|
||||
*/
|
||||
'host' => apply_filters( 'rocket_varnish_purge_request_host', $parse_url['host'] ),
|
||||
'X-Purge-Method' => $varnish_x_purgemethod,
|
||||
]
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a warning notice if WP Rocket scheduled events are not running properly
|
||||
*
|
||||
* @since 3.5.4 deprecated
|
||||
* @since 3.3.7
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function rocket_warning_cron() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5.4', 'WP_Rocket\Engine\Admin\HealthCheck::missed_cron()' );
|
||||
$screen = get_current_screen();
|
||||
|
||||
// This filter is documented in inc/admin-bar.php.
|
||||
if ( ! current_user_can( apply_filters( 'rocket_capacity', 'manage_options' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'settings_page_wprocket' !== $screen->id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
|
||||
|
||||
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 0 === (int) get_rocket_option( 'purge_cron_interval' ) && 0 === get_rocket_option( 'async_css' ) && 0 === get_rocket_option( 'manual_preload' ) && 0 === get_rocket_option( 'schedule_automatic_cleanup' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$events = [
|
||||
'rocket_purge_time_event' => 'Scheduled Cache Purge',
|
||||
'rocket_database_optimization_time_event' => 'Scheduled Database Optimization',
|
||||
'rocket_database_optimization_cron_interval' => 'Database Optimization Process',
|
||||
'rocket_preload_cron_interval' => 'Preload',
|
||||
'rocket_critical_css_generation_cron_interval' => 'Critical Path CSS Generation Process',
|
||||
];
|
||||
|
||||
foreach ( $events as $event => $description ) {
|
||||
$timestamp = wp_next_scheduled( $event );
|
||||
|
||||
if ( false === $timestamp ) {
|
||||
unset( $events[ $event ] );
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $timestamp - time() > 0 ) {
|
||||
unset( $events[ $event ] );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $events ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = '<p>' . _n( 'The following scheduled event failed to run. This may indicate the CRON system is not running properly, which can prevent some WP Rocket features from working as intended:', 'The following scheduled events failed to run. This may indicate the CRON system is not running properly, which can prevent some WP Rocket features from working as intended:', count( $events ), 'rocket' ) . '</p>';
|
||||
|
||||
$message .= '<ul>';
|
||||
|
||||
foreach ( $events as $description ) {
|
||||
$message .= '<li>' . $description . '</li>';
|
||||
}
|
||||
|
||||
$message .= '</ul>';
|
||||
$message .= '<p>' . __( 'Please contact your host to check if CRON is working.', 'rocket' ) . '</p>';
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'warning',
|
||||
'dismissible' => '',
|
||||
'message' => $message,
|
||||
'dismiss_button' => __FUNCTION__,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a link "Purge this cache" in the taxonomy edit area
|
||||
*
|
||||
* @since 3.5.5 deprecated
|
||||
* @since 1.0
|
||||
*
|
||||
* @param array $actions An array of row action links.
|
||||
* @param object $term The term object.
|
||||
* @return array Updated array of row action links
|
||||
*/
|
||||
function rocket_tag_row_actions( $actions, $term ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.5.5', 'WP_Rocket\Engine\Cache\AdminSubscriber::add_purge_term_link()' );
|
||||
global $taxnow;
|
||||
|
||||
if ( ! current_user_can( 'rocket_purge_terms' ) ) {
|
||||
return $actions;
|
||||
}
|
||||
|
||||
$url = wp_nonce_url( admin_url( 'admin-post.php?action=purge_cache&type=term-' . $term->term_id . '&taxonomy=' . $taxnow ), 'purge_cache_term-' . $term->term_id );
|
||||
$actions['rocket_purge'] = sprintf( '<a href="%s">%s</a>', $url, __( 'Clear this cache', 'rocket' ) );
|
||||
|
||||
return $actions;
|
||||
}
|
1134
wp-content/plugins/wp-rocket/inc/deprecated/3.6.php
Normal file
1134
wp-content/plugins/wp-rocket/inc/deprecated/3.6.php
Normal file
File diff suppressed because it is too large
Load Diff
340
wp-content/plugins/wp-rocket/inc/deprecated/3.7.php
Normal file
340
wp-content/plugins/wp-rocket/inc/deprecated/3.7.php
Normal file
@@ -0,0 +1,340 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Require deprecated classes.
|
||||
*/
|
||||
if ( ! class_exists( 'Minify_HTML' ) ) {
|
||||
require_once __DIR__ . '/vendors/classes/class-minify-html.php';
|
||||
}
|
||||
if ( ! class_exists( 'WP_Rocket\Subscriber\Optimization\Minify_HTML_Subscriber' ) ) {
|
||||
require_once __DIR__ . '/subscriber/admin/Optimization/class-minify-html-subscriber.php';
|
||||
}
|
||||
|
||||
class_alias( '\WP_Rocket\Engine\Heartbeat\HeartbeatSubscriber', '\WP_Rocket\Subscriber\Heartbeat_Subscriber' );
|
||||
|
||||
/**
|
||||
* Conflict with WP Serveur hosting: don't apply inline JS on all pages.
|
||||
*
|
||||
* @since 3.7 deprecated
|
||||
* @since 2.6.11
|
||||
*
|
||||
* @param array $html_options WP Rocket options array.
|
||||
*
|
||||
* @return array Updated WP Rocket options array.
|
||||
*/
|
||||
function rocket_deactivate_inline_js_on_wp_serveur( $html_options ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.7' );
|
||||
if ( isset( $html_options['jsMinifier'] ) ) {
|
||||
unset( $html_options['jsMinifier'] );
|
||||
}
|
||||
|
||||
return $html_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conflict with AppBanners: don't minify inline script when HTML minification is activated
|
||||
*
|
||||
* @since 3.7 deprecated
|
||||
* @since 2.2.4
|
||||
*
|
||||
* @param array $html_options An array of WP Rocket options.
|
||||
*
|
||||
* @return array Array without the inline js minify option
|
||||
*/
|
||||
function rocket_deactivate_js_minifier_with_appbanner( $html_options ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.7' );
|
||||
if ( isset( $html_options['jsMinifier'] ) && class_exists( 'AppBanners' ) ) {
|
||||
unset( $html_options['jsMinifier'] );
|
||||
}
|
||||
|
||||
return $html_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate WP Rocket HTML Minification if Autoptimize HTML minification is enabled
|
||||
*
|
||||
* @since 3.7 deprecated
|
||||
* @since 2.9.5
|
||||
*
|
||||
* @param string $old_value Previous autoptimize option value.
|
||||
* @param string $value New autoptimize option value.
|
||||
*
|
||||
* @author Remy Perona
|
||||
*
|
||||
*/
|
||||
function rocket_maybe_deactivate_minify_html( $old_value, $value ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.7' );
|
||||
if ( $value !== $old_value && 'on' === $value ) {
|
||||
update_rocket_option( 'minify_html', 0 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable WP Rocket HTML minification field if Autoptimize HTML minification is enabled
|
||||
*
|
||||
* @since 3.7 deprecated
|
||||
* @since 2.9.5
|
||||
* @return bool|null True if it is active
|
||||
* @author Remy Perona
|
||||
*
|
||||
*/
|
||||
function rocket_maybe_disable_minify_html() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.7' );
|
||||
if ( is_plugin_active( 'autoptimize/autoptimize.php' ) && 'on' === get_option( 'autoptimize_html' ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Conflict with Revolution Slider: don't minify inline script when HTML minification is activated
|
||||
*
|
||||
* @since 3.7 deprecated
|
||||
* @since 2.6.8
|
||||
*
|
||||
* @param array $html_options WP Rocket options array.
|
||||
*
|
||||
* @return array Updated WP Rocket options
|
||||
*/
|
||||
function rocket_deactivate_js_minifier_with_revslider( $html_options ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.7' );
|
||||
if ( isset( $html_options['jsMinifier'] ) && class_exists( 'RevSliderFront' ) ) {
|
||||
unset( $html_options['jsMinifier'] );
|
||||
}
|
||||
|
||||
return $html_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the emoji functionality to reduce then number of external HTTP requests.
|
||||
*
|
||||
* @sicne 3.7 Deprecated.
|
||||
* @since 2.7
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function rocket_disable_emoji() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.7' );
|
||||
|
||||
if ( rocket_bypass() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
|
||||
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
|
||||
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
|
||||
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
|
||||
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
|
||||
add_filter( 'emoji_svg_url', '__return_false' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the tinymce emoji plugin.
|
||||
*
|
||||
* @since 3.7 Deprecated.
|
||||
* @since 2.7
|
||||
*
|
||||
* @param array $plugins Plugins loaded for TinyMCE.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function rocket_disable_emoji_tinymce( $plugins ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.7' );
|
||||
if ( is_array( $plugins ) ) {
|
||||
return array_diff( $plugins, [ 'wpemoji' ] );
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable embeds on init.
|
||||
*
|
||||
* - Removes the needed query vars.
|
||||
* - Disables oEmbed discovery.
|
||||
* - Completely removes the related JavaScript.
|
||||
*
|
||||
* @since 3.7 Deprecated.
|
||||
* @since 2.10
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function rocket_disable_embeds_init() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.7' );
|
||||
if ( rocket_bypass() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $wp;
|
||||
|
||||
// Remove the embed query var.
|
||||
$wp->public_query_vars = array_diff(
|
||||
$wp->public_query_vars,
|
||||
[
|
||||
'embed',
|
||||
]
|
||||
);
|
||||
|
||||
// Remove the oembed/1.0/embed REST route.
|
||||
add_filter( 'rest_endpoints', 'rocket_disable_embeds_remove_embed_endpoint' );
|
||||
|
||||
// Disable handling of internal embeds in oembed/1.0/proxy REST route.
|
||||
add_filter( 'oembed_response_data', 'rocket_disable_embeds_filter_oembed_response_data' );
|
||||
|
||||
// Turn off oEmbed auto discovery.
|
||||
add_filter( 'embed_oembed_discover', '__return_false' );
|
||||
|
||||
// Don't filter oEmbed results.
|
||||
remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
|
||||
|
||||
// Remove oEmbed discovery links.
|
||||
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
|
||||
|
||||
// Remove oEmbed-specific JavaScript from the front-end and back-end.
|
||||
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
|
||||
add_filter( 'tiny_mce_plugins', 'rocket_disable_embeds_tiny_mce_plugin' );
|
||||
|
||||
// Remove all embeds rewrite rules.
|
||||
add_filter( 'rewrite_rules_array', 'rocket_disable_embeds_rewrites' );
|
||||
|
||||
// Remove filter of the oEmbed result before any HTTP requests are made.
|
||||
remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
|
||||
|
||||
// Load block editor JavaScript.
|
||||
add_action( 'enqueue_block_editor_assets', 'rocket_disable_embeds_enqueue_block_editor_assets' );
|
||||
|
||||
// Remove wp-embed dependency of wp-edit-post script handle.
|
||||
add_action( 'wp_default_scripts', 'rocket_disable_embeds_remove_script_dependencies' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the 'wpembed' TinyMCE plugin.
|
||||
*
|
||||
* @since 3.7 Deprecated.
|
||||
* @since 2.10
|
||||
*
|
||||
* @param array $plugins List of TinyMCE plugins.
|
||||
*
|
||||
* @return array The modified list.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function rocket_disable_embeds_tiny_mce_plugin( $plugins ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.7' );
|
||||
return array_diff( $plugins, [ 'wpembed' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all rewrite rules related to embeds.
|
||||
*
|
||||
* @since 3.7 Deprecated.
|
||||
* @since 2.10
|
||||
*
|
||||
* @param array $rules WordPress rewrite rules.
|
||||
*
|
||||
* @return array Rewrite rules without embeds rules.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function rocket_disable_embeds_rewrites( $rules ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.7' );
|
||||
if ( empty( $rules ) ) {
|
||||
return $rules;
|
||||
}
|
||||
|
||||
foreach ( $rules as $rule => $rewrite ) {
|
||||
if ( false !== strpos( $rewrite, 'embed=true' ) ) {
|
||||
unset( $rules[ $rule ] );
|
||||
}
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the oembed/1.0/embed REST route.
|
||||
*
|
||||
* @since 3.6 Deprecated.
|
||||
* @since 3.3.3
|
||||
*
|
||||
* @param array $endpoints Registered REST API endpoints.
|
||||
*
|
||||
* @return array Filtered REST API endpoints.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function rocket_disable_embeds_remove_embed_endpoint( $endpoints ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.7' );
|
||||
unset( $endpoints['/oembed/1.0/embed'] );
|
||||
|
||||
return $endpoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables sending internal oEmbed response data in proxy endpoint.
|
||||
*
|
||||
* @since 3.7 Deprecated.
|
||||
* @since 3.3.3
|
||||
*
|
||||
* @param array $data The response data.
|
||||
*
|
||||
* @return array|false Response data or false if in a REST API context.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function rocket_disable_embeds_filter_oembed_response_data( $data ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.7' );
|
||||
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues JavaScript for the block editor.
|
||||
*
|
||||
* This is used to unregister the `core-embed/wordpress` block type.
|
||||
*
|
||||
* @since 3.7 Deprecated.
|
||||
* @since 3.3.3
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function rocket_disable_embeds_enqueue_block_editor_assets() {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.7' );
|
||||
wp_enqueue_script(
|
||||
'rocket-disable-embeds',
|
||||
WP_ROCKET_ASSETS_JS_URL . 'editor/editor.js',
|
||||
[
|
||||
'wp-edit-post',
|
||||
'wp-editor',
|
||||
'wp-dom',
|
||||
],
|
||||
WP_ROCKET_VERSION,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes wp-embed dependency of core packages.
|
||||
*
|
||||
* @since 3.7 deprecated
|
||||
* @since 3.3.3
|
||||
*
|
||||
* @param \WP_Scripts $scripts WP_Scripts instance, passed by reference.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
function rocket_disable_embeds_remove_script_dependencies( $scripts ) {
|
||||
_deprecated_function( __FUNCTION__ . '()', '3.7' );
|
||||
if ( ! empty( $scripts->registered['wp-edit-post'] ) ) {
|
||||
$scripts->registered['wp-edit-post']->deps = array_diff(
|
||||
$scripts->registered['wp-edit-post']->deps,
|
||||
[ 'wp-embed' ]
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\deprecated;
|
||||
|
||||
/**
|
||||
* Trait to use in a deprecated class, or a class containing deprecated methods.
|
||||
*/
|
||||
trait DeprecatedClassTrait {
|
||||
/**
|
||||
* Marks a class as deprecated and informs when it has been used.
|
||||
* Similar to _deprecated_constructor(), but with different strings.
|
||||
* The current behavior is to trigger a user error if `WP_DEBUG` is true.
|
||||
*
|
||||
* @since 3.6
|
||||
*
|
||||
* @param string $version The version of WordPress that deprecated the class.
|
||||
* @param string $replacement Optional. The method that should have been called. Default null.
|
||||
*/
|
||||
private static function deprecated_class( $version, $replacement = null ) {
|
||||
/**
|
||||
* Fires when a deprecated class is called.
|
||||
*
|
||||
* @since 3.6
|
||||
*
|
||||
* @param string $class The class containing the deprecated constructor.
|
||||
* @param string $version The version of WordPress that deprecated the class.
|
||||
* @param string $replacement Optional. The method that should have been called.
|
||||
*/
|
||||
do_action( 'rocket_deprecated_class_run', static::class, $version, $replacement );
|
||||
|
||||
if ( ! WP_DEBUG ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters whether to trigger an error for deprecated classes.
|
||||
* `WP_DEBUG` must be true in addition to the filter evaluating to true.
|
||||
*
|
||||
* @since 3.6
|
||||
*
|
||||
* @param bool $trigger Whether to trigger the error for deprecated classes. Default true.
|
||||
*/
|
||||
if ( ! apply_filters( 'rocket_deprecated_class_trigger_error', true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( function_exists( '__' ) ) {
|
||||
if ( ! empty( $replacement ) ) {
|
||||
/**
|
||||
* With replacement.
|
||||
*/
|
||||
$message = sprintf(
|
||||
/* translators: 1: PHP class name, 2: version number, 3: replacement class name. */
|
||||
__( 'The called class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', 'rocket' ),
|
||||
'<code>' . static::class . '</code>',
|
||||
'<strong>' . $version . '</strong>',
|
||||
'<code>' . $replacement . '</code>'
|
||||
);
|
||||
} else {
|
||||
/**
|
||||
* Without replacement.
|
||||
*/
|
||||
$message = sprintf(
|
||||
/* translators: 1: PHP class name, 2: version number. */
|
||||
__( 'The called class %1$s is <strong>deprecated</strong> since version %2$s!', 'rocket' ),
|
||||
'<code>' . static::class . '</code>',
|
||||
'<strong>' . $version . '</strong>'
|
||||
);
|
||||
}
|
||||
} elseif ( ! empty( $replacement ) ) {
|
||||
/**
|
||||
* With replacement.
|
||||
*/
|
||||
$message = sprintf(
|
||||
'The called class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
|
||||
'<code>' . static::class . '</code>',
|
||||
'<strong>' . $version . '</strong>',
|
||||
'<code>' . $replacement . '</code>'
|
||||
);
|
||||
} else {
|
||||
/**
|
||||
* Without replacement.
|
||||
*/
|
||||
$message = sprintf(
|
||||
'The called class %1$s is <strong>deprecated</strong> since version %2$s!',
|
||||
'<code>' . static::class . '</code>',
|
||||
'<strong>' . $version . '</strong>'
|
||||
);
|
||||
}
|
||||
|
||||
call_user_func( 'trigger_error', $message );
|
||||
}
|
||||
}
|
@@ -0,0 +1,365 @@
|
||||
<?php
|
||||
namespace WP_Rocket\Engine\Optimization\QueryString;
|
||||
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
use WP_Rocket\deprecated\DeprecatedClassTrait;
|
||||
use WP_Rocket\Engine\Optimization\AbstractOptimization;
|
||||
use WP_Rocket\Engine\Optimization\CSSTrait;
|
||||
|
||||
/**
|
||||
* Remove query string from static resources.
|
||||
*
|
||||
* @since 3.1
|
||||
* @since 3.6 Deprecated.
|
||||
* @author Remy Perona
|
||||
* @deprecated
|
||||
*/
|
||||
class Remove extends AbstractOptimization {
|
||||
use DeprecatedClassTrait;
|
||||
use CSSTrait;
|
||||
|
||||
/**
|
||||
* Plugin options instance.
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* Cache busting base path
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $busting_path;
|
||||
|
||||
/**
|
||||
* Cache busting base URL
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $busting_url;
|
||||
|
||||
/**
|
||||
* Excluded files from optimization
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $excluded_files;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param Options_Data $options Plugin options instance.
|
||||
* @param string $busting_path Base cache busting files path.
|
||||
* @param string $busting_url Base cache busting files URL.
|
||||
*/
|
||||
public function __construct( Options_Data $options, $busting_path, $busting_url ) {
|
||||
self::deprecated_class( '3.6' );
|
||||
$this->options = $options;
|
||||
$this->busting_path = $busting_path . get_current_blog_id() . '/';
|
||||
$this->busting_url = $busting_url . get_current_blog_id() . '/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a regex-ready string with the excluded filepaths for the Remove Query Strings option
|
||||
*
|
||||
* @since 3.3.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_excluded_files() {
|
||||
static $excluded_files;
|
||||
|
||||
if ( isset( $excluded_files ) ) {
|
||||
return $excluded_files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters files to exclude from cache busting
|
||||
*
|
||||
* @since 2.9.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param array $excluded_files An array of filepath to exclude.
|
||||
*/
|
||||
$excluded_files = apply_filters( 'rocket_exclude_cache_busting', [] );
|
||||
|
||||
if ( empty( $excluded_files ) ) {
|
||||
$excluded_files = '';
|
||||
|
||||
return $excluded_files;
|
||||
}
|
||||
|
||||
foreach ( $excluded_files as $i => $excluded_file ) {
|
||||
// Escape character for future use in regex pattern.
|
||||
$excluded_files[ $i ] = str_replace( '#', '\#', $excluded_file );
|
||||
}
|
||||
|
||||
$excluded_files = implode( '|', $excluded_files );
|
||||
|
||||
return $excluded_files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove query strings for CSS files that have one
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $html HTML content.
|
||||
* @return string
|
||||
*/
|
||||
public function remove_query_strings_css( $html ) {
|
||||
$html_nocomments = preg_replace( '/<!--(.*)-->/Uis', '', $html );
|
||||
$styles = $this->find( '<link\s+([^>]+[\s\'"])?href\s*=\s*[\'"]\s*?([^\'"]+\.css(?:\?[^\'"]*)?)\s*?[\'"]([^>]+)?\/?>', $html_nocomments );
|
||||
|
||||
if ( ! $styles ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
foreach ( $styles as $style ) {
|
||||
$url = $style[2];
|
||||
|
||||
$url = $this->can_replace( $url );
|
||||
|
||||
if ( ! $url ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$optimized_url = $this->replace_url( $url, 'css' );
|
||||
|
||||
if ( ! $optimized_url ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$replace_style = str_replace( $style[2], $optimized_url, $style[0] );
|
||||
$html = str_replace( $style[0], $replace_style, $html );
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove query strings for JS files that have one
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $html HTML content.
|
||||
* @return string
|
||||
*/
|
||||
public function remove_query_strings_js( $html ) {
|
||||
$html_nocomments = $this->hide_comments( $html );
|
||||
$scripts = $this->find( '<script\s+([^>]+[\s\'"])?src\s*=\s*[\'"]\s*?([^\'"]+\.js(?:\?[^\'"]*)?)\s*?[\'"]([^>]+)?\/?>', $html_nocomments );
|
||||
|
||||
if ( ! $scripts ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
foreach ( $scripts as $script ) {
|
||||
$url = $script[2];
|
||||
|
||||
$url = $this->can_replace( $url );
|
||||
|
||||
if ( ! $url ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$optimized_url = $this->replace_url( $url, 'js' );
|
||||
|
||||
if ( ! $optimized_url ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$replace_script = str_replace( $script[2], $optimized_url, $script[0] );
|
||||
$html = str_replace( $script[0], $replace_script, $html );
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the CDN zones.
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_zones() {
|
||||
return [ 'all', 'css_and_js', 'css', 'js' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if we can optimize
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_allowed() {
|
||||
if ( rocket_get_constant( 'DONOTROCKETOPTIMIZE' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! $this->options->get( 'remove_query_strings' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if we can perform the remove query string on that URL
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $url source URL.
|
||||
* @return bool\string
|
||||
*/
|
||||
protected function can_replace( $url ) {
|
||||
$parsed_url = get_rocket_parse_url( $url );
|
||||
|
||||
if ( empty( $parsed_url['query'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$version = get_bloginfo( 'version' );
|
||||
|
||||
if ( false !== strpos( $url, 'ver=' . $version ) ) {
|
||||
$url = rtrim( str_replace( [ 'ver=' . $version, '?&', '&&' ], [ '', '?', '&' ], $url ), '?&' );
|
||||
}
|
||||
|
||||
if ( $this->is_external_file( $url ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $this->is_excluded( $url ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the URL is excluded
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $url source URL.
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_excluded( $url ) {
|
||||
$excluded_files = $this->get_excluded_files();
|
||||
|
||||
if ( ! empty( $excluded_files ) && preg_match( '#^' . $excluded_files . '$#', rocket_clean_exclude_file( $url ) ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the original URL with the cache busting URL
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $url source URL.
|
||||
* @param string $extension file extension.
|
||||
* @return bool|string
|
||||
*/
|
||||
protected function replace_url( $url, $extension ) {
|
||||
$query = wp_parse_url( $url, PHP_URL_QUERY );
|
||||
|
||||
if ( empty( $query ) ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
// This filter is documented in /inc/classes/optimization/class-abstract-optimization.php.
|
||||
$internal_url = apply_filters( 'rocket_asset_url', $url, $this->get_zones() );
|
||||
$parsed_url = get_rocket_parse_url( $internal_url );
|
||||
$relative_src = ltrim( $parsed_url['path'] . '?' . $parsed_url['query'], '/' );
|
||||
$filename = preg_replace( '/\.(' . $extension . ')\?(?:timestamp|ver)=([^&]+)(?:.*)/', '-$2.$1', $relative_src );
|
||||
|
||||
if ( $relative_src === $filename ) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$busting_file = $this->busting_path . $filename;
|
||||
$busting_url = $this->get_busting_url( $filename, $extension, $url );
|
||||
|
||||
if ( rocket_direct_filesystem()->is_readable( $busting_file ) ) {
|
||||
return $busting_url;
|
||||
}
|
||||
|
||||
$file = $this->get_file_path( $url );
|
||||
|
||||
if ( ! $file ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$busting_content = $this->get_file_content( $file );
|
||||
|
||||
if ( ! $busting_content ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( 'css' === $extension ) {
|
||||
$busting_content = $this->rewrite_paths( $file, $busting_file, $busting_content );
|
||||
}
|
||||
|
||||
if ( ! $this->write_file( $busting_content, $busting_file ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $busting_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cache busting URL
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $filename Cache busting filename.
|
||||
* @param string $extension File extension.
|
||||
* @param string $original_url Original URL for the file.
|
||||
* @return string
|
||||
*/
|
||||
protected function get_busting_url( $filename, $extension, $original_url ) {
|
||||
$url = $this->busting_url . $filename;
|
||||
|
||||
switch ( $extension ) {
|
||||
case 'css':
|
||||
// This filter is documented in inc/classes/optimization/css/class-abstract-css-optimization.php.
|
||||
$url = apply_filters( 'rocket_css_url', $url, $original_url );
|
||||
break;
|
||||
case 'js':
|
||||
// This filter is documented in inc/classes/optimization/css/class-abstract-js-optimization.php.
|
||||
$url = apply_filters( 'rocket_js_url', $url, $original_url );
|
||||
break;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
namespace WP_Rocket\Engine\Optimization\QueryString;
|
||||
|
||||
use WP_Rocket\deprecated\DeprecatedClassTrait;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
/**
|
||||
* Hooks into WordPress to remove query strings for static files.
|
||||
*
|
||||
* @since 3.1
|
||||
* @since 3.6 Deprecated.
|
||||
* @author Remy Perona
|
||||
* @deprecated
|
||||
*/
|
||||
class RemoveSubscriber implements Subscriber_Interface {
|
||||
use DeprecatedClassTrait;
|
||||
|
||||
/**
|
||||
* Remove Query String instance.
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @var Remove
|
||||
*/
|
||||
protected $remove_query_string;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param Remove $remove_query_string Remove Query String instance.
|
||||
*/
|
||||
public function __construct( Remove $remove_query_string ) {
|
||||
self::deprecated_class( '3.6' );
|
||||
$this->remove_query_string = $remove_query_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'rocket_buffer' => [ 'process', 30 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the HTML to fetch static files with a query string and remove it
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $html HTML content.
|
||||
* @return string
|
||||
*/
|
||||
public function process( $html ) {
|
||||
if ( ! $this->is_allowed() ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
$html = $this->remove_query_string->remove_query_strings_css( $html );
|
||||
$html = $this->remove_query_string->remove_query_strings_js( $html );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is allowed to remove query strings for static files.
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_allowed() {
|
||||
return $this->remove_query_string->is_allowed();
|
||||
}
|
||||
}
|
3290
wp-content/plugins/wp-rocket/inc/deprecated/deprecated.php
Normal file
3290
wp-content/plugins/wp-rocket/inc/deprecated/deprecated.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
namespace WP_Rocket\Subscriber\Optimization;
|
||||
|
||||
use WP_Rocket\deprecated\DeprecatedClassTrait;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
use WP_Rocket\Admin\Options_Data as Options;
|
||||
use WP_Rocket\Dependencies\Minify;
|
||||
|
||||
/**
|
||||
* HTML minification subscriber
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*/
|
||||
class Minify_HTML_Subscriber implements Subscriber_Interface {
|
||||
use DeprecatedClassTrait;
|
||||
/**
|
||||
* Plugin options
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @var Options
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param Options $options Plugin options.
|
||||
*/
|
||||
public function __construct( Options $options ) {
|
||||
self::deprecated_class( '3.7' );
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'rocket_buffer' => [ 'process', 14 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Minifies HTML
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param string $html HTML content.
|
||||
* @return string
|
||||
*/
|
||||
public function process( $html ) {
|
||||
if ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
if ( ! $this->options->get( 'minify_html' ) || \is_rocket_post_excluded_option( 'minify_html' ) ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
$html_options = [
|
||||
'cssMinifier' => [ $this, 'minify_inline_css' ],
|
||||
];
|
||||
|
||||
/**
|
||||
* Filter options of minify inline HTML
|
||||
*
|
||||
* @since 1.1.12
|
||||
*
|
||||
* @param array $html_options Options of minify inline HTML.
|
||||
*/
|
||||
$html_options = apply_filters( 'rocket_minify_html_options', $html_options );
|
||||
|
||||
return \Minify_HTML::minify( $html, $html_options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Minifies inline CSS
|
||||
*
|
||||
* @since 1.1.6
|
||||
*
|
||||
* @param string $css HTML content.
|
||||
* @return string
|
||||
*/
|
||||
public function minify_inline_css( $css ) {
|
||||
$minify = new Minify\CSS( $css );
|
||||
return $minify->minify();
|
||||
}
|
||||
|
||||
/**
|
||||
* Minifies inline JavaScript
|
||||
*
|
||||
* @since 1.1.6
|
||||
*
|
||||
* @param string $javascript HTML content.
|
||||
* @return string
|
||||
*/
|
||||
public function minify_inline_js( $javascript ) {
|
||||
$minify = new Minify\JS( $javascript );
|
||||
return $minify->minify();
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace WP_Rocket\Subscriber\Admin\Settings;
|
||||
|
||||
use WP_Rocket\deprecated\DeprecatedClassTrait;
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
use WP_Rocket\Admin\Settings\Beacon;
|
||||
|
||||
/**
|
||||
* Beacon Subscriber to WordPress
|
||||
*
|
||||
* @since 3.2
|
||||
* @author Remy Perona
|
||||
*/
|
||||
class Beacon_Subscriber implements Subscriber_Interface {
|
||||
use DeprecatedClassTrait;
|
||||
/**
|
||||
* Beacon instance
|
||||
*
|
||||
* @var Beacon
|
||||
*/
|
||||
private $beacon;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Beacon $beacon Beacon instance.
|
||||
*/
|
||||
public function __construct( Beacon $beacon ) {
|
||||
self::deprecated_class( '3.6' );
|
||||
$this->beacon = $beacon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of events that this subscriber wants to listen to.
|
||||
*
|
||||
* @since 3.2
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'admin_print_footer_scripts-settings_page_wprocket' => 'insert_script',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert HelpScout Beacon script
|
||||
*
|
||||
* @since 3.0
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function insert_script() {
|
||||
echo $this->beacon->insert_script(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
|
||||
}
|
||||
}
|
308
wp-content/plugins/wp-rocket/inc/deprecated/vendors/classes/class-minify-html.php
vendored
Normal file
308
wp-content/plugins/wp-rocket/inc/deprecated/vendors/classes/class-minify-html.php
vendored
Normal file
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
|
||||
use WP_Rocket\deprecated\DeprecatedClassTrait;
|
||||
|
||||
/**
|
||||
* Class Minify_HTML
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
/**
|
||||
* Compress HTML
|
||||
*
|
||||
* This is a heavy regex-based removal of whitespace, unnecessary comments and
|
||||
* tokens. IE conditional comments are preserved. There are also options to have
|
||||
* STYLE and SCRIPT blocks compressed by callback functions.
|
||||
*
|
||||
* A test suite is available.
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
*/
|
||||
class Minify_HTML
|
||||
{
|
||||
use DeprecatedClassTrait;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_jsCleanComments = true;
|
||||
|
||||
/**
|
||||
* "Minify" an HTML page
|
||||
*
|
||||
* @param string $html
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* 'cssMinifier' : (optional) callback function to process content of STYLE
|
||||
* elements.
|
||||
*
|
||||
* 'jsMinifier' : (optional) callback function to process content of SCRIPT
|
||||
* elements. Note: the type attribute is ignored.
|
||||
*
|
||||
* 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
|
||||
* unset, minify will sniff for an XHTML doctype.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function minify($html, $options = array())
|
||||
{
|
||||
$min = new self($html, $options);
|
||||
|
||||
return $min->process();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a minifier object
|
||||
*
|
||||
* @param string $html
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* 'cssMinifier' : (optional) callback function to process content of STYLE
|
||||
* elements.
|
||||
*
|
||||
* 'jsMinifier' : (optional) callback function to process content of SCRIPT
|
||||
* elements. Note: the type attribute is ignored.
|
||||
*
|
||||
* 'jsCleanComments' : (optional) whether to remove HTML comments beginning and end of script block
|
||||
*
|
||||
* 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
|
||||
* unset, minify will sniff for an XHTML doctype.
|
||||
*/
|
||||
public function __construct($html, $options = array())
|
||||
{
|
||||
self::deprecated_class( '3.7' );
|
||||
|
||||
$this->_html = str_replace("\r\n", "\n", trim($html));
|
||||
if (isset($options['xhtml'])) {
|
||||
$this->_isXhtml = (bool)$options['xhtml'];
|
||||
}
|
||||
if (isset($options['cssMinifier'])) {
|
||||
$this->_cssMinifier = $options['cssMinifier'];
|
||||
}
|
||||
if (isset($options['jsMinifier'])) {
|
||||
$this->_jsMinifier = $options['jsMinifier'];
|
||||
}
|
||||
if (isset($options['jsCleanComments'])) {
|
||||
$this->_jsCleanComments = (bool)$options['jsCleanComments'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Minify the markeup given in the constructor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
if ($this->_isXhtml === null) {
|
||||
$this->_isXhtml = (false !== strpos($this->_html, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML'));
|
||||
}
|
||||
|
||||
$this->_replacementHash = 'MINIFYHTML' . md5($_SERVER['REQUEST_TIME']);
|
||||
$this->_placeholders = array();
|
||||
|
||||
// replace SCRIPTs (and minify) with placeholders
|
||||
// preg_replace_callback - on errors the return is NULL
|
||||
// On big scripts PREG_BACKTRACK_LIMIT_ERROR is reached and causes the empty page
|
||||
$pregJs = preg_replace_callback(
|
||||
'/(\\s*)<script(\\b[^>]*?>)([\\s\\S]*?)<\\/script>(\\s*)/i'
|
||||
,array($this, '_removeScriptCB')
|
||||
,$this->_html);
|
||||
|
||||
if ( isset($pregJs) && ! empty( $pregJs ) ) {
|
||||
$this->_html = $pregJs;
|
||||
}
|
||||
|
||||
// replace STYLEs (and minify) with placeholders
|
||||
// preg_replace_callback - on errors the return is NULL
|
||||
// On big scripts PREG_BACKTRACK_LIMIT_ERROR is reached and causes the empty page
|
||||
$pregCSS = preg_replace_callback(
|
||||
'/\\s*<style(\\b[^>]*>)([\\s\\S]*?)<\\/style>\\s*/i'
|
||||
,array($this, '_removeStyleCB')
|
||||
,$this->_html);
|
||||
|
||||
if ( isset( $pregCSS ) && ! empty( $pregCSS ) ) {
|
||||
$this->_html = $pregCSS;
|
||||
}
|
||||
|
||||
// remove HTML comments (not containing IE conditional comments).
|
||||
$this->_html = preg_replace_callback(
|
||||
'/<!--([\\s\\S]*?)-->/'
|
||||
,array($this, '_commentCB')
|
||||
,$this->_html);
|
||||
|
||||
// replace PREs with placeholders
|
||||
$this->_html = preg_replace_callback('/\\s*<pre(\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i'
|
||||
,array($this, '_removePreCB')
|
||||
,$this->_html);
|
||||
|
||||
// replace TEXTAREAs with placeholders
|
||||
$this->_html = preg_replace_callback(
|
||||
'/\\s*<textarea(\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i'
|
||||
,array($this, '_removeTextareaCB')
|
||||
,$this->_html);
|
||||
|
||||
// trim each line.
|
||||
// @todo take into account attribute values that span multiple lines.
|
||||
// Fixed attribute values which span on multiple lines. Causes double spaces " "
|
||||
$this->_html = preg_replace('/^\s+|\s+$/m', ' ', $this->_html);
|
||||
// Fixed double spaces. Replaced with a single space
|
||||
$this->_html = preg_replace('/\s+/', ' ', $this->_html);
|
||||
|
||||
// remove ws around block/undisplayed elements
|
||||
$this->_html = preg_replace('/\\s+(<\\/?(?:area|article|aside|base(?:font)?|blockquote|body'
|
||||
.'|canvas|caption|center|col(?:group)?|dd|dir|div|dl|dt|fieldset|figcaption|figure|footer|form'
|
||||
.'|frame(?:set)?|h[1-6]|head|header|hgroup|hr|html|legend|li|link|main|map|menu|meta|nav'
|
||||
.'|ol|opt(?:group|ion)|output|p|param|section|t(?:able|body|head|d|h||r|foot|itle)'
|
||||
.'|ul|video)\\b[^>]*>)/i', '$1', $this->_html);
|
||||
|
||||
// remove ws outside of all elements
|
||||
$this->_html = preg_replace_callback(
|
||||
'/>([^<]+)</'
|
||||
,array($this, '_outsideTagCB')
|
||||
,$this->_html);
|
||||
|
||||
// fill placeholders
|
||||
$this->_html = str_replace(
|
||||
array_keys($this->_placeholders)
|
||||
,array_values($this->_placeholders)
|
||||
,$this->_html
|
||||
);
|
||||
// issue 229: multi-pass to catch scripts that didn't get replaced in textareas
|
||||
$this->_html = str_replace(
|
||||
array_keys($this->_placeholders)
|
||||
,array_values($this->_placeholders)
|
||||
,$this->_html
|
||||
);
|
||||
|
||||
return $this->_html;
|
||||
}
|
||||
|
||||
protected function _commentCB($m)
|
||||
{
|
||||
return
|
||||
(
|
||||
false !== strpos($m[1], 'fwp-loop')
|
||||
||
|
||||
false !== strpos($m[1], 'ngg_resource_manager_marker')
|
||||
||
|
||||
0 === strpos($m[1], '[')
|
||||
||
|
||||
false !== strpos($m[1], '<![')
|
||||
||
|
||||
0 === strpos($m[1], 'esi')
|
||||
||
|
||||
0 === strpos($m[1], 'noindex')
|
||||
||
|
||||
0 === strpos($m[1], '/noindex')
|
||||
||
|
||||
0 === strpos($m[1], 'start_content')
|
||||
||
|
||||
0 === strpos($m[1], 'end_content')
|
||||
||
|
||||
0 === strpos($m[1], '{{WP_ROCKET_CONDITIONAL}}')
|
||||
)
|
||||
? $m[0]
|
||||
: '';
|
||||
}
|
||||
|
||||
protected function _reservePlace($content)
|
||||
{
|
||||
$placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%';
|
||||
$this->_placeholders[$placeholder] = $content;
|
||||
|
||||
return $placeholder;
|
||||
}
|
||||
|
||||
protected $_isXhtml = null;
|
||||
protected $_replacementHash = null;
|
||||
protected $_placeholders = array();
|
||||
protected $_cssMinifier = null;
|
||||
protected $_jsMinifier = null;
|
||||
|
||||
protected function _outsideTagCB($m)
|
||||
{
|
||||
return '>' . preg_replace('/^\\s+|\\s+$/', ' ', $m[1]) . '<';
|
||||
}
|
||||
|
||||
protected function _removePreCB($m)
|
||||
{
|
||||
return $this->_reservePlace("<pre{$m[1]}");
|
||||
}
|
||||
|
||||
protected function _removeTextareaCB($m)
|
||||
{
|
||||
return $this->_reservePlace("<textarea{$m[1]}");
|
||||
}
|
||||
|
||||
protected function _removeStyleCB($m)
|
||||
{
|
||||
$openStyle = "<style{$m[1]}";
|
||||
$css = $m[2];
|
||||
// remove HTML comments
|
||||
$css = preg_replace('/(?:^\\s*<!--|-->\\s*$)/u', '', $css);
|
||||
|
||||
// remove CDATA section markers
|
||||
$data = $this->_removeCdata($css);
|
||||
|
||||
// minify
|
||||
$minifier = $this->_cssMinifier
|
||||
? $this->_cssMinifier
|
||||
: 'trim';
|
||||
$css = call_user_func($minifier, $data['content']);
|
||||
|
||||
return $this->_reservePlace( $data['cdata']
|
||||
? "{$openStyle}/* <![CDATA[ */ {$css} /* ]]> */</style>"
|
||||
: "{$openStyle}{$css}</style>"
|
||||
);
|
||||
}
|
||||
|
||||
protected function _removeScriptCB($m)
|
||||
{
|
||||
$openScript = "<script{$m[2]}";
|
||||
$js = $m[3];
|
||||
|
||||
// whitespace surrounding? preserve at least one space
|
||||
$ws1 = ($m[1] === '') ? '' : ' ';
|
||||
$ws2 = ($m[4] === '') ? '' : ' ';
|
||||
|
||||
// remove HTML comments (and ending "//" if present)
|
||||
if ($this->_jsCleanComments) {
|
||||
$js = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/u', '', $js);
|
||||
}
|
||||
|
||||
// remove CDATA section markers
|
||||
$data = $this->_removeCdata($js);
|
||||
|
||||
// minify
|
||||
$minifier = $this->_jsMinifier
|
||||
? $this->_jsMinifier
|
||||
: 'trim';
|
||||
$js = call_user_func($minifier, $data['content']);
|
||||
|
||||
return $this->_reservePlace($data['cdata']
|
||||
? "{$ws1}{$openScript}/* <![CDATA[ */ {$js} /* ]]> */</script>{$ws2}"
|
||||
: "{$ws1}{$openScript}{$js}</script>{$ws2}"
|
||||
);
|
||||
}
|
||||
|
||||
protected function _removeCdata($str)
|
||||
{
|
||||
$data = array();
|
||||
|
||||
if ( false !== strpos( $str, '<![CDATA[' ) ) {
|
||||
$data['content'] = str_replace( array( '/* <![CDATA[ */', '/* ]]> */' ), '', $str );
|
||||
$data['cdata'] = true;
|
||||
|
||||
} else {
|
||||
$data['content'] = $str;
|
||||
$data['cdata'] = false;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user