add wp-rocket

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

View File

@@ -0,0 +1,68 @@
<?php
defined( 'ABSPATH' ) || exit;
$current_theme = wp_get_theme(); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
if ( 'Avada' === $current_theme->get( 'Name' ) ) {
// When Avada theme purge its own cache.
add_action( 'avada_clear_dynamic_css_cache', 'rocket_clean_domain' );
/**
* Deactivate WP Rocket lazyload if Avada lazyload is enabled
*
* @since 3.3.4
*
* @param string $old_value Previous Avada option value.
* @param string $value New Avada option value.
* @return void
*/
function rocket_avada_maybe_deactivate_lazyload( $old_value, $value ) {
if (
empty( $old_value['lazy_load'] )
||
( ! empty( $value['lazy_load'] ) && 'avada' === $value['lazy_load'] )
) {
update_rocket_option( 'lazyload', 0 );
}
}
add_action( 'update_option_fusion_options', 'rocket_avada_maybe_deactivate_lazyload', 10, 2 );
}
/**
* Disable WP Rocket lazyload field if Avada lazyload is enabled
*
* @since 3.3.4
*
* @return bool
*/
function rocket_avada_maybe_disable_lazyload() {
$avada_options = get_option( 'fusion_options' );
$current_theme = wp_get_theme();
if ( 'Avada' !== $current_theme->get( 'Name' ) ) {
return false;
}
if ( empty( $avada_options['lazy_load'] ) ) {
return false;
}
if ( ! empty( $avada_options['lazy_load'] && 'avada' !== $avada_options['lazy_load'] ) ) {
return false;
}
return true;
}
/**
* Clears WP Rocket's cache after Avada's Fusion Patcher flushes their caches
*
* @since 3.3.5
*
* @return void
*/
function rocket_avada_clear_cache_fusion_patcher() {
rocket_clean_domain();
}
add_action( 'fusion_cache_reset_after', 'rocket_avada_clear_cache_fusion_patcher' );

View File

@@ -0,0 +1,44 @@
<?php
defined( 'ABSPATH' ) || exit;
add_action( 'admin_init', 'rocket_clear_cache_after_studiopress_accelerator' );
/**
* Clear WP Rocket cache after purged the StudioPress Accelerator cache
*
* @since 2.5.5
*
* @return void
*/
function rocket_clear_cache_after_studiopress_accelerator() {
if ( isset( $GLOBALS['sp_accel_nginx_proxy_cache_purge'] ) && is_a( $GLOBALS['sp_accel_nginx_proxy_cache_purge'], 'SP_Accel_Nginx_Proxy_Cache_Purge' ) && isset( $_REQUEST['_wpnonce'] ) ) {
$nonce = $_REQUEST['_wpnonce']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Recommended
if ( wp_verify_nonce( $nonce, 'sp-accel-purge-url' ) && ! empty( $_REQUEST['cache-purge-url'] ) ) {
$submitted_url = sanitize_text_field( wp_unslash( $_REQUEST['cache-purge-url'] ) );
// Clear the URL.
rocket_clean_files( [ $submitted_url ] );
} elseif ( wp_verify_nonce( $nonce, 'sp-accel-purge-theme' ) ) {
// Clear all caching files.
rocket_clean_domain();
// Preload cache.
run_rocket_bot();
run_rocket_sitemap_preload();
}
}
}
add_action( 'after_rocket_clean_domain', 'rocket_clean_studiopress_accelerator' );
/**
* Call the cache server to purge the cache with StudioPress Accelerator.
*
* @since 2.5.5
*
* @return void
*/
function rocket_clean_studiopress_accelerator() {
if ( isset( $GLOBALS['sp_accel_nginx_proxy_cache_purge'] ) && is_a( $GLOBALS['sp_accel_nginx_proxy_cache_purge'], 'SP_Accel_Nginx_Proxy_Cache_Purge' ) ) {
$GLOBALS['sp_accel_nginx_proxy_cache_purge']->cache_flush_theme();
}
}

View File

@@ -0,0 +1,64 @@
<?php
defined( 'ABSPATH' ) || exit;
$current_theme = wp_get_theme(); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
if ( 'uncode' === strtolower( $current_theme->get( 'Name' ) ) || 'uncode' === strtolower( $current_theme->get( 'Template' ) ) ) {
/**
* Excludes Uncode init and ai-uncode JS files from minification/combine
*
* @since 3.1
* @author Remy Perona
*
* @param array $excluded_js Array of JS filepaths to be excluded.
* @return array
*/
function rocket_exclude_js_uncode( $excluded_js ) {
$excluded_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/init.js' );
$excluded_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/min/init.min.js' );
$excluded_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/ai-uncode.js' );
$excluded_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/min/ai-uncode.min.js' );
return $excluded_js;
}
add_filter( 'rocket_exclude_js', 'rocket_exclude_js_uncode' );
/**
* Excludes some Uncode inline scripts from combine JS
*
* @since 3.1
* @author Remy Perona
*
* @param array $inline_js Array of patterns to match for exclusion.
* @return array
*/
function rocket_exclude_inline_js_uncode( $inline_js ) {
$inline_js[] = 'SiteParameters';
$inline_js[] = 'script-';
$inline_js[] = 'initBox';
$inline_js[] = 'initHeader';
$inline_js[] = 'fixMenuHeight';
return $inline_js;
}
add_filter( 'rocket_excluded_inline_js_content', 'rocket_exclude_inline_js_uncode' );
if ( version_compare( $current_theme->get( 'Version' ), '2.1', '<' ) ) {
/**
* Excludes Uncode JS files from defer JS
*
* @since 3.2.5
* @author Remy Perona
*
* @param array $exclude_defer_js Array of JS filepaths to be excluded.
* @return array
*/
function rocket_exclude_defer_js_uncode( $exclude_defer_js ) {
$exclude_defer_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/init.js' );
$exclude_defer_js[] = rocket_clean_exclude_file( get_template_directory_uri() . '/library/js/min/init.min.js' );
return $exclude_defer_js;
}
add_filter( 'rocket_exclude_defer_js', 'rocket_exclude_defer_js_uncode' );
}
}