Fast Velocity Minify - Version 2.6.0

Version Description

[2019.03.02] = * fixed cache purging with the hypercache plugin * fixed a bug with inline scripts and styles not showing up if there is no url for the enqueued handle * changed the cache directory from the wp-content/uploads to wp-content/cache * improved compatibility with page cache plugins and servers (purging FVM without purging the page cache should be fine now) * added a daily cronjob, to delete public invalid cache files that are older than 3 months (your page cache should expire before this)

Download this release

Release Info

Developer Alignak
Plugin Icon 128x128 Fast Velocity Minify
Version 2.6.0
Comparing to
See all releases

Code changes from version 2.5.9 to 2.6.0

Files changed (5) hide show
  1. fvm.php +94 -32
  2. inc/functions-cache.php +366 -0
  3. inc/functions-upgrade.php +12 -2
  4. inc/functions.php +23 -302
  5. readme.txt +27 -33
fvm.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://fastvelocity.com
5
  Description: Improve your speed score on GTmetrix, Pingdom Tools and Google PageSpeed Insights by merging and minifying CSS and JavaScript files into groups, compressing HTML and other speed optimizations.
6
  Author: Raul Peixoto
7
  Author URI: http://fastvelocity.com
8
- Version: 2.5.9
9
  License: GPL2
10
 
11
  ------------------------------------------------------------------------
@@ -71,6 +71,7 @@ $plugindir = plugin_dir_path( __FILE__ ); # prints with trailing slash
71
  include($plugindir.'inc/functions.php');
72
  include($plugindir.'inc/functions-serverinfo.php');
73
  include($plugindir.'inc/functions-upgrade.php');
 
74
 
75
  # wp-cli support
76
  if ( defined( 'WP_CLI' ) && WP_CLI ) {
@@ -171,10 +172,8 @@ if(is_admin()) {
171
  add_action('admin_init', 'fastvelocity_min_register_settings');
172
 
173
  # This function runs when WordPress updates or installs/remove something
174
- add_action('upgrader_process_complete', 'fvm_purge_all');
175
- add_action('after_switch_theme', 'fvm_purge_all');
176
- add_action('activated_plugin', 'fvm_purge_all');
177
- add_action('deactivated_plugin', 'fvm_purge_all');
178
  add_action('admin_init', 'fastvelocity_purge_onsave', 1);
179
 
180
  # activation, deactivation
@@ -337,7 +336,6 @@ function fastvelocity_min_load_admin_jscss($hook) {
337
  # register plugin settings
338
  function fastvelocity_min_register_settings() {
339
  register_setting('fvm-group', 'fastvelocity_min_enable_purgemenu');
340
- register_setting('fvm-group', 'fastvelocity_min_preserve_oldcache');
341
  register_setting('fvm-group', 'fastvelocity_preserve_settings_on_uninstall');
342
  register_setting('fvm-group', 'fastvelocity_min_default_protocol');
343
  register_setting('fvm-group', 'fastvelocity_min_disable_js_merge');
@@ -579,11 +577,6 @@ $active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'status';
579
  Admin Bar Purge <span class="note-info">[ If selected, a new option to purge FVM cache from the admin bar will show up ]</span></label>
580
  <br />
581
 
582
- <label for="fastvelocity_min_preserve_oldcache">
583
- <input name="fastvelocity_min_preserve_oldcache" type="checkbox" id="fastvelocity_min_preserve_oldcache" value="1" <?php echo checked(1 == get_option('fastvelocity_min_preserve_oldcache'), true, false); ?>>
584
- Preserve Cache Files <span class="note-info">[ This will reload your cache files when you purge, but preserve the old files ]</span></label>
585
- <br />
586
-
587
  <label for="fastvelocity_preserve_settings_on_uninstall">
588
  <input name="fastvelocity_preserve_settings_on_uninstall" type="checkbox" id="fastvelocity_preserve_settings_on_uninstall" value="1" <?php echo checked(1 == get_option('fastvelocity_preserve_settings_on_uninstall'), true, false); ?>>
589
  Preserve Settings<span class="note-info">[ If selected, all FVM settings will be preserved, even if you uninstall the plugin ]</span></label>
@@ -1214,7 +1207,10 @@ $ignore = fastvelocity_default_ignore($ignore);
1214
  foreach( $scripts->to_do as $handle ) :
1215
 
1216
  # is it a footer script?
1217
- $is_footer = 0; if (isset($wp_scripts->registered[$handle]->extra["group"]) || isset($wp_scripts->registered[$handle]->args)) { $is_footer = 1; }
 
 
 
1218
 
1219
  # skip footer scripts for now
1220
  if($is_footer != 1) {
@@ -1222,6 +1218,11 @@ $is_footer = 0; if (isset($wp_scripts->registered[$handle]->extra["group"]) || i
1222
  # get full url
1223
  $hurl = fastvelocity_min_get_hurl($wp_scripts->registered[$handle]->src, $wp_domain, $wp_home);
1224
 
 
 
 
 
 
1225
  # Exclude JS files from PSI (Async) takes priority over the ignore list
1226
  if($fvm_min_excludejslist != false || is_array($fvm_min_excludejslist)) {
1227
 
@@ -1240,6 +1241,7 @@ $is_footer = 0; if (isset($wp_scripts->registered[$handle]->extra["group"]) || i
1240
  if($skipjs != false) { continue; }
1241
  }
1242
 
 
1243
  # IE only files don't increment things
1244
  $ieonly = fastvelocity_ie_blacklist($hurl);
1245
  if($ieonly == true) { continue; }
@@ -1263,7 +1265,13 @@ $is_footer = 0; if (isset($wp_scripts->registered[$handle]->extra["group"]) || i
1263
  # make sure that the scripts skipped here, show up in the footer
1264
  } else {
1265
  $hurl = fastvelocity_min_get_hurl($wp_scripts->registered[$handle]->src, $wp_domain, $wp_home);
1266
- wp_enqueue_script($handle, $hurl, array(), null, true);
 
 
 
 
 
 
1267
  }
1268
  endforeach;
1269
 
@@ -1276,8 +1284,8 @@ for($i=0,$l=count($header);$i<$l;$i++) {
1276
  $hash = 'header-'.hash('adler32',implode('',$header[$i]['handles']));
1277
 
1278
  # create cache files and urls
1279
- $file = $cachedir.'/'.$hash.'-'.$ctime.'.min.js';
1280
- $file_url = fvm_get_protocol($cachedirurl.'/'.$hash.'-'.$ctime.'.min.js');
1281
 
1282
  # generate a new cache file
1283
  clearstatcache();
@@ -1293,10 +1301,17 @@ for($i=0,$l=count($header);$i<$l;$i++) {
1293
 
1294
  # get hurl per handle
1295
  $hurl = fastvelocity_min_get_hurl($wp_scripts->registered[$handle]->src, $wp_domain, $wp_home);
 
 
 
 
 
 
 
1296
  $printurl = str_ireplace(array(site_url(), home_url(), 'http:', 'https:'), '', $hurl);
1297
 
1298
  # download, minify, cache
1299
- $tkey = 'js-'.$ctime.'-'.hash('adler32', $handle.$hurl).'.js';
1300
  $json = false; $json = fvm_get_transient($tkey);
1301
  if ( $json === false) {
1302
  $json = fvm_download_and_minify($hurl, null, $disable_js_minification, 'js', $handle);
@@ -1410,6 +1425,11 @@ foreach( $scripts->to_do as $handle ) :
1410
  # get full url
1411
  $hurl = fastvelocity_min_get_hurl($wp_scripts->registered[$handle]->src, $wp_domain, $wp_home);
1412
 
 
 
 
 
 
1413
  # Exclude JS files from PSI (Async) takes priority over the ignore list
1414
  if($fvm_min_excludejslist != false || is_array($fvm_min_excludejslist)) {
1415
 
@@ -1458,8 +1478,8 @@ for($i=0,$l=count($footer);$i<$l;$i++) {
1458
  $hash = 'footer-'.hash('adler32',implode('',$footer[$i]['handles']));
1459
 
1460
  # create cache files and urls
1461
- $file = $cachedir.'/'.$hash.'-'.$ctime.'.min.js';
1462
- $file_url = fvm_get_protocol($cachedirurl.'/'.$hash.'-'.$ctime.'.min.js');
1463
 
1464
  # generate a new cache file
1465
  clearstatcache();
@@ -1475,11 +1495,18 @@ for($i=0,$l=count($footer);$i<$l;$i++) {
1475
 
1476
  # get hurl per handle
1477
  $hurl = fastvelocity_min_get_hurl($wp_scripts->registered[$handle]->src, $wp_domain, $wp_home);
 
 
 
 
 
 
 
1478
  $printurl = str_ireplace(array(site_url(), home_url(), 'http:', 'https:'), '', $hurl);
1479
 
1480
 
1481
  # download, minify, cache
1482
- $tkey = 'js-'.$ctime.'-'.hash('adler32', $handle.$hurl).'.js';
1483
  $json = false; $json = fvm_get_transient($tkey);
1484
  if ( $json === false) {
1485
  $json = fvm_download_and_minify($hurl, null, $disable_js_minification, 'js', $handle);
@@ -1712,6 +1739,11 @@ foreach( $styles->to_do as $handle):
1712
  # full url or empty
1713
  $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
1714
 
 
 
 
 
 
1715
  # mark duplicates as done and remove from the queue
1716
  if(!empty($hurl)) {
1717
  $key = hash('adler32', $hurl);
@@ -1800,7 +1832,7 @@ if(!$skip_google_fonts && count($google_fonts) > 0 || ($force_inline_googlefonts
1800
  } elseif($force_inline_googlefonts == true) {
1801
 
1802
  # download, minify, cache
1803
- $tkey = 'css-'.$ctime.'-'.hash('adler32', $gfurl).'.css';
1804
  $json = false; $json = fvm_get_transient($tkey);
1805
  if ( $json === false) {
1806
  $json = fvm_download_and_minify($gfurl, null, $disable_css_minification, 'css', null);
@@ -1926,8 +1958,8 @@ for($i=0,$l=count($header);$i<$l;$i++) {
1926
  $hash = 'header-'.hash('adler32',implode('',$header[$i]['handles']).$inline_css_hash);
1927
 
1928
  # create cache files and urls
1929
- $file = $cachedir.'/'.$hash.'-'.$ctime.'.min.css';
1930
- $file_url = fvm_get_protocol($cachedirurl.'/'.$hash.'-'.$ctime.'.min.css');
1931
 
1932
  # generate a new cache file
1933
  clearstatcache();
@@ -1943,10 +1975,17 @@ for($i=0,$l=count($header);$i<$l;$i++) {
1943
 
1944
  # get hurl per handle
1945
  $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
 
 
 
 
 
 
 
1946
  $printurl = str_ireplace(array(site_url(), home_url(), 'http:', 'https:'), '', $hurl);
1947
 
1948
  # download, minify, cache
1949
- $tkey = 'css-'.$ctime.'-'.hash('adler32', $handle.$hurl).'.css';
1950
  $json = false; $json = fvm_get_transient($tkey);
1951
  if ( $json === false) {
1952
  $json = fvm_download_and_minify($hurl, null, $disable_css_minification, 'css', $handle);
@@ -2083,6 +2122,11 @@ foreach( $styles->to_do as $handle ) :
2083
  # dequeue and get a list of google fonts, or requeue external
2084
  $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
2085
 
 
 
 
 
 
2086
  if (stripos($hurl, 'fonts.googleapis.com') !== false) {
2087
  wp_dequeue_style($handle);
2088
  if($remove_googlefonts != false) { $done = array_merge($done, array($handle)); continue; } # mark as done if to be removed
@@ -2133,7 +2177,7 @@ if(!$skip_google_fonts && count($google_fonts) > 0 || ($force_inline_googlefonts
2133
  } elseif($force_inline_googlefonts == true) {
2134
 
2135
  # download, minify, cache
2136
- $tkey = 'css-'.$ctime.'-'.hash('adler32', $gfurl).'.css';
2137
  $json = false; $json = fvm_get_transient($tkey);
2138
  if ( $json === false) {
2139
  $json = fvm_download_and_minify($gfurl, null, $disable_css_minification, 'css', null);
@@ -2190,7 +2234,12 @@ foreach( $styles->to_do as $handle ) :
2190
 
2191
  # get full url
2192
  $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
2193
-
 
 
 
 
 
2194
  # mark duplicates as done and remove from the queue
2195
  if(!empty($hurl)) {
2196
  $key = hash('adler32', $hurl);
@@ -2297,8 +2346,8 @@ for($i=0,$l=count($footer);$i<$l;$i++) {
2297
  $hash = 'footer-'.hash('adler32',implode('',$footer[$i]['handles']).$inline_css_hash);
2298
 
2299
  # create cache files and urls
2300
- $file = $cachedir.'/'.$hash.'-'.$ctime.'.min.css';
2301
- $file_url = fvm_get_protocol($cachedirurl.'/'.$hash.'-'.$ctime.'.min.css');
2302
 
2303
  # generate a new cache file
2304
  clearstatcache();
@@ -2314,10 +2363,17 @@ for($i=0,$l=count($footer);$i<$l;$i++) {
2314
 
2315
  # get hurl per handle
2316
  $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
 
 
 
 
 
 
 
2317
  $printurl = str_ireplace(array(site_url(), home_url(), 'http:', 'https:'), '', $hurl);
2318
 
2319
  # download, minify, cache
2320
- $tkey = 'css-'.$ctime.'-'.hash('adler32', $handle.$hurl).'.css';
2321
  $json = false; $json = fvm_get_transient($tkey);
2322
  if ( $json === false) {
2323
  $json = fvm_download_and_minify($hurl, null, $disable_css_minification, 'css', $handle);
@@ -2616,7 +2672,7 @@ function fastvelocity_optimizecss($html, $handle, $href, $media){
2616
  if($fvm_fawesome_method == 1 && stripos($href, 'font-awesome') !== false) {
2617
 
2618
  # download, minify, cache
2619
- $tkey = 'css-'.$ctime.'-'.hash('adler32', $handle.$href).'.css';
2620
  $json = false; $json = fvm_get_transient($tkey);
2621
  if ( $json === false) {
2622
  $json = fvm_download_and_minify($href, null, $disable_css_minification, 'css', $handle);
@@ -2645,7 +2701,7 @@ function fastvelocity_optimizecss($html, $handle, $href, $media){
2645
  if(stripos($href, 'fonts.googleapis.com') !== false && $force_inline_googlefonts != false && $css_hide_googlefonts != true && $min_async_googlefonts != true) {
2646
 
2647
  # download, minify, cache
2648
- $tkey = 'css-'.$ctime.'-'.hash('adler32', $handle.$href).'.css';
2649
  $json = false; $json = fvm_get_transient($tkey);
2650
  if ( $json === false) {
2651
  $json = fvm_download_and_minify($href, null, $disable_css_minification, 'css', $handle);
@@ -2683,7 +2739,7 @@ function fastvelocity_optimizecss($html, $handle, $href, $media){
2683
  }
2684
 
2685
  # download, minify, cache
2686
- $tkey = 'css-'.$ctime.'-'.hash('adler32', $handle.$href).'.css';
2687
  $json = false; $json = fvm_get_transient($tkey);
2688
  if ( $json === false) {
2689
  $json = fvm_download_and_minify($href, null, $disable_css_minification, 'css', $handle);
@@ -2927,4 +2983,10 @@ function fastvelocity_get_preload_headers(){
2927
  if($b != $a && file_exists($b)) { return file_get_contents($b); }
2928
 
2929
  return false;
2930
- }
 
 
 
 
 
 
5
  Description: Improve your speed score on GTmetrix, Pingdom Tools and Google PageSpeed Insights by merging and minifying CSS and JavaScript files into groups, compressing HTML and other speed optimizations.
6
  Author: Raul Peixoto
7
  Author URI: http://fastvelocity.com
8
+ Version: 2.6.0
9
  License: GPL2
10
 
11
  ------------------------------------------------------------------------
71
  include($plugindir.'inc/functions.php');
72
  include($plugindir.'inc/functions-serverinfo.php');
73
  include($plugindir.'inc/functions-upgrade.php');
74
+ include($plugindir.'inc/functions-cache.php');
75
 
76
  # wp-cli support
77
  if ( defined( 'WP_CLI' ) && WP_CLI ) {
172
  add_action('admin_init', 'fastvelocity_min_register_settings');
173
 
174
  # This function runs when WordPress updates or installs/remove something
175
+ add_action('upgrader_process_complete', 'fastvelocity_purge_all_global');
176
+ add_action('after_switch_theme', 'fastvelocity_purge_all_global');
 
 
177
  add_action('admin_init', 'fastvelocity_purge_onsave', 1);
178
 
179
  # activation, deactivation
336
  # register plugin settings
337
  function fastvelocity_min_register_settings() {
338
  register_setting('fvm-group', 'fastvelocity_min_enable_purgemenu');
 
339
  register_setting('fvm-group', 'fastvelocity_preserve_settings_on_uninstall');
340
  register_setting('fvm-group', 'fastvelocity_min_default_protocol');
341
  register_setting('fvm-group', 'fastvelocity_min_disable_js_merge');
577
  Admin Bar Purge <span class="note-info">[ If selected, a new option to purge FVM cache from the admin bar will show up ]</span></label>
578
  <br />
579
 
 
 
 
 
 
580
  <label for="fastvelocity_preserve_settings_on_uninstall">
581
  <input name="fastvelocity_preserve_settings_on_uninstall" type="checkbox" id="fastvelocity_preserve_settings_on_uninstall" value="1" <?php echo checked(1 == get_option('fastvelocity_preserve_settings_on_uninstall'), true, false); ?>>
582
  Preserve Settings<span class="note-info">[ If selected, all FVM settings will be preserved, even if you uninstall the plugin ]</span></label>
1207
  foreach( $scripts->to_do as $handle ) :
1208
 
1209
  # is it a footer script?
1210
+ $is_footer = 0;
1211
+ if (isset($wp_scripts->registered[$handle]->extra["group"]) || isset($wp_scripts->registered[$handle]->args)) {
1212
+ $is_footer = 1;
1213
+ }
1214
 
1215
  # skip footer scripts for now
1216
  if($is_footer != 1) {
1218
  # get full url
1219
  $hurl = fastvelocity_min_get_hurl($wp_scripts->registered[$handle]->src, $wp_domain, $wp_home);
1220
 
1221
+ # inlined scripts without file
1222
+ if( empty($hurl)) {
1223
+ continue;
1224
+ }
1225
+
1226
  # Exclude JS files from PSI (Async) takes priority over the ignore list
1227
  if($fvm_min_excludejslist != false || is_array($fvm_min_excludejslist)) {
1228
 
1241
  if($skipjs != false) { continue; }
1242
  }
1243
 
1244
+
1245
  # IE only files don't increment things
1246
  $ieonly = fastvelocity_ie_blacklist($hurl);
1247
  if($ieonly == true) { continue; }
1265
  # make sure that the scripts skipped here, show up in the footer
1266
  } else {
1267
  $hurl = fastvelocity_min_get_hurl($wp_scripts->registered[$handle]->src, $wp_domain, $wp_home);
1268
+
1269
+ # inlined scripts without file
1270
+ if( empty($hurl)) {
1271
+ wp_enqueue_script($handle, false);
1272
+ } else {
1273
+ wp_enqueue_script($handle, $hurl, array(), null, true);
1274
+ }
1275
  }
1276
  endforeach;
1277
 
1284
  $hash = 'header-'.hash('adler32',implode('',$header[$i]['handles']));
1285
 
1286
  # create cache files and urls
1287
+ $file = $cachedir.'/'.$hash.'.min.js';
1288
+ $file_url = fvm_get_protocol($cachedirurl.'/'.$hash.'.min.js');
1289
 
1290
  # generate a new cache file
1291
  clearstatcache();
1301
 
1302
  # get hurl per handle
1303
  $hurl = fastvelocity_min_get_hurl($wp_scripts->registered[$handle]->src, $wp_domain, $wp_home);
1304
+
1305
+ # inlined scripts without file
1306
+ if( empty($hurl)) {
1307
+ continue;
1308
+ }
1309
+
1310
+ # print url
1311
  $printurl = str_ireplace(array(site_url(), home_url(), 'http:', 'https:'), '', $hurl);
1312
 
1313
  # download, minify, cache
1314
+ $tkey = 'js-'.hash('adler32', $handle.$hurl).'.js';
1315
  $json = false; $json = fvm_get_transient($tkey);
1316
  if ( $json === false) {
1317
  $json = fvm_download_and_minify($hurl, null, $disable_js_minification, 'js', $handle);
1425
  # get full url
1426
  $hurl = fastvelocity_min_get_hurl($wp_scripts->registered[$handle]->src, $wp_domain, $wp_home);
1427
 
1428
+ # inlined scripts without file
1429
+ if( empty($hurl)) {
1430
+ continue;
1431
+ }
1432
+
1433
  # Exclude JS files from PSI (Async) takes priority over the ignore list
1434
  if($fvm_min_excludejslist != false || is_array($fvm_min_excludejslist)) {
1435
 
1478
  $hash = 'footer-'.hash('adler32',implode('',$footer[$i]['handles']));
1479
 
1480
  # create cache files and urls
1481
+ $file = $cachedir.'/'.$hash.'.min.js';
1482
+ $file_url = fvm_get_protocol($cachedirurl.'/'.$hash.'.min.js');
1483
 
1484
  # generate a new cache file
1485
  clearstatcache();
1495
 
1496
  # get hurl per handle
1497
  $hurl = fastvelocity_min_get_hurl($wp_scripts->registered[$handle]->src, $wp_domain, $wp_home);
1498
+
1499
+ # inlined scripts without file
1500
+ if( empty($hurl)) {
1501
+ continue;
1502
+ }
1503
+
1504
+ # print url
1505
  $printurl = str_ireplace(array(site_url(), home_url(), 'http:', 'https:'), '', $hurl);
1506
 
1507
 
1508
  # download, minify, cache
1509
+ $tkey = 'js-'.hash('adler32', $handle.$hurl).'.js';
1510
  $json = false; $json = fvm_get_transient($tkey);
1511
  if ( $json === false) {
1512
  $json = fvm_download_and_minify($hurl, null, $disable_js_minification, 'js', $handle);
1739
  # full url or empty
1740
  $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
1741
 
1742
+ # inlined scripts without file
1743
+ if( empty($hurl)) {
1744
+ continue;
1745
+ }
1746
+
1747
  # mark duplicates as done and remove from the queue
1748
  if(!empty($hurl)) {
1749
  $key = hash('adler32', $hurl);
1832
  } elseif($force_inline_googlefonts == true) {
1833
 
1834
  # download, minify, cache
1835
+ $tkey = 'css-'.hash('adler32', $gfurl).'.css';
1836
  $json = false; $json = fvm_get_transient($tkey);
1837
  if ( $json === false) {
1838
  $json = fvm_download_and_minify($gfurl, null, $disable_css_minification, 'css', null);
1958
  $hash = 'header-'.hash('adler32',implode('',$header[$i]['handles']).$inline_css_hash);
1959
 
1960
  # create cache files and urls
1961
+ $file = $cachedir.'/'.$hash.'.min.css';
1962
+ $file_url = fvm_get_protocol($cachedirurl.'/'.$hash.'.min.css');
1963
 
1964
  # generate a new cache file
1965
  clearstatcache();
1975
 
1976
  # get hurl per handle
1977
  $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
1978
+
1979
+ # inlined scripts without file
1980
+ if( empty($hurl)) {
1981
+ continue;
1982
+ }
1983
+
1984
+ # print url
1985
  $printurl = str_ireplace(array(site_url(), home_url(), 'http:', 'https:'), '', $hurl);
1986
 
1987
  # download, minify, cache
1988
+ $tkey = 'css-'.hash('adler32', $handle.$hurl).'.css';
1989
  $json = false; $json = fvm_get_transient($tkey);
1990
  if ( $json === false) {
1991
  $json = fvm_download_and_minify($hurl, null, $disable_css_minification, 'css', $handle);
2122
  # dequeue and get a list of google fonts, or requeue external
2123
  $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
2124
 
2125
+ # inlined scripts without file
2126
+ if( empty($hurl)) {
2127
+ continue;
2128
+ }
2129
+
2130
  if (stripos($hurl, 'fonts.googleapis.com') !== false) {
2131
  wp_dequeue_style($handle);
2132
  if($remove_googlefonts != false) { $done = array_merge($done, array($handle)); continue; } # mark as done if to be removed
2177
  } elseif($force_inline_googlefonts == true) {
2178
 
2179
  # download, minify, cache
2180
+ $tkey = 'css-'.hash('adler32', $gfurl).'.css';
2181
  $json = false; $json = fvm_get_transient($tkey);
2182
  if ( $json === false) {
2183
  $json = fvm_download_and_minify($gfurl, null, $disable_css_minification, 'css', null);
2234
 
2235
  # get full url
2236
  $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
2237
+
2238
+ # inlined scripts without file
2239
+ if( empty($hurl)) {
2240
+ continue;
2241
+ }
2242
+
2243
  # mark duplicates as done and remove from the queue
2244
  if(!empty($hurl)) {
2245
  $key = hash('adler32', $hurl);
2346
  $hash = 'footer-'.hash('adler32',implode('',$footer[$i]['handles']).$inline_css_hash);
2347
 
2348
  # create cache files and urls
2349
+ $file = $cachedir.'/'.$hash.'.min.css';
2350
+ $file_url = fvm_get_protocol($cachedirurl.'/'.$hash.'.min.css');
2351
 
2352
  # generate a new cache file
2353
  clearstatcache();
2363
 
2364
  # get hurl per handle
2365
  $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
2366
+
2367
+ # inlined scripts without file
2368
+ if( empty($hurl)) {
2369
+ continue;
2370
+ }
2371
+
2372
+ # print url
2373
  $printurl = str_ireplace(array(site_url(), home_url(), 'http:', 'https:'), '', $hurl);
2374
 
2375
  # download, minify, cache
2376
+ $tkey = 'css-'.hash('adler32', $handle.$hurl).'.css';
2377
  $json = false; $json = fvm_get_transient($tkey);
2378
  if ( $json === false) {
2379
  $json = fvm_download_and_minify($hurl, null, $disable_css_minification, 'css', $handle);
2672
  if($fvm_fawesome_method == 1 && stripos($href, 'font-awesome') !== false) {
2673
 
2674
  # download, minify, cache
2675
+ $tkey = 'css-'.hash('adler32', $handle.$href).'.css';
2676
  $json = false; $json = fvm_get_transient($tkey);
2677
  if ( $json === false) {
2678
  $json = fvm_download_and_minify($href, null, $disable_css_minification, 'css', $handle);
2701
  if(stripos($href, 'fonts.googleapis.com') !== false && $force_inline_googlefonts != false && $css_hide_googlefonts != true && $min_async_googlefonts != true) {
2702
 
2703
  # download, minify, cache
2704
+ $tkey = 'css-'.hash('adler32', $handle.$href).'.css';
2705
  $json = false; $json = fvm_get_transient($tkey);
2706
  if ( $json === false) {
2707
  $json = fvm_download_and_minify($href, null, $disable_css_minification, 'css', $handle);
2739
  }
2740
 
2741
  # download, minify, cache
2742
+ $tkey = 'css-'.hash('adler32', $handle.$href).'.css';
2743
  $json = false; $json = fvm_get_transient($tkey);
2744
  if ( $json === false) {
2745
  $json = fvm_download_and_minify($href, null, $disable_css_minification, 'css', $handle);
2983
  if($b != $a && file_exists($b)) { return file_get_contents($b); }
2984
 
2985
  return false;
2986
+ }
2987
+
2988
+
2989
+
2990
+ # cron job to delete old FVM cache
2991
+ add_action('fastvelocity_purge_old_cron_event', 'fvm_purge_old');
2992
+
inc/functions-cache.php ADDED
@@ -0,0 +1,366 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ # Fix the permission bits on generated files
5
+ function fastvelocity_fix_permission_bits($file){
6
+ if(function_exists('stat') && fvm_function_available('stat')) {
7
+ if ($stat = @stat(dirname($file))) {
8
+ $perms = $stat['mode'] & 0007777;
9
+ @chmod($file, $perms);
10
+ clearstatcache();
11
+ return true;
12
+ }
13
+ }
14
+
15
+
16
+ # get permissions from parent directory
17
+ $perms = 0777;
18
+ if(function_exists('stat') && fvm_function_available('stat')) {
19
+ if ($stat = @stat(dirname($file))) { $perms = $stat['mode'] & 0007777; }
20
+ }
21
+
22
+ if (file_exists($file)){
23
+ if ($perms != ($perms & ~umask())){
24
+ $folder_parts = explode( '/', substr( $file, strlen(dirname($file)) + 1 ) );
25
+ for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
26
+ @chmod(dirname($file) . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $perms );
27
+ }
28
+ }
29
+ }
30
+
31
+ return true;
32
+ }
33
+
34
+
35
+ # get cache directories and urls
36
+ function fvm_cachepath() {
37
+
38
+ # custom directory
39
+ $fvm_change_cache_path = get_option('fastvelocity_min_change_cache_path');
40
+ $fvm_change_cache_base = get_option('fastvelocity_min_change_cache_base_url');
41
+ $upload = array();
42
+ if($fvm_change_cache_path !== false && $fvm_change_cache_base !== false && strlen($fvm_change_cache_path) > 1) {
43
+ $upload['basedir'] = trim($fvm_change_cache_path);
44
+ $upload['baseurl'] = trim($fvm_change_cache_base);
45
+ } else {
46
+ $up = wp_upload_dir(); # default
47
+
48
+ # upload path for multisite
49
+ $upload['basedir'] = rtrim($up['basedir']);
50
+ $upload['baseurl'] = rtrim($up['baseurl']);
51
+
52
+ # for single sites, change to the cache directory
53
+ if(basename($up['basedir']) == 'uploads') {
54
+ $upload['basedir'] = dirname($upload['basedir']);
55
+ $upload['baseurl'] = dirname($upload['baseurl']);
56
+ }
57
+
58
+ }
59
+
60
+ # last update or zero
61
+ $ctime = get_option('fvm-last-cache-update', '0');
62
+
63
+ # create
64
+ $uploadsdir = $upload['basedir'].'/cache';
65
+ $uploadsurl = $upload['baseurl'].'/cache';
66
+ $cachebase = $uploadsdir.'/fvm/'.$ctime;
67
+ $cachebaseurl = $uploadsurl.'/fvm/'.$ctime;
68
+ $cachedir = $cachebase.'/out';
69
+ $tmpdir = $cachebase.'/tmp';
70
+ $headerdir = $cachebase.'/header';
71
+ $cachedirurl = $cachebaseurl.'/out';
72
+
73
+ # get permissions from uploads directory
74
+ $dir_perms = 0777;
75
+ if(is_dir($uploadsdir.'/cache') && function_exists('stat') && fvm_function_available('stat')) {
76
+ if ($stat = @stat($uploadsdir.'/cache')) { $dir_perms = $stat['mode'] & 0007777; }
77
+ }
78
+
79
+ # mkdir and check if umask requires chmod
80
+ $dirs = array($cachebase, $cachedir, $tmpdir, $headerdir);
81
+ foreach ($dirs as $target) {
82
+ if(!is_dir($target)) {
83
+ if (@mkdir($target, $dir_perms, true)){
84
+ if ($dir_perms != ($dir_perms & ~umask())){
85
+ $folder_parts = explode( '/', substr($target, strlen(dirname($target)) + 1 ));
86
+ for ($i = 1, $c = count($folder_parts ); $i <= $c; $i++){
87
+ @chmod(dirname($target) . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
88
+ }
89
+ }
90
+ } else {
91
+ # fallback
92
+ wp_mkdir_p($target);
93
+ }
94
+ }
95
+ }
96
+
97
+ # return
98
+ return array('cachebase'=>$cachebase,'tmpdir'=>$tmpdir, 'cachedir'=>$cachedir, 'cachedirurl'=>$cachedirurl, 'headerdir'=>$headerdir);
99
+ }
100
+
101
+
102
+
103
+ # increment file names
104
+ function fvm_cache_increment() {
105
+ update_option('fvm-last-cache-update', time());
106
+ }
107
+
108
+ # will delete temporary intermediate stuff but leave final css/js alone for compatibility
109
+ function fvm_purge_all() {
110
+
111
+ # get cache directories and urls
112
+ $cachepath = fvm_cachepath();
113
+ $tmpdir = $cachepath['tmpdir'];
114
+ $headerdir = $cachepath['headerdir'];
115
+
116
+ # increment cache file names
117
+ fvm_cache_increment();
118
+
119
+ # delete temporary directories only
120
+ if(is_dir($tmpdir)) { fastvelocity_rrmdir($tmpdir); }
121
+ if(is_dir($headerdir)) { fastvelocity_rrmdir($headerdir); }
122
+
123
+ # extra hook for developers
124
+ do_action('fvm_after_purge_all');
125
+ return true;
126
+ }
127
+
128
+
129
+ # purge all public files on uninstall
130
+ function fvm_purge_all_uninstall() {
131
+ $cachepath = fvm_cachepath();
132
+ $cachebaseparent = dirname($cachepath['cachebase']);
133
+ if(is_dir($cachebaseparent)) { fastvelocity_rrmdir($cachebaseparent); }
134
+ return true;
135
+ }
136
+
137
+ # purge cache files older than 3 months
138
+ fvm_purge_old();
139
+ function fvm_purge_old() {
140
+
141
+ # get cache directories and urls
142
+ $cachepath = fvm_cachepath();
143
+ $cachebaseparent = dirname($cachepath['cachebase']);
144
+ $ctime = get_option('fvm-last-cache-update', '0');
145
+ $expires = time() - 86400 * 90; # three months
146
+
147
+ # get all directories that are a direct child of current directory
148
+ if ($handle = opendir($cachebaseparent)) {
149
+ while (false !== ($d = readdir($handle))) {
150
+ if (strcmp($d, '.')==0 || strcmp($d, '..')==0) { continue; }
151
+ if($d != $ctime && (is_numeric($d) && $d <= $expires)) {
152
+ $dir = $cachebaseparent.'/'.$d;
153
+ if(is_dir($dir)) {
154
+ fastvelocity_rrmdir($dir);
155
+ rmdir($dir);
156
+ }
157
+ }
158
+
159
+ }
160
+
161
+ closedir($handle);
162
+ }
163
+
164
+ return true;
165
+ }
166
+
167
+
168
+ # purge temp cache on save settings
169
+ function fastvelocity_purge_onsave() {
170
+ if(current_user_can( 'manage_options') && isset($_POST['fastvelocity_min_save_options'])) {
171
+ fvm_purge_all();
172
+ fvm_purge_others();
173
+ }
174
+ }
175
+
176
+
177
+ # purge temp cache globally, after updates
178
+ function fastvelocity_purge_all_global() {
179
+ if(current_user_can( 'manage_options')) {
180
+ fvm_purge_all();
181
+ fvm_purge_others();
182
+ }
183
+ }
184
+
185
+
186
+ # get transients on the disk
187
+ function fvm_get_transient($key) {
188
+ $cachepath = fvm_cachepath();
189
+ $tmpdir = $cachepath['tmpdir'];
190
+ $f = $tmpdir.'/'.$key.'.transient';
191
+ clearstatcache();
192
+ if(file_exists($f)) {
193
+ return file_get_contents($f);
194
+ } else {
195
+ return false;
196
+ }
197
+ }
198
+
199
+ # set cache on disk
200
+ function fvm_set_transient($key, $code) {
201
+ if(is_null($code) || empty($code)) { return false; }
202
+ $cachepath = fvm_cachepath();
203
+ $tmpdir = $cachepath['tmpdir'];
204
+ $f = $tmpdir.'/'.$key.'.transient';
205
+ file_put_contents($f, $code);
206
+ fastvelocity_fix_permission_bits($f);
207
+ return true;
208
+ }
209
+
210
+
211
+
212
+ # get cache size and count
213
+ function fastvelocity_get_cachestats() {
214
+ clearstatcache();
215
+ $cachepath = fvm_cachepath();
216
+ $cachedir = $cachepath['cachedir'];
217
+ if(is_dir($cachedir)) {
218
+ $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cachedir, FilesystemIterator::SKIP_DOTS));
219
+ $size = 0;
220
+ foreach ($dir as $file) {
221
+ $size += $file->getSize();
222
+ }
223
+ return fastvelocity_format_filesize($size);
224
+ } else {
225
+ return 'Error: '.$cachedir. ' is not a directory!';
226
+ }
227
+ }
228
+
229
+ # remove all cache files
230
+ function fastvelocity_rrmdir($path) {
231
+ # purge
232
+ clearstatcache();
233
+ if(is_dir($path)) {
234
+ $i = new DirectoryIterator($path);
235
+ foreach($i as $f){
236
+ if($f->isFile()){ unlink($f->getRealPath());
237
+ } else if(!$f->isDot() && $f->isDir()){
238
+ fastvelocity_rrmdir($f->getRealPath());
239
+ rmdir($f->getRealPath());
240
+ }
241
+ }
242
+ }
243
+ }
244
+
245
+
246
+ # return size in human format
247
+ function fastvelocity_format_filesize($bytes, $decimals = 2) {
248
+ $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' );
249
+ for ($i = 0; ($bytes / 1024) > 0.9; $i++, $bytes /= 1024) {}
250
+ return sprintf( "%1.{$decimals}f %s", round( $bytes, $decimals ), $units[$i] );
251
+ }
252
+
253
+
254
+ # Purge Godaddy Managed WordPress Hosting (Varnish)
255
+ # https://github.com/wp-media/wp-rocket/blob/master/inc/3rd-party/hosting/godaddy.php
256
+ function fastvelocity_godaddy_request( $method, $url = null ) {
257
+ $url = empty( $url ) ? home_url() : $url;
258
+ $host = parse_url( $url, PHP_URL_HOST );
259
+ $url = set_url_scheme( str_replace( $host, WPaas\Plugin::vip(), $url ), 'http' );
260
+ wp_cache_flush();
261
+ update_option( 'gd_system_last_cache_flush', time() ); # purge apc
262
+ wp_remote_request( esc_url_raw( $url ), array('method' => $method, 'blocking' => false, 'headers' => array('Host' => $host)) );
263
+ }
264
+
265
+
266
+ # purge supported hosting and plugins
267
+ function fvm_purge_others(){
268
+
269
+ # wordpress default cache
270
+ if (function_exists('wp_cache_flush')) {
271
+ wp_cache_flush();
272
+ }
273
+
274
+ # Purge all W3 Total Cache
275
+ if (function_exists('w3tc_pgcache_flush')) {
276
+ w3tc_pgcache_flush();
277
+ return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>W3 Total Cache</strong> have also been purged.</p></div>');
278
+ }
279
+
280
+ # Purge WP Super Cache
281
+ if (function_exists('wp_cache_clear_cache')) {
282
+ wp_cache_clear_cache();
283
+ return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>WP Super Cache</strong> have also been purged.</p></div>');
284
+ }
285
+
286
+ # Purge WP Rocket
287
+ if (function_exists('rocket_clean_domain')) {
288
+ rocket_clean_domain();
289
+ return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>WP Rocket</strong> have also been purged.</p></div>');
290
+ }
291
+
292
+ # Purge Wp Fastest Cache
293
+ if(isset($GLOBALS['wp_fastest_cache']) && method_exists($GLOBALS['wp_fastest_cache'], 'deleteCache')){
294
+ $GLOBALS['wp_fastest_cache']->deleteCache();
295
+ return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>Wp Fastest Cache</strong> have also been purged.</p></div>');
296
+ }
297
+
298
+ # Purge Cachify
299
+ if (function_exists('cachify_flush_cache')) {
300
+ cachify_flush_cache();
301
+ return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>Cachify</strong> have also been purged.</p></div>');
302
+ }
303
+
304
+ # Purge Comet Cache
305
+ if ( class_exists("comet_cache") ) {
306
+ comet_cache::clear();
307
+ return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>Comet Cache</strong> have also been purged.</p></div>');
308
+ }
309
+
310
+ # Purge Zen Cache
311
+ if ( class_exists("zencache") ) {
312
+ zencache::clear();
313
+ return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>Comet Cache</strong> have also been purged.</p></div>');
314
+ }
315
+
316
+ # Purge LiteSpeed Cache
317
+ if (class_exists('LiteSpeed_Cache_Tags')) {
318
+ LiteSpeed_Cache_Tags::add_purge_tag('*');
319
+ return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>LiteSpeed Cache</strong> have also been purged.</p></div>');
320
+ }
321
+
322
+ # Purge SG Optimizer
323
+ if (function_exists('sg_cachepress_purge_cache')) {
324
+ sg_cachepress_purge_cache();
325
+ return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>SG Optimizer</strong> have also been purged.</p></div>');
326
+ }
327
+
328
+ # Purge Hyper Cache
329
+ if (function_exists('hyper_cache_flush_all')) {
330
+ hyper_cache_flush_all();
331
+ return __( '<div class="notice notice-info is-dismissible"><p>All caches from <strong>HyperCache</strong> have also been purged.</p></div>');
332
+ }
333
+
334
+ # Purge Godaddy Managed WordPress Hosting (Varnish + APC)
335
+ if (class_exists('WPaaS\Plugin')) {
336
+ fastvelocity_godaddy_request('BAN');
337
+ return __('<div class="notice notice-info is-dismissible"><p>A cache purge request has been sent to <strong>Go Daddy Varnish</strong></p></div><div class="notice notice-info is-dismissible"><p>Please note that it may not work 100% of the time, due to cache rate limiting by your host!</p></div>');
338
+ }
339
+
340
+ # purge cache enabler
341
+ if ( has_action('ce_clear_cache') ) {
342
+ do_action('ce_clear_cache');
343
+ return __( '<div class="notice notice-info is-dismissible"><p>All caches from <strong>Cache Enabler</strong> have also been purged.</p></div>');
344
+ }
345
+
346
+
347
+ # Purge WP Engine
348
+ if (class_exists("WpeCommon")) {
349
+ if (method_exists('WpeCommon', 'purge_memcached')) { WpeCommon::purge_memcached(); }
350
+ if (method_exists('WpeCommon', 'clear_maxcdn_cache')) { WpeCommon::clear_maxcdn_cache(); }
351
+ if (method_exists('WpeCommon', 'purge_varnish_cache')) { WpeCommon::purge_varnish_cache(); }
352
+
353
+ if (method_exists('WpeCommon', 'purge_memcached') || method_exists('WpeCommon', 'clear_maxcdn_cache') || method_exists('WpeCommon', 'purge_varnish_cache')) {
354
+ return __('<div class="notice notice-info is-dismissible"><p>A cache purge request has been sent to <strong>WP Engine</strong></p></div><div class="notice notice-info is-dismissible"><p>Please note that it may not work 100% of the time, due to cache rate limiting by your host!</p></div>');
355
+ }
356
+ }
357
+
358
+ # add breeze cache purge support
359
+ if (class_exists("Breeze_PurgeCache")) {
360
+ Breeze_PurgeCache::breeze_cache_flush();
361
+ return __( '<div class="notice notice-info is-dismissible"><p>All caches from <strong>Breeze</strong> have also been purged.</p></div>');
362
+ }
363
+
364
+ }
365
+
366
+
inc/functions-upgrade.php CHANGED
@@ -7,7 +7,7 @@ function fastvelocity_version_check() {
7
  $ver = get_option("fastvelocity_plugin_version");
8
  if ($ver == false) { $ver = '0.0.0'; }
9
 
10
- # save on upgrade
11
  if ($ver != $fastvelocity_plugin_version) {
12
  update_option( "fastvelocity_plugin_version", $fastvelocity_plugin_version);
13
  }
@@ -43,7 +43,17 @@ function fastvelocity_version_check() {
43
  }
44
 
45
  }
46
-
 
 
 
 
 
 
 
 
 
 
47
  }
48
  add_action( 'plugins_loaded', 'fastvelocity_version_check' );
49
 
7
  $ver = get_option("fastvelocity_plugin_version");
8
  if ($ver == false) { $ver = '0.0.0'; }
9
 
10
+ # save current version on upgrade
11
  if ($ver != $fastvelocity_plugin_version) {
12
  update_option( "fastvelocity_plugin_version", $fastvelocity_plugin_version);
13
  }
43
  }
44
 
45
  }
46
+
47
+
48
+ # changed on 2.6.0
49
+ if($dots[0] < 2 || ($dots[0] == 2 && $dots[1] < 6)) {
50
+
51
+ # add old cache purge event cron
52
+ if (!wp_next_scheduled ('fastvelocity_purge_old_cron')) {
53
+ wp_schedule_event(time(), 'daily', 'fastvelocity_purge_old_cron_event');
54
+ }
55
+
56
+ }
57
  }
58
  add_action( 'plugins_loaded', 'fastvelocity_version_check' );
59
 
inc/functions.php CHANGED
@@ -42,98 +42,22 @@ function fvm_function_available($func) {
42
  return true;
43
  }
44
 
45
- # Fix the permission bits on generated files
46
- function fastvelocity_fix_permission_bits($file){
47
- if(function_exists('stat') && fvm_function_available('stat')) {
48
- if ($stat = @stat(dirname($file))) {
49
- $perms = $stat['mode'] & 0007777;
50
- @chmod($file, $perms);
51
- clearstatcache();
52
- return true;
53
- }
54
- }
55
 
 
 
56
 
57
- # get permissions from parent directory
58
- $perms = 0777;
59
- if(function_exists('stat') && fvm_function_available('stat')) {
60
- if ($stat = @stat(dirname($file))) { $perms = $stat['mode'] & 0007777; }
61
  }
62
 
63
- if (file_exists($file)){
64
- if ($perms != ($perms & ~umask())){
65
- $folder_parts = explode( '/', substr( $file, strlen(dirname($file)) + 1 ) );
66
- for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
67
- @chmod(dirname($file) . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $perms );
68
- }
69
- }
70
- }
71
-
72
- return true;
73
- }
74
-
75
-
76
- # get cache directories and urls
77
- function fvm_cachepath() {
78
-
79
- # custom directory
80
- $fvm_change_cache_path = get_option('fastvelocity_min_change_cache_path');
81
- $fvm_change_cache_base = get_option('fastvelocity_min_change_cache_base_url');
82
- $upload = array();
83
- if($fvm_change_cache_path !== false && $fvm_change_cache_base !== false && strlen($fvm_change_cache_path) > 1) {
84
- $upload['basedir'] = trim($fvm_change_cache_path);
85
- $upload['baseurl'] = trim($fvm_change_cache_base);
86
- } else {
87
- $upload = wp_upload_dir(); # default
88
- }
89
-
90
- # create
91
- $uploadsdir = rtrim($upload['basedir'], '/');
92
- $uploadsurl = rtrim($upload['baseurl'], '/');
93
- $cachebase = $uploadsdir.'/fvm';
94
- $cachedir = $uploadsdir.'/fvm/out';
95
- $tmpdir = $uploadsdir.'/fvm/tmp';
96
- $cachedirurl = $uploadsurl.'/fvm/out';
97
- $headerdir = $uploadsdir.'/fvm/header';
98
-
99
- # get permissions from uploads directory
100
- $dir_perms = 0777;
101
- if(function_exists('stat') && fvm_function_available('stat')) {
102
- if ($stat = @stat($uploadsdir)) { $dir_perms = $stat['mode'] & 0007777; }
103
- }
104
-
105
- # mkdir and check if umask requires chmod
106
- $dirs = array($cachebase, $cachedir, $tmpdir, $headerdir);
107
- foreach ($dirs as $target) {
108
- if(!is_dir($target)) {
109
- if (@mkdir($target, $dir_perms, true)){
110
- if ($dir_perms != ($dir_perms & ~umask())){
111
- $folder_parts = explode( '/', substr($target, strlen(dirname($target)) + 1 ));
112
- for ($i = 1, $c = count($folder_parts ); $i <= $c; $i++){
113
- @chmod(dirname($target) . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
114
- }
115
- }
116
- } else {
117
- # fallback
118
- wp_mkdir_p($target);
119
- }
120
- }
121
- }
122
-
123
- # return
124
- return array('cachebase'=>$cachebase,'tmpdir'=>$tmpdir, 'cachedir'=>$cachedir, 'cachedirurl'=>$cachedirurl, 'headerdir'=>$headerdir);
125
- }
126
-
127
-
128
- # run during activation
129
- function fastvelocity_plugin_activate() {
130
 
131
  # setup defaults if no option to preserve exists
132
  if(get_option('fastvelocity_preserve_settings_on_uninstall') == false) {
133
 
134
- # increment time
135
- fvm_cache_increment();
136
-
137
  # default options to enable (1)
138
  $options_enable_default = array('fastvelocity_min_remove_print_mediatypes', 'fastvelocity_fvm_clean_header_one', 'fastvelocity_min_skip_google_fonts', 'fastvelocity_min_force_inline_css_footer', 'fastvelocity_min_skip_cssorder', 'fastvelocity_gfonts_method', 'fastvelocity_fontawesome_method', 'fastvelocity_min_disable_css_inline_merge');
139
  foreach($options_enable_default as $option) {
@@ -153,8 +77,17 @@ function fastvelocity_plugin_activate() {
153
 
154
  # run during deactivation
155
  function fastvelocity_plugin_deactivate() {
 
 
156
  fvm_purge_all();
157
  fvm_purge_others();
 
 
 
 
 
 
 
158
  }
159
 
160
  # run during uninstall
@@ -169,6 +102,12 @@ function fastvelocity_plugin_uninstall() {
169
  if(is_array($plugin_options) && count($plugin_options) > 0) {
170
  foreach( $plugin_options as $option ) { delete_option( $option->option_name ); }
171
  }
 
 
 
 
 
 
172
 
173
  }
174
  }
@@ -401,48 +340,6 @@ function fastvelocity_min_html_compression_start() {
401
  }
402
 
403
 
404
- # remove all cache files
405
- function fastvelocity_rrmdir($path) {
406
- # purge
407
- clearstatcache();
408
- if(is_dir($path)) {
409
- $i = new DirectoryIterator($path);
410
- foreach($i as $f){
411
- if($f->isFile()){ unlink($f->getRealPath());
412
- } else if(!$f->isDot() && $f->isDir()){
413
- fastvelocity_rrmdir($f->getRealPath());
414
- rmdir($f->getRealPath());
415
- }
416
- }
417
- }
418
- }
419
-
420
-
421
- # return size in human format
422
- function fastvelocity_format_filesize($bytes, $decimals = 2) {
423
- $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' );
424
- for ($i = 0; ($bytes / 1024) > 0.9; $i++, $bytes /= 1024) {}
425
- return sprintf( "%1.{$decimals}f %s", round( $bytes, $decimals ), $units[$i] );
426
- }
427
-
428
-
429
- # get cache size and count
430
- function fastvelocity_get_cachestats() {
431
- clearstatcache();
432
- $cachepath = fvm_cachepath();
433
- $cachebase = $cachepath['cachebase'];
434
- if(is_dir($cachebase)) {
435
- $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cachebase, FilesystemIterator::SKIP_DOTS));
436
- $size = 0;
437
- foreach ($dir as $file) {
438
- $size += $file->getSize();
439
- }
440
- return fastvelocity_format_filesize($size);
441
- } else {
442
- return 'Error: '.$cachebase. ' is not a directory!';
443
- }
444
- }
445
-
446
  # remove default HTTP headers
447
  function fastvelocity_remove_redundant_shortlink() {
448
  remove_action('wp_head', 'wp_shortlink_wp_head', 10);
@@ -862,71 +759,7 @@ function fvm_get_protocol($url) {
862
  }
863
 
864
 
865
- # increment file names
866
- function fvm_cache_increment() {
867
- update_option('fvm-last-cache-update', time());
868
- }
869
 
870
- # purge all caches
871
- function fvm_purge_all() {
872
-
873
- # get cache directories and urls
874
- $cachepath = fvm_cachepath();
875
- $cachebase = $cachepath['cachebase'];
876
- $tmpdir = $cachepath['tmpdir'];
877
-
878
- # delete minification files and transients
879
- if(!is_dir($cachebase)) {
880
- return false;
881
- }
882
-
883
- # preserve cache, or delete temp only
884
- if(!get_option('fastvelocity_min_preserve_oldcache')) {
885
- fastvelocity_rrmdir($cachebase);
886
- } else {
887
- if(is_dir($tmpdir)) {
888
- fastvelocity_rrmdir($tmpdir);
889
- return true;
890
- }
891
- }
892
-
893
- fvm_cache_increment();
894
- do_action('fvm_after_purge_all');
895
- return true;
896
- }
897
-
898
-
899
- # purge temp cache on save settings
900
- function fastvelocity_purge_onsave() {
901
- if(current_user_can( 'manage_options') && isset($_POST['fastvelocity_min_save_options'])) {
902
- fvm_purge_all();
903
- fvm_purge_others();
904
- }
905
- }
906
-
907
- # get transients on the disk
908
- function fvm_get_transient($key) {
909
- $cachepath = fvm_cachepath();
910
- $tmpdir = $cachepath['tmpdir'];
911
- $f = $tmpdir.'/'.$key.'.transient';
912
- clearstatcache();
913
- if(file_exists($f)) {
914
- return file_get_contents($f);
915
- } else {
916
- return false;
917
- }
918
- }
919
-
920
- # set cache on disk
921
- function fvm_set_transient($key, $code) {
922
- if(is_null($code) || empty($code)) { return false; }
923
- $cachepath = fvm_cachepath();
924
- $tmpdir = $cachepath['tmpdir'];
925
- $f = $tmpdir.'/'.$key.'.transient';
926
- file_put_contents($f, $code);
927
- fastvelocity_fix_permission_bits($f);
928
- return true;
929
- }
930
 
931
 
932
  # generate ascii slug
@@ -1047,118 +880,6 @@ function fastvelocity_download($url) {
1047
  }
1048
 
1049
 
1050
- # Purge Godaddy Managed WordPress Hosting (Varnish)
1051
- # https://github.com/wp-media/wp-rocket/blob/master/inc/3rd-party/hosting/godaddy.php
1052
- function fastvelocity_godaddy_request( $method, $url = null ) {
1053
- $url = empty( $url ) ? home_url() : $url;
1054
- $host = parse_url( $url, PHP_URL_HOST );
1055
- $url = set_url_scheme( str_replace( $host, WPaas\Plugin::vip(), $url ), 'http' );
1056
- wp_cache_flush();
1057
- update_option( 'gd_system_last_cache_flush', time() ); # purge apc
1058
- wp_remote_request( esc_url_raw( $url ), array('method' => $method, 'blocking' => false, 'headers' => array('Host' => $host)) );
1059
- }
1060
-
1061
-
1062
- function fvm_purge_others(){
1063
-
1064
- # wordpress default cache
1065
- if (function_exists('wp_cache_flush')) {
1066
- wp_cache_flush();
1067
- }
1068
-
1069
- # Purge all W3 Total Cache
1070
- if (function_exists('w3tc_pgcache_flush')) {
1071
- w3tc_pgcache_flush();
1072
- return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>W3 Total Cache</strong> have also been purged.</p></div>');
1073
- }
1074
 
1075
- # Purge WP Super Cache
1076
- if (function_exists('wp_cache_clear_cache')) {
1077
- wp_cache_clear_cache();
1078
- return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>WP Super Cache</strong> have also been purged.</p></div>');
1079
- }
1080
-
1081
- # Purge WP Rocket
1082
- if (function_exists('rocket_clean_domain')) {
1083
- rocket_clean_domain();
1084
- return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>WP Rocket</strong> have also been purged.</p></div>');
1085
- }
1086
-
1087
- # Purge Wp Fastest Cache
1088
- if(isset($GLOBALS['wp_fastest_cache']) && method_exists($GLOBALS['wp_fastest_cache'], 'deleteCache')){
1089
- $GLOBALS['wp_fastest_cache']->deleteCache();
1090
- return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>Wp Fastest Cache</strong> have also been purged.</p></div>');
1091
- }
1092
-
1093
- # Purge Cachify
1094
- if (function_exists('cachify_flush_cache')) {
1095
- cachify_flush_cache();
1096
- return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>Cachify</strong> have also been purged.</p></div>');
1097
- }
1098
-
1099
- # Purge Comet Cache
1100
- if ( class_exists("comet_cache") ) {
1101
- comet_cache::clear();
1102
- return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>Comet Cache</strong> have also been purged.</p></div>');
1103
- }
1104
-
1105
- # Purge Zen Cache
1106
- if ( class_exists("zencache") ) {
1107
- zencache::clear();
1108
- return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>Comet Cache</strong> have also been purged.</p></div>');
1109
- }
1110
-
1111
- # Purge LiteSpeed Cache
1112
- if (class_exists('LiteSpeed_Cache_Tags')) {
1113
- LiteSpeed_Cache_Tags::add_purge_tag('*');
1114
- return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>LiteSpeed Cache</strong> have also been purged.</p></div>');
1115
- }
1116
-
1117
- # Purge SG Optimizer
1118
- if (function_exists('sg_cachepress_purge_cache')) {
1119
- sg_cachepress_purge_cache();
1120
- return __('<div class="notice notice-info is-dismissible"><p>All caches from <strong>SG Optimizer</strong> have also been purged.</p></div>');
1121
- }
1122
-
1123
- # Purge Hyper Cache
1124
- if (class_exists( 'HyperCache' )) {
1125
- do_action( 'autoptimize_action_cachepurged' );
1126
- return __( '<div class="notice notice-info is-dismissible"><p>All caches from <strong>HyperCache</strong> have also been purged.</p></div>');
1127
- }
1128
-
1129
- # Purge Godaddy Managed WordPress Hosting (Varnish + APC)
1130
- if (class_exists('WPaaS\Plugin')) {
1131
- fastvelocity_godaddy_request('BAN');
1132
- return __('<div class="notice notice-info is-dismissible"><p>A cache purge request has been sent to <strong>Go Daddy Varnish</strong></p></div><div class="notice notice-info is-dismissible"><p>Please note that it may not work 100% of the time, due to cache rate limiting by your host!</p></div>');
1133
- }
1134
-
1135
- # purge cache enabler
1136
- if ( has_action('ce_clear_cache') ) {
1137
- do_action('ce_clear_cache');
1138
- return __( '<div class="notice notice-info is-dismissible"><p>All caches from <strong>Cache Enabler</strong> have also been purged.</p></div>');
1139
- }
1140
-
1141
-
1142
- # Purge WP Engine
1143
- if (class_exists("WpeCommon")) {
1144
- if (method_exists('WpeCommon', 'purge_memcached')) { WpeCommon::purge_memcached(); }
1145
- if (method_exists('WpeCommon', 'clear_maxcdn_cache')) { WpeCommon::clear_maxcdn_cache(); }
1146
- if (method_exists('WpeCommon', 'purge_varnish_cache')) { WpeCommon::purge_varnish_cache(); }
1147
-
1148
- if (method_exists('WpeCommon', 'purge_memcached') || method_exists('WpeCommon', 'clear_maxcdn_cache') || method_exists('WpeCommon', 'purge_varnish_cache')) {
1149
- return __('<div class="notice notice-info is-dismissible"><p>A cache purge request has been sent to <strong>WP Engine</strong></p></div><div class="notice notice-info is-dismissible"><p>Please note that it may not work 100% of the time, due to cache rate limiting by your host!</p></div>');
1150
- }
1151
- }
1152
-
1153
- # add breeze cache purge support
1154
- add_action('fvm_after_purge_all', 'extra_fvm_purge_breeze_support');
1155
- function extra_fvm_purge_breeze_support() {
1156
- if (class_exists("Breeze_PurgeCache")) {
1157
- Breeze_PurgeCache::breeze_cache_flush();
1158
- return __( '<div class="notice notice-info is-dismissible"><p>All caches from <strong>Breeze</strong> have also been purged.</p></div>');
1159
- }
1160
- }
1161
-
1162
- }
1163
 
1164
 
42
  return true;
43
  }
44
 
45
+
46
+ # run during activation
47
+ function fastvelocity_plugin_activate() {
 
 
 
 
 
 
 
48
 
49
+ # increment cache time
50
+ fvm_cache_increment();
51
 
52
+ # old cache purge event cron
53
+ if (!wp_next_scheduled ('fastvelocity_purge_old_cron')) {
54
+ wp_schedule_event(time(), 'daily', 'fastvelocity_purge_old_cron_event');
 
55
  }
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  # setup defaults if no option to preserve exists
59
  if(get_option('fastvelocity_preserve_settings_on_uninstall') == false) {
60
 
 
 
 
61
  # default options to enable (1)
62
  $options_enable_default = array('fastvelocity_min_remove_print_mediatypes', 'fastvelocity_fvm_clean_header_one', 'fastvelocity_min_skip_google_fonts', 'fastvelocity_min_force_inline_css_footer', 'fastvelocity_min_skip_cssorder', 'fastvelocity_gfonts_method', 'fastvelocity_fontawesome_method', 'fastvelocity_min_disable_css_inline_merge');
63
  foreach($options_enable_default as $option) {
77
 
78
  # run during deactivation
79
  function fastvelocity_plugin_deactivate() {
80
+
81
+ # remove all on deactivation
82
  fvm_purge_all();
83
  fvm_purge_others();
84
+
85
+ # old cache purge event cron
86
+ if (wp_next_scheduled ('fastvelocity_purge_old_cron')) {
87
+ $timestamp = wp_next_scheduled ('fastvelocity_purge_old_cron');
88
+ wp_unschedule_event ($timestamp, 'fastvelocity_purge_old_cron_event');
89
+ }
90
+
91
  }
92
 
93
  # run during uninstall
102
  if(is_array($plugin_options) && count($plugin_options) > 0) {
103
  foreach( $plugin_options as $option ) { delete_option( $option->option_name ); }
104
  }
105
+
106
+ # purge all caches
107
+ if(function_exists('fvm_purge_all_uninstall') && function_exists('fvm_purge_others')) {
108
+ fvm_purge_all_uninstall();
109
+ fvm_purge_others();
110
+ }
111
 
112
  }
113
  }
340
  }
341
 
342
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
343
  # remove default HTTP headers
344
  function fastvelocity_remove_redundant_shortlink() {
345
  remove_action('wp_head', 'wp_shortlink_wp_head', 10);
759
  }
760
 
761
 
 
 
 
 
762
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
763
 
764
 
765
  # generate ascii slug
880
  }
881
 
882
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
883
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
884
 
885
 
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: Alignak
3
  Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, CSS Merging, JS Merging, CSS Minification, JS Minification, Speed Optimization, HTML Minification, Performance, Optimization, Speed, Fast
4
  Requires at least: 4.5
5
- Stable tag: 2.5.9
6
  Tested up to: 5.1
7
  License: GPLv3 or later
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -83,54 +83,44 @@ I can offer you aditional `custom made` optimization on top of this plugin. If y
83
  == Frequently Asked Questions ==
84
 
85
  = Can I update plugins and themes after installing FVM? =
86
-
87
- Yes. FVM doesn't touch your original files, it merely copies them to the uploads directory and merges them together with minification. If you install new plugins, update or change themes, FVM will purge its cache as well as some of the most popular cache plugins. It's recommended that you purge your page cache on the server "after" purging Fast Velocity Minify, if you have some cache on the server side.
88
 
89
  = After installing, why did my site feels slow to load? =
90
-
91
  Please see the question below.
92
 
93
-
94
  = Why are there lots of JS and CSS files listed on the status page and why is the cache directory taking so much space? =
95
-
96
- Beware! Some themes combine CSS using PHP with a query string that changes on every pageload... (this is bad practice). When FVM sees a different url being enqueued, it will consider that as a new file and try to create a new set of files on every pageview too. You must exclude that dynamic url via the Ignore List on FVM for your cache to be efficient and stop growing. Also note, if your pages enqueue different styles and javascript in different pages, that is "one set" of files to be merged.
97
 
98
 
99
- = How can I exclude certain assets by wildcard? =
100
-
101
- Each line on the ignore list will try to match a substring against all CSS or JS files, for example `//yoursite.com/wp-content/plugins/some-plugin/js/` will ignore all files inside that directory. You can also shorten the URL like `/some-plugin/js/` and then it will match any css or js URL that has `/some-plugin/js/` on the path. Obviously, doing `/js/` would match any files inside any "/js/" directory and in any location, so to avoid unexpected situations please always use the longest, most specific path you can use.
102
 
103
 
104
  = Why is the ignore list not working? =
105
-
106
- The ignore list "is" working, just try to use partial paths (see wildcard help above) and use relative urls only without any query vars.
107
 
108
 
109
  = Is it compatible with other caching plugins? =
 
110
 
111
- Please note, you must disable any features on your theme or cache plugins, which perform minification of css, html and js. Double minification not only slows the whole process, but also has the high potential of causing conflicts in javascript. The plugin will try to automatically purge several popular cache plugins, however if you have a cache on the server side (some hosting services have this) you may need to purge it manually, after you purge FVM. The automatic purge is active for the following plugins and hosting: W3 Total Cache, WP Supercache, WP Rocket, Wp Fastest Cache, Cachify, Comet Cache, Zen Cache, LiteSpeed Cache, Cache Enabler, SG Optimizer, Breeze (Cloudways), Godaddy Managed WordPress Hosting and WP Engine
112
 
113
  = Do you recommend a specific Cache Plugin? =
114
- Yes! Currently FVM recommends the "Cache Enabler" plugin, for it's simplicity, compatibility with most systems and performance.
115
 
116
 
117
  = Is it resource intensive, or will it use too much CPU on my shared hosting plan? =
 
118
 
119
- Unless you are not excluding dynamic CSS files that change the url in every pageload, no it is not heavy at all. On the first run, each single file is minified into an intermediate cache. When a new group of CSS/JS files is found on a new page, it reuses those files and merges them into a new static cache file. All pages that request the same group of CSS or JS files will also make use of that file, thus regeneration only happens once.
 
 
120
 
121
 
122
  = Is it compatible with multisites? =
123
-
124
  Yes, it generates a new cache file for every different set of JS and CSS requirements it finds, but you must enable and configure FVM settings for each site in your network separatly (no global settings for all sites).
125
 
126
 
127
- = How do I use the pre-compressed files with gzip_static or brotli_static on Nginx? =
128
-
129
- When we merge and minify the css and js files, we also create a `.gz` file to be used with `gzip_static` on Nginx. You need to enable this feature on your Nginx configuration file if you want to make use of it. Likewise, if you have Nginx compiled with brotli and have enabled the php-ext-brotli extension for PHP, you can enable the brotli_static option and FVM will also generate .br files for you :)
130
-
131
-
132
  = Is it compatible with AdSense and other ad networks? =
133
-
134
  If you are just inserting ads on your pages, yes. If you are using a custom script to inject those ads, please double check if it works.
135
 
136
 
@@ -146,42 +136,41 @@ d) Sometimes a plugin conflicts with another when merged (look at google chrome
146
 
147
  e) If you have a conflict, try to add each CSS and each JS file to the ignore list one by one, until you find the one that causes the conflict. If you have no idea of which files to add, check the log file on the "status page" for a list of files being merged into each generated file.
148
 
 
149
 
150
- = Why are some of the CSS and JS files not being merged? =
151
 
 
152
  The plugin only processes JS and CSS files enqueued using the official WordPress api method - https://developer.wordpress.org/themes/basics/including-css-javascript/ -as well as files from the same domain (unless specified on the settings).
153
 
154
 
155
- = How to undo all changes done by the plugin? =
 
 
156
 
 
157
  The plugin itself does not do any "changes" to your site and all original files are untouched. It intercepts the enqueued CSS and JS files just before printing your HTML, copies them and enqueues the newly optimized cached version of those files to the frontend. As with any plugin... simply disable or uninstall the plugin, purge all caches you may have in use (plugins, server, cloudflare, etc.) and the site will go back to what it was before installing it. The plugin does not delete anything from the database or modify any of your files.
158
 
159
 
160
  = I have disabled or deleted the plugin but my design is still broken! =
161
-
162
  Some "cheap" (or sometimes expensive) "optimized" hosting providers, implement a (misconfigured) aggressive cache on their servers that caches PHP code execution and PHP files. I've seen people completely deleting all WordPress files from their host via SFTP/FTP and the website kept working fine for hours. Furthermore, very often they rate limit your cache purge requests... so if you delete FVM and are still seeing references to FVM files on the "view-source:https://example.com" please be patient and contact your web hosting to purge all caches. Providers known to have this issue are some plans on hostgator and iPage (please report others if you find them).
163
 
164
 
165
  = Why is my Visual Composer or Page Editor not working? =
166
-
167
  Some plugins and themes need to edit the layout and styles on the frontend. If you have trouble with page editors, please enable the "Fix Page Editors" option on FVM and purge your caches. Note: You will only see the FVM minification working when you're logged out or using another browser after this setting.
168
 
169
- = What are the recommended cloudflare settings for this plugin? =
170
 
 
171
  On the "Speed" tab, deselect the Auto Minify for JavaScript, CSS and HTML as well as the Rocket Loader option as there is no benefit of using them with our plugin (we already minify things). Those options can also break the design due to double minification or the fact that the Rocket Loader is still experimental (you can read about that on the "Help" link under each selected option on cloudflare).
172
 
173
 
174
  = How can I load CSS async? =
175
-
176
- You are probably a developer if you are trying this. The answer is: make sure FVM is only generating 1 CSS file, because "async" means multiple files will load out of order (but CSS needs order most of the times). If FVM is generating more than 1 CSS file, try to manually dequeue some of the CSS files that are breaking the series on FVM (such as external enqueued files), or add their domain to the settings to be merged together. Please note... this is an advanced option for highly skilled developers. Do not try to fiddle with these settings if you are not one, as it will almost certainly break your site layout and functionality.
177
 
178
 
179
  = I have a complaint or I need support right now. =
180
-
181
  Before getting angry because you have no answer within a few hours (even with paid plugins, sometimes it takes weeks...), please be informed about how wordpress.org and the plugins directory work. The plugins directory is an open source, free service where developers and programmers contribute (on their free time) with plugins that can be downloaded and installed by anyone "at their own risk" and are all released under the GPL license. While all plugins have to be approved and reviewed by the WordPress team before being published (for dangerous code, spam, etc.) this does not change the license or add any warranty. All plugins are provided as they are, free of charge and should be used at your own risk (so you should make backups before installing any plugin or performing updates) and it is your sole responsibility if you break your site after installing a plugin from the plugins directory. For a full version of the license, please read: https://wordpress.org/about/gpl/
182
 
183
  = Why haven't you replied to my topic on the support forum yet? =
184
-
185
  Support is provided by plugin authors on their free time and without warranty of a reply, so you can experience different levels of support level from plugin to plugin. As the author of this plugin I strive to provide support on a daily basis and I can take a look and help you with some issues related with my plugin, but please note that this is done out of my goodwill and in no way I have any legal or moral obligation for doing this. Sometimes I am extremely busy and may take a few days to reply, but I will always reply.
186
 
187
  = But I really need fast support right now, is there any other way? =
@@ -189,12 +178,10 @@ I am also available for hiring if you need custom-made speed optimizations. Afte
189
 
190
 
191
  = Where can I report bugs? =
192
-
193
  You can get support on the official WordPress plugin page at https://wordpress.org/support/plugin/fast-velocity-minify
194
  Alternatively, you can reach me via info (at) fastvelocity.com for security or other vulnerabilities.
195
 
196
  = How can I donate to the plugin author? =
197
-
198
  If you would like to donate any amount to the plugin author (thank you in advance), you can do it via PayPal at https://goo.gl/vpLrSV
199
 
200
 
@@ -209,6 +196,13 @@ Please backup your site before updating. Version 3.0 will have a major code rewr
209
 
210
  == Changelog ==
211
 
 
 
 
 
 
 
 
212
  = 2.5.9 [2019.02.19] =
213
  * fixed some PHP notices, when wordpress fails to download a missing js/css file
214
 
2
  Contributors: Alignak
3
  Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, CSS Merging, JS Merging, CSS Minification, JS Minification, Speed Optimization, HTML Minification, Performance, Optimization, Speed, Fast
4
  Requires at least: 4.5
5
+ Stable tag: 2.6.0
6
  Tested up to: 5.1
7
  License: GPLv3 or later
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
83
  == Frequently Asked Questions ==
84
 
85
  = Can I update plugins and themes after installing FVM? =
86
+ FVM doesn't touch your original files. It copies those files to the cache directory, minifies that copy and merges them together under a different name. If you install new plugins, change themes or do plugin updates, FVM will purge its cache as well as some of the most popular cache plugins.
 
87
 
88
  = After installing, why did my site feels slow to load? =
 
89
  Please see the question below.
90
 
 
91
  = Why are there lots of JS and CSS files listed on the status page and why is the cache directory taking so much space? =
92
+ Some themes combine and enqueue their CSS using a PHP script with a query string that changes on every pageload... (this is to bust cache, but it's bad practice since it prevents caching at all). When FVM sees a different url being enqueued, it will consider that as a new file and try to create a new set of files on every pageview as well. You must then exclude that dynamic url via the Ignore List on the settings for your cache to be efficient and stop growing. Also note, if your pages enqueue different styles or javascript in different pages (fairly common), that is "one set" of files to be merged. Pay attention to the logs header and look for the page url where those files have ben generated. If you have multiple files generated for the same url, you have some css/js that keeps changing on every pageview (and thus needs exclusion).
 
93
 
94
 
95
+ = How can I exclude certain assets? =
96
+ Each line on the ignore list will try to match a substring against all CSS or JS files, for example `//yoursite.com/wp-content/plugins/some-plugin/js/` will ignore all files inside that directory. You can also shorten the URL like `/some-plugin/js/` and then it will match any css or js URL that has `/some-plugin/js/` on the path. Obviously, doing `/js/` would match any files inside any "/js/" directory and in any location, so to avoid unexpected situations please always use the longest, most specific path you can use. There is no need to use asterisks or regex code (it won't work).
 
97
 
98
 
99
  = Why is the ignore list not working? =
100
+ The ignore list "is" working, just try to use partial paths (see previous faq) and use relative urls only without any query vars.
 
101
 
102
 
103
  = Is it compatible with other caching plugins? =
104
+ You must disable any features on your theme or cache plugins which perform minification of css, html and js. Double minification not only slows the whole process, but also has the high potential of causing conflicts in javascript. The plugin will try to automatically purge several popular cache plugins, however if you have a cache on the server side (some hosting services have this) you may need to purge it manually, after you purge FVM to see the results you expect. The automatic purge is active for the following plugins and hosting: W3 Total Cache, WP Supercache, WP Rocket, Wp Fastest Cache, Cachify, Comet Cache, Zen Cache, LiteSpeed Cache, Cache Enabler, SG Optimizer, Breeze (Cloudways), Godaddy Managed WordPress Hosting and WP Engine
105
 
 
106
 
107
  = Do you recommend a specific Cache Plugin? =
108
+ Currently we recommend the "Cache Enabler" plugin, for it's simplicity, compatibility with most systems and performance. Alternatively, W3 Total Cache is a great choice as well.
109
 
110
 
111
  = Is it resource intensive, or will it use too much CPU on my shared hosting plan? =
112
+ Unless you are not excluding dynamic CSS files that change the url in every pageload, its not heavy at all. On the first run, each single file is minified into an intermediate cache. When a new group of CSS/JS files is found on a new page, it reuses those files and merges them into a new static cache file. All pages that request the same group of CSS or JS files will also make use of that file, thus regeneration only happens once. In addition, gz and br files will be pre-compressed (if supported).
113
 
114
+
115
+ = How do I use the pre-compressed files with gzip_static or brotli_static on Nginx? =
116
+ When we merge and minify the css and js files, we also create a `.gz` file to be used with `gzip_static` on Nginx. You need to enable this feature on your Nginx configuration file if you want to make use of it. Likewise, if you have Nginx compiled with brotli and have enabled the php-ext-brotli extension for PHP, you can enable the brotli_static option and FVM will also generate .br files for you :)
117
 
118
 
119
  = Is it compatible with multisites? =
 
120
  Yes, it generates a new cache file for every different set of JS and CSS requirements it finds, but you must enable and configure FVM settings for each site in your network separatly (no global settings for all sites).
121
 
122
 
 
 
 
 
 
123
  = Is it compatible with AdSense and other ad networks? =
 
124
  If you are just inserting ads on your pages, yes. If you are using a custom script to inject those ads, please double check if it works.
125
 
126
 
136
 
137
  e) If you have a conflict, try to add each CSS and each JS file to the ignore list one by one, until you find the one that causes the conflict. If you have no idea of which files to add, check the log file on the "status page" for a list of files being merged into each generated file.
138
 
139
+ f) If you coded some inline JS code that depends on some JS file being loaded before it's execution, try to save that code into an external file and enqueue it as a dependency. It will be merged together, thus no longer being "undefined".
140
 
 
141
 
142
+ = Why are some of the CSS and JS files not being merged? =
143
  The plugin only processes JS and CSS files enqueued using the official WordPress api method - https://developer.wordpress.org/themes/basics/including-css-javascript/ -as well as files from the same domain (unless specified on the settings).
144
 
145
 
146
+ = Can I merge files from other domains? =
147
+ Yes and no. You can for example, merge js files such as jQuery if they are loading from a CDN and it will work, because it doesn't matter where those files are being served from. However, stuff like Facebook and other social media widgets, as well as tracking codes, widgets and so on, cannot usually be merged and cached locally as they may load something different on every pageload, or anytime they change something. Ads and widgets make your site slow, so make sure you only use the minimum necessary plugins and widgets.
148
+
149
 
150
+ = How to undo all changes done by the plugin? =
151
  The plugin itself does not do any "changes" to your site and all original files are untouched. It intercepts the enqueued CSS and JS files just before printing your HTML, copies them and enqueues the newly optimized cached version of those files to the frontend. As with any plugin... simply disable or uninstall the plugin, purge all caches you may have in use (plugins, server, cloudflare, etc.) and the site will go back to what it was before installing it. The plugin does not delete anything from the database or modify any of your files.
152
 
153
 
154
  = I have disabled or deleted the plugin but my design is still broken! =
 
155
  Some "cheap" (or sometimes expensive) "optimized" hosting providers, implement a (misconfigured) aggressive cache on their servers that caches PHP code execution and PHP files. I've seen people completely deleting all WordPress files from their host via SFTP/FTP and the website kept working fine for hours. Furthermore, very often they rate limit your cache purge requests... so if you delete FVM and are still seeing references to FVM files on the "view-source:https://example.com" please be patient and contact your web hosting to purge all caches. Providers known to have this issue are some plans on hostgator and iPage (please report others if you find them).
156
 
157
 
158
  = Why is my Visual Composer or Page Editor not working? =
 
159
  Some plugins and themes need to edit the layout and styles on the frontend. If you have trouble with page editors, please enable the "Fix Page Editors" option on FVM and purge your caches. Note: You will only see the FVM minification working when you're logged out or using another browser after this setting.
160
 
 
161
 
162
+ = What are the recommended cloudflare settings for this plugin? =
163
  On the "Speed" tab, deselect the Auto Minify for JavaScript, CSS and HTML as well as the Rocket Loader option as there is no benefit of using them with our plugin (we already minify things). Those options can also break the design due to double minification or the fact that the Rocket Loader is still experimental (you can read about that on the "Help" link under each selected option on cloudflare).
164
 
165
 
166
  = How can I load CSS async? =
167
+ You are probably a developer if you are trying this. The answer is: make sure FVM is only generating 1 CSS file, because "async" means multiple files will load out of order (however CSS needs order most of the times). If FVM is generating more than 1 CSS file per mediatype, try to manually dequeue some of the CSS files that are breaking the series on FVM (such as external enqueued files), or add their domain to the settings to be merged together. Please note... this is an advanced option for skilled developers. Do not try to fiddle with these settings if you are not one, as it will almost certainly break your site layout and functionality.
 
168
 
169
 
170
  = I have a complaint or I need support right now. =
 
171
  Before getting angry because you have no answer within a few hours (even with paid plugins, sometimes it takes weeks...), please be informed about how wordpress.org and the plugins directory work. The plugins directory is an open source, free service where developers and programmers contribute (on their free time) with plugins that can be downloaded and installed by anyone "at their own risk" and are all released under the GPL license. While all plugins have to be approved and reviewed by the WordPress team before being published (for dangerous code, spam, etc.) this does not change the license or add any warranty. All plugins are provided as they are, free of charge and should be used at your own risk (so you should make backups before installing any plugin or performing updates) and it is your sole responsibility if you break your site after installing a plugin from the plugins directory. For a full version of the license, please read: https://wordpress.org/about/gpl/
172
 
173
  = Why haven't you replied to my topic on the support forum yet? =
 
174
  Support is provided by plugin authors on their free time and without warranty of a reply, so you can experience different levels of support level from plugin to plugin. As the author of this plugin I strive to provide support on a daily basis and I can take a look and help you with some issues related with my plugin, but please note that this is done out of my goodwill and in no way I have any legal or moral obligation for doing this. Sometimes I am extremely busy and may take a few days to reply, but I will always reply.
175
 
176
  = But I really need fast support right now, is there any other way? =
178
 
179
 
180
  = Where can I report bugs? =
 
181
  You can get support on the official WordPress plugin page at https://wordpress.org/support/plugin/fast-velocity-minify
182
  Alternatively, you can reach me via info (at) fastvelocity.com for security or other vulnerabilities.
183
 
184
  = How can I donate to the plugin author? =
 
185
  If you would like to donate any amount to the plugin author (thank you in advance), you can do it via PayPal at https://goo.gl/vpLrSV
186
 
187
 
196
 
197
  == Changelog ==
198
 
199
+ = 2.6.0 [2019.03.02] =
200
+ * fixed cache purging with the hypercache plugin
201
+ * fixed a bug with inline scripts and styles not showing up if there is no url for the enqueued handle
202
+ * changed the cache directory from the wp-content/uploads to wp-content/cache
203
+ * improved compatibility with page cache plugins and servers (purging FVM without purging the page cache should be fine now)
204
+ * added a daily cronjob, to delete public invalid cache files that are older than 3 months (your page cache should expire before this)
205
+
206
  = 2.5.9 [2019.02.19] =
207
  * fixed some PHP notices, when wordpress fails to download a missing js/css file
208