updated plugin W3 Total Cache
version 2.5.0
This commit is contained in:
wp-content/plugins/w3-total-cache
BrowserCache_Environment_Nginx.phpBrowserCache_Page_View_SectionSecurity.phpBrowserCache_Plugin.phpCacheFlush.phpCacheFlush_Locally.phpCacheGroups_Plugin_Admin.phpCacheGroups_Plugin_Admin_View.jsCacheGroups_Plugin_Admin_View.phpCache_File_Generic.phpCdn_AdminActions.phpCdn_GeneralPage_View.phpCdn_Highwinds_Widget_View.phpCdn_Highwinds_Widget_View_NotConfigured.phpCdn_Plugin.phpCdn_StackPath2_Page_View.phpCdn_StackPath2_Widget_View_Authorized.phpCdn_StackPath2_Widget_View_Unauthorized.phpCdn_StackPath_Page_View.phpCdn_StackPath_Widget_View_Authorized.phpCdn_StackPath_Widget_View_Unauthorized.phpCdnfsd_CloudFront_Page_View.phpCdnfsd_GeneralPage_View.phpCdnfsd_LimeLight_Page_View.phpCdnfsd_StackPath2_Page_View.phpCdnfsd_StackPath_Page_View.phpCdnfsd_TransparentCDN_Page_View.phpConfigCompiler.phpConfigKeys.phpDbCache_Environment.phpDbCache_Page.phpDbCache_Plugin.phpDbCache_Wpdb.phpDbCache_WpdbNew.phpDispatcher.phpExtension_Amp_Page_View.phpExtension_CloudFlare_Cdn_Page_View.phpExtension_CloudFlare_GeneralPage_View.phpExtension_CloudFlare_Page_View.phpExtension_CloudFlare_Plugin_Admin.phpExtension_FragmentCache_GeneralPage_View.phpExtension_FragmentCache_Page_View.phpExtension_FragmentCache_Plugin.phpExtension_FragmentCache_Plugin_Admin.phpExtension_Genesis_Page_View.phpExtension_ImageService_Page_View.phpExtension_ImageService_Plugin_Admin.phpExtension_NewRelic_GeneralPage_View.phpExtension_NewRelic_Page_View_Apm.phpExtension_Swarmify_Page_View.phpExtension_Wpml_Plugin_Admin.phpExtensions_Plugin_Admin.phpFeatureShowcase_Plugin_Admin.phpFeatureShowcase_Plugin_Admin_View.phpGeneric_AdminActions_Default.phpGeneric_AdminActions_Flush.phpGeneric_Page_Dashboard_View.cssGeneric_Plugin.phpGeneric_Plugin_Admin.phpGeneric_WidgetCommunity_View.phpGeneric_WidgetServices.phpGeneric_WidgetServices_View.phpLicensing_Plugin_Admin.phpMinify_Plugin.phpMinify_Plugin_Admin.phpMobile_Base.phpObjectCache_Environment.phpObjectCache_Page.phpObjectCache_Plugin.phpObjectCache_Plugin_Admin.phpObjectCache_WpObjectCache.phpObjectCache_WpObjectCache_Regular.phpPageSpeed_Api.phpPageSpeed_Instructions.phpPageSpeed_Page.phpPageSpeed_Page_View.cssPageSpeed_Page_View.jsPageSpeed_Widget.phpPgCache_ContentGrabber.phpPgCache_Plugin.phpRoot_AdminMenu.phpRoot_Loader.phpSetupGuide_Plugin_Admin.phpSupport_Page.phpSupport_Page_View_DoneContent.phpSystemOpCache_GeneralPage_View.phpUsageStatistics_GeneralPage_View.phpUsageStatistics_Page.phpUsageStatistics_Page_View_Free.phpUsageStatistics_Widget_View_Disabled.phpUserExperience_DeferScripts_Extension.phpUserExperience_DeferScripts_Mutator.phpUserExperience_DeferScripts_Page_View.phpUserExperience_DeferScripts_Script.jsUserExperience_GeneralPage_View.phpUserExperience_LazyLoad_Page_View.phpUserExperience_Page_View.phpUserExperience_Plugin_Admin.phpUtil_Admin.phpUtil_AttachToActions.phpUtil_Environment.phpUtil_PageSpeed.phpUtil_PageUrls.phpUtil_Ui.phpVarnish_Plugin.phpreadme.txt
extension-example
inc
lightbox
options
about.phpbrowsercache.phpcdn.php
common
dashboard.phpdbcache.phpedd
enterprise
extensions.phpextensions
general.phpinstall.phpminify.phpobjectcache.phpparts
pgcache.phpsupport.phppopup
cdn_export_file.phpcdn_export_library.phpcdn_import_library.phpcdn_purge.phpcdn_queue.phpcdn_rename_domain.php
wizard
languages
pub
css
js
vendor
autoload.php
w3-total-cache-api.phpw3-total-cache.phpcomposer
guzzlehttp
guzzle
.editorconfig.gitattributes
.github
Makefilebuild
docs
Makefile
phpstan-baseline.neonphpstan.neon.distphpunit.xml.dist_static
conf.pyfaq.rsthandlers-and-middleware.rstindex.rstoverview.rstpsr7.rstquickstart.rstrequest-options.rstrequirements.txttesting.rsttests
ClientTest.php
Cookie
Exception
Handler
CurlFactoryTest.phpCurlHandlerTest.phpCurlMultiHandlerTest.phpEasyHandleTest.phpMockHandlerTest.phpProxyTest.phpStreamHandlerTest.php
HandlerStackTest.phpInternalUtilsTest.phpMessageFormatterTest.phpMiddlewareTest.phpPoolTest.phpPrepareBodyMiddlewareTest.phpRedirectMiddlewareTest.phpRetryMiddlewareTest.phpServer.phpTransferStatsTest.phpUriTemplateTest.phpbootstrap.phpfunctionsTest.phpserver.jspsr7
.editorconfig.gitattributes.travis.ymlMakefilephpunit.xml.dist
.github
workflows
tests
AppendStreamTest.phpBaseTest.phpBufferStreamTest.phpCachingStreamTest.phpDroppingStreamTest.phpFnStreamTest.phpHasToString.phpHeaderTest.phpHelpers.phpInflateStreamTest.php
Integration
LazyOpenStreamTest.phpLimitStreamTest.phpMessageTest.phpMimeTypeTest.phpMultipartStreamTest.phpNoSeekStreamTest.phpPumpStreamTest.phpQueryTest.phpReadSeekOnlyStream.phpRequestTest.phpResponseTest.phpServerRequestTest.phpStreamDecoratorTraitTest.phpStreamTest.phpStreamWrapperTest.phpUploadedFileTest.phpUriComparatorTest.phpUriNormalizerTest.phpUriResolverTest.phpUriTest.phpUtilsTest.phpwp-content
@ -0,0 +1,175 @@
|
||||
<?php
|
||||
/**
|
||||
* File: UserExperience_DeferScripts_Mutator.php
|
||||
*
|
||||
* JS feature mutator for buffer processing.
|
||||
*
|
||||
* @since 2.4.2
|
||||
*
|
||||
* @package W3TC
|
||||
*/
|
||||
|
||||
namespace W3TC;
|
||||
|
||||
/**
|
||||
* UserExperience DeferScripts Mutator.
|
||||
*
|
||||
* @since 2.4.2
|
||||
*/
|
||||
class UserExperience_DeferScripts_Mutator {
|
||||
/**
|
||||
* Config.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* Modified flag.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $modified = false;
|
||||
|
||||
/**
|
||||
* Array of includes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $includes = array();
|
||||
|
||||
/**
|
||||
* User Experience DeferScripts Mutator constructor.
|
||||
*
|
||||
* @since 2.4.2
|
||||
*
|
||||
* @param object $config Config object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $config ) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs User Experience DeferScripts Mutator.
|
||||
*
|
||||
* @since 2.4.2
|
||||
*
|
||||
* @param string $buffer Buffer string containing browser output.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function run( $buffer ) {
|
||||
$r = apply_filters(
|
||||
'w3tc_deferscripts_mutator_before',
|
||||
array(
|
||||
'buffer' => $buffer,
|
||||
'modified' => $this->modified,
|
||||
)
|
||||
);
|
||||
|
||||
$buffer = $r['buffer'];
|
||||
$this->modified = $r['modified'];
|
||||
|
||||
$this->includes = $this->config->get_array(
|
||||
array(
|
||||
'user-experience-defer-scripts',
|
||||
'includes',
|
||||
)
|
||||
);
|
||||
|
||||
$buffer = preg_replace_callback(
|
||||
'~<script\s[^>]+>~is',
|
||||
array(
|
||||
$this,
|
||||
'tag_script',
|
||||
),
|
||||
$buffer
|
||||
);
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get modified status flag.
|
||||
*
|
||||
* @since 2.4.2
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function content_modified() {
|
||||
return $this->modified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies script tag for script matched to be deferred.
|
||||
*
|
||||
* @since 2.4.2
|
||||
*
|
||||
* @param array $matches array of matched JS entries.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function tag_script( $matches ) {
|
||||
$content = $matches[0];
|
||||
|
||||
if ( $this->is_content_included( $content ) ) {
|
||||
$count = 0;
|
||||
$content = preg_replace(
|
||||
'~(\s)src=~is',
|
||||
'$1data-lazy="w3tc" data-src=',
|
||||
$content,
|
||||
-1,
|
||||
$count
|
||||
);
|
||||
|
||||
if ( $count > 0 ) {
|
||||
$this->modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if content has already been deferred.
|
||||
*
|
||||
* @since 2.4.2
|
||||
*
|
||||
* @param string $content script tag string.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function is_content_included( $content ) {
|
||||
foreach ( $this->includes as $w ) {
|
||||
if ( ! empty( $w ) ) {
|
||||
if ( strpos( $content, $w ) !== false ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters out scripts so Minify doesn't touch deferred scripts.
|
||||
*
|
||||
* @since 2.4.2
|
||||
*
|
||||
* @param array $script_tags array of script tags.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function w3tc_minify_js_script_tags( $script_tags ) {
|
||||
return array_values(
|
||||
array_filter(
|
||||
$script_tags,
|
||||
function( $i ) {
|
||||
return ! preg_match( '~\sdata-lazy="w3tc"\s~', $i );
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user