Fast Velocity Minify - Version 2.5.7

Version Description

[2019.02.04] = * reverted back the css merging method to version 2.5.2 due to some compatibility issues

Download this release

Release Info

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

Code changes from version 2.5.6 to 2.5.7

Files changed (2) hide show
  1. fvm.php +696 -343
  2. readme.txt +4 -1
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.6
9
  License: GPL2
10
 
11
  ------------------------------------------------------------------------
@@ -93,7 +93,6 @@ $fastvelocity_min_global_js_done = array();
93
  $fvm_collect_google_fonts = array();
94
  $collect_preload_css = array();
95
  $collect_preload_js = array();
96
- $csscollect = array();
97
  $fvm_debug = get_option('fastvelocity_fvm_debug');
98
 
99
  ###########################################
@@ -116,6 +115,7 @@ $disable_css_minification = get_option('fastvelocity_min_disable_css_minificatio
116
  $remove_print_mediatypes = get_option('fastvelocity_min_remove_print_mediatypes');
117
  $skip_html_minification = get_option('fastvelocity_min_skip_html_minification');
118
  $strip_htmlcomments = get_option('fastvelocity_min_strip_htmlcomments');
 
119
  $skip_google_fonts = get_option('fastvelocity_min_skip_google_fonts');
120
  $skip_emoji_removal = get_option('fastvelocity_min_skip_emoji_removal');
121
  $fvm_clean_header_one = get_option('fastvelocity_fvm_clean_header_one');
@@ -123,7 +123,6 @@ $enable_defer_js = get_option('fastvelocity_min_enable_defer_js');
123
  $exclude_defer_jquery = get_option('fastvelocity_min_exclude_defer_jquery');
124
  $force_inline_css = get_option('fastvelocity_min_force_inline_css');
125
  $force_inline_css_footer = get_option('fastvelocity_min_force_inline_css_footer');
126
- $disable_css_inline_merge = get_option('fastvelocity_min_disable_css_inline_merge');
127
  $remove_googlefonts = get_option('fastvelocity_min_remove_googlefonts');
128
  $defer_for_pagespeed = get_option('fastvelocity_min_defer_for_pagespeed');
129
  $defer_for_pagespeed_optimize = get_option('fastvelocity_min_defer_for_pagespeed_optimize');
@@ -161,7 +160,7 @@ if($fvm_gfonts_method != false) {
161
 
162
 
163
  # default ua list
164
- $fvmualist = array('nux.*oto\sG', 'x11.*fox\/54', 'x11.*ome\/39', 'x11.*ome\/62', 'oid\s6.*1.*xus\s5.*MRA58N.*ome', 'JWR66Y.*ome\/62', 'woobot', 'wget', 'speed', 'ighth', 'tmetr');
165
 
166
 
167
  # add admin page and rewrite defaults
@@ -198,9 +197,8 @@ if(is_admin()) {
198
 
199
  # merge, if inline is not selected
200
  if($force_inline_css != true) {
201
- add_filter('style_loader_tag', 'fastvelocity_min_merge_css', PHP_INT_MAX, 4 );
202
- add_action('wp_print_styles','fastvelocity_add_google_fonts_merged', PHP_INT_MAX);
203
- add_action('wp_print_footer_scripts','fastvelocity_add_google_fonts_merged', PHP_INT_MAX );
204
  } else {
205
  add_filter('style_loader_tag', 'fastvelocity_optimizecss', PHP_INT_MAX, 4 );
206
  add_action('wp_print_styles','fastvelocity_add_google_fonts_merged', PHP_INT_MAX);
@@ -254,7 +252,8 @@ global $fvm_fix_editor, $disable_js_merge, $disable_css_merge, $skip_emoji_remov
254
  if($fvm_fix_editor == true && is_user_logged_in()) {
255
  remove_action('wp_print_scripts', 'fastvelocity_min_merge_header_scripts', PHP_INT_MAX );
256
  remove_action('wp_print_footer_scripts', 'fastvelocity_min_merge_footer_scripts', 9.999999 );
257
- remove_filter('style_loader_tag', 'fastvelocity_min_merge_css', PHP_INT_MAX, 4 );
 
258
  remove_action('wp_print_styles', 'fastvelocity_add_google_fonts_merged', PHP_INT_MAX);
259
  remove_action('wp_print_footer_scripts', 'fastvelocity_add_google_fonts_merged', PHP_INT_MAX );
260
  remove_action('init', 'fastvelocity_min_disable_wp_emojicons');
@@ -348,13 +347,13 @@ function fastvelocity_min_register_settings() {
348
  register_setting('fvm-group', 'fastvelocity_min_remove_print_mediatypes');
349
  register_setting('fvm-group', 'fastvelocity_min_skip_html_minification');
350
  register_setting('fvm-group', 'fastvelocity_min_strip_htmlcomments');
 
351
  register_setting('fvm-group', 'fastvelocity_min_skip_google_fonts');
352
  register_setting('fvm-group', 'fastvelocity_min_skip_fontawesome_fonts');
353
  register_setting('fvm-group', 'fastvelocity_min_skip_emoji_removal');
354
  register_setting('fvm-group', 'fastvelocity_fvm_clean_header_one');
355
  register_setting('fvm-group', 'fastvelocity_min_enable_defer_js');
356
  register_setting('fvm-group', 'fastvelocity_min_exclude_defer_jquery');
357
- register_setting('fvm-group', 'fastvelocity_min_disable_css_inline_merge');
358
  register_setting('fvm-group', 'fastvelocity_min_force_inline_css');
359
  register_setting('fvm-group', 'fastvelocity_min_force_inline_css_footer');
360
  register_setting('fvm-group', 'fastvelocity_min_remove_googlefonts');
@@ -720,14 +719,14 @@ Disable CSS processing<span class="note-info">[ If selected, this plugin will ig
720
  <input name="fastvelocity_min_disable_css_minification" type="checkbox" id="fastvelocity_min_disable_css_minification" value="1" <?php echo checked(1 == get_option('fastvelocity_min_disable_css_minification'), true, false); ?>>
721
  Disable minification on CSS files <span class="note-info">[ If selected, CSS files will be merged but not minified ]</span></label>
722
  <br />
 
 
 
 
723
  <label for="fastvelocity_min_remove_print_mediatypes">
724
  <input name="fastvelocity_min_remove_print_mediatypes" type="checkbox" id="fastvelocity_min_remove_print_mediatypes" value="1" <?php echo checked(1 == get_option('fastvelocity_min_remove_print_mediatypes'), true, false); ?> >
725
  Disable the "Print" related stylesheets <span class="note-info">[ If selected, CSS files of mediatype "print" will be removed from the site ]</span></label>
726
  <br />
727
- <label for="fastvelocity_min_disable_css_inline_merge">
728
- <input name="fastvelocity_min_disable_css_inline_merge" type="checkbox" id="fastvelocity_min_disable_css_inline_merge" value="1" <?php echo checked(1 == get_option('fastvelocity_min_disable_css_inline_merge'), true, false); ?>>
729
- Disable merging of inlined CSS code <span class="note-info">[ If selected, existing inline CSS will be inlined after the FVM generated CSS file instead of merged together]</span></label>
730
- <br />
731
  <label for="fastvelocity_min_force_inline_css_footer">
732
  <input name="fastvelocity_min_force_inline_css_footer" type="checkbox" id="fastvelocity_min_force_inline_css_footer" value="1" <?php echo checked(1 == get_option('fastvelocity_min_force_inline_css_footer'), true, false); ?>>
733
  Inline CSS in the footer <span class="note-info">[ If selected, any FVM generated CSS files in the footer, will be inlined ]</span></label>
@@ -1614,9 +1613,18 @@ if (stripos($tag, 'defer') === false && stripos($tag, 'async') === false) {
1614
 
1615
  # defer tag globally
1616
  $jsdefer = str_ireplace('<script ', '<script defer ', $tag);
 
 
 
 
 
 
 
 
 
1617
 
1618
  # defer tag for PSI only
1619
- $jsdeferpsionly = '<script type="text/javascript">if(navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){document.write('.json_encode($jsdefer).');}else{document.write('.json_encode($tag).');}</script>';
1620
 
1621
  # hide tag from PSI
1622
  $jsdeferhidepsi = '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){document.write('.json_encode($tag).');}</script>';
@@ -1657,337 +1665,321 @@ return $tag;
1657
  ###########################################
1658
 
1659
 
1660
-
1661
  ###########################################
1662
- # process css #############################
1663
  ###########################################
1664
- # collect all css files as well as inline css code, to be printed later
1665
- function fastvelocity_min_merge_css($html, $handle, $href, $media){
1666
- global $fvm_debug, $wp_domain, $wp_home, $fvmualist, $fvm_collect_google_fonts, $force_inline_googlefonts, $min_async_googlefonts, $remove_googlefonts, $skip_google_fonts, $css_hide_googlefonts, $remove_print_mediatypes, $ignore, $blacklist, $ignorelist, $fvm_remove_css, $fvm_min_excludecsslist, $disable_css_minification, $fvm_fix_editor, $fvm_fawesome_method, $csscollect, $disable_css_inline_merge;
1667
-
1668
- # current timestamp
1669
- $ctime = get_option('fvm-last-cache-update', '0');
1670
-
1671
- # make sure href is complete
1672
- $href = fastvelocity_min_get_hurl($href, $wp_domain, $wp_home);
1673
-
1674
- if($fvm_debug == true) { echo "<!-- FVM DEBUG: Merging CSS processing start $handle / $href -->" . PHP_EOL; }
1675
-
1676
- # prevent optimization for these locations
1677
- if (is_admin() || is_preview() || is_customize_preview() || ($fvm_fix_editor == true && is_user_logged_in()) || (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint())) {
1678
- return $html;
1679
- }
1680
-
1681
- # remove all css?
1682
- if($fvm_remove_css != false) {
1683
- return false;
1684
- }
1685
-
1686
- # leave conditionals alone
1687
- $conditional = wp_styles()->get_data($handle, 'conditional');
1688
- if($conditional != false) {
1689
- return $html;
1690
- }
1691
-
1692
- # mediatype fix for some plugins + remove print mediatypes
1693
- if ($media == 'screen' || $media == 'screen, print' || empty($media) || is_null($media) || $media == false) { $media = 'all'; }
1694
- if($remove_print_mediatypes != false && $media == 'print') {
1695
- return false;
1696
- }
1697
-
1698
- # Exclude specific CSS files from PSI?
1699
- if($fvm_min_excludecsslist != false && is_array($fvm_min_excludecsslist) && fastvelocity_min_in_arrayi($href, $fvm_min_excludecsslist)) {
1700
- $cssguid = 'fvm'.hash('adler32', $href);
1701
- echo '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){';
1702
- echo 'var '.$cssguid.'=document.createElement("link");'.$cssguid.'.rel="stylesheet",'.$cssguid.'.type="text/css",'.$cssguid.'.media="async",'.$cssguid.'.href="'.$href.'",'.$cssguid.'.onload=function(){'.$cssguid.'.media="'.$media.'"},document.getElementsByTagName("head")[0].appendChild('.$cssguid.');';
1703
- echo '}</script>';
1704
- return false;
1705
- }
1706
-
1707
- # remove FVM from the ignore list
1708
- array_filter($ignore, function ($var) { return (stripos($var, '/fvm/') === false); });
1709
-
1710
- # return if in any ignore or black list
1711
- if (count($ignore) > 0 && fastvelocity_min_in_arrayi($href, $ignore) || count($blacklist) > 0 && fastvelocity_min_in_arrayi($href, $blacklist) || count($ignorelist) > 0 && fastvelocity_min_in_arrayi($href, $ignorelist)) {
1712
- return $html;
1713
- }
1714
-
1715
- # remove google fonts completely?
1716
- if($remove_googlefonts != false && stripos($href, 'fonts.googleapis.com') !== false) {
1717
- return false;
1718
- }
1719
-
1720
- # handle google fonts here, when merging is disabled
1721
- if(stripos($href, 'fonts.googleapis.com') !== false && $skip_google_fonts != false) {
1722
-
1723
- # hide google fonts from PSI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1724
  if($css_hide_googlefonts == true) {
1725
- $cssguid = 'fvm'.hash('adler32', $href);
 
 
1726
  echo '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){';
1727
- echo 'var '.$cssguid.'=document.createElement("link");'.$cssguid.'.rel="stylesheet",'.$cssguid.'.type="text/css",'.$cssguid.'.media="async",'.$cssguid.'.href="'.$href.'",'.$cssguid.'.onload=function(){'.$cssguid.'.media="all"},document.getElementsByTagName("head")[0].appendChild('.$cssguid.');';
1728
- echo '}</script>';
1729
- return false;
1730
- }
1731
-
1732
- # load google fonts async
1733
- if($min_async_googlefonts != false) {
1734
- echo '<link rel="preload" href="'.$href.'" as="style" media="all" onload="this.onload=null;this.rel=\'stylesheet\'" />';
1735
- echo '<noscript><link rel="stylesheet" href="'.$href.'" media="all" /></noscript>';
1736
- echo '<!--[if IE]><link rel="stylesheet" href="'.$href.'" media="all" /><![endif]-->';
1737
- return false;
1738
- }
1739
- }
1740
-
1741
- # font awesome processing, async css
1742
- if($fvm_fawesome_method == 2 && stripos($href, 'font-awesome') !== false) {
1743
- echo '<link rel="preload" href="'.$href.'" as="style" media="'.$media.'" onload="this.onload=null;this.rel=\'stylesheet\'" />';
1744
- echo '<noscript><link rel="stylesheet" href="'.$href.'" media="'.$media.'" /></noscript>';
1745
- echo '<!--[if IE]><link rel="stylesheet" href="'.$href.'" media="'.$media.'" /><![endif]-->';
1746
- return false;
1747
- }
1748
-
1749
- # font awesome processing, async and exclude from PSI
1750
- if($fvm_fawesome_method == 3 && stripos($href, 'font-awesome') !== false) {
1751
- $cssguid = 'fvm'.hash('adler32', $href);
1752
- echo '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){';
1753
- echo 'var '.$cssguid.'=document.createElement("link");'.$cssguid.'.rel="stylesheet",'.$cssguid.'.type="text/css",'.$cssguid.'.media="async",'.$cssguid.'.href="'.$href.'",'.$cssguid.'.onload=function(){'.$cssguid.'.media="'.$media.'"},document.getElementsByTagName("head")[0].appendChild('.$cssguid.');';
1754
- echo '}</script>';
1755
- return false;
1756
- }
1757
-
1758
- # font awesome processing, inline
1759
- if($fvm_fawesome_method == 1 && stripos($href, 'font-awesome') !== false) {
1760
-
1761
- # download, minify, cache
1762
- $tkey = 'css-'.$ctime.'-'.hash('adler32', $handle.$href).'.css';
1763
- $json = false; $json = fvm_get_transient($tkey);
1764
- if ( $json === false) {
1765
- $json = fvm_download_and_minify($href, null, $disable_css_minification, 'css', $handle);
1766
- if($fvm_debug == true) { echo "<!-- FVM DEBUG: Uncached file processing now for $handle / $href -->" . PHP_EOL; }
1767
- fvm_set_transient($tkey, $json);
1768
- }
1769
-
1770
- # decode
1771
- $res = json_decode($json, true);
1772
-
1773
- # add font-display
1774
- # https://developers.google.com/web/updates/2016/02/font-display
1775
- $res['code'] = str_ireplace('font-style:normal;', 'font-display:block;font-style:normal;', $res['code']);
1776
-
1777
- # inline css or fail
1778
- if($res['status'] != false) {
1779
- echo '<style type="text/css" media="all">'.$res['code'].'</style>'.PHP_EOL;
1780
- return false;
1781
- } else {
1782
- if($fvm_debug == true) { echo "<!-- FVM DEBUG: Font Awesome request failed for $href -->" . PHP_EOL; }
1783
- return $html;
1784
- }
1785
- }
1786
-
1787
- # inline google fonts, do not collect
1788
- if(stripos($href, 'fonts.googleapis.com') !== false && $force_inline_googlefonts != false && $css_hide_googlefonts != true && $min_async_googlefonts != true) {
1789
-
1790
- # download, minify, cache
1791
- $tkey = 'css-'.$ctime.'-'.hash('adler32', $handle.$href).'.css';
1792
- $json = false; $json = fvm_get_transient($tkey);
1793
- if ( $json === false) {
1794
- $json = fvm_download_and_minify($href, null, $disable_css_minification, 'css', $handle);
1795
- if($fvm_debug == true) { echo "<!-- FVM DEBUG: Uncached file processing now for $handle / $href -->" . PHP_EOL; }
1796
- fvm_set_transient($tkey, $json);
1797
- }
1798
-
1799
- # decode
1800
- $res = json_decode($json, true);
1801
-
1802
- # add font-display
1803
- # https://developers.google.com/web/updates/2016/02/font-display
1804
- $res['code'] = str_ireplace('font-style:normal;', 'font-display:block;font-style:normal;', $res['code']);
1805
-
1806
- # inline css or fail
1807
- if($res['status'] != false) {
1808
- echo '<style type="text/css" media="all">'.$res['code'].'</style>'.PHP_EOL;
1809
- return false;
1810
- } else {
1811
- if($fvm_debug == true) { echo "<!-- FVM DEBUG: Google fonts request failed for $href -->" . PHP_EOL; }
1812
- return $html;
1813
- }
1814
- }
1815
-
1816
- # collect and remove google fonts for merging
1817
- if(stripos($href, 'fonts.googleapis.com') !== false){
1818
- $fvm_collect_google_fonts[$handle] = $href;
1819
- return false;
1820
- }
1821
-
1822
- # skip external scripts that are not specifically allowed
1823
- if (fvm_internal_url($href, $wp_home) === false || empty($href)) {
1824
- if($fvm_debug == true) { echo "<!-- FVM DEBUG: Skipped the next external enqueued CSS -->" . PHP_EOL; }
1825
- return $html;
1826
- }
1827
-
1828
- # download, minify, cache
1829
- $tkey = 'css-'.$ctime.'-'.hash('adler32', $handle.$href).'.css';
1830
- $json = false; $json = fvm_get_transient($tkey);
1831
- if ( $json === false) {
1832
- $json = fvm_download_and_minify($href, null, $disable_css_minification, 'css', $handle);
1833
- if($fvm_debug == true) { echo "<!-- FVM DEBUG: Uncached file processing now for $handle / $href -->" . PHP_EOL; }
1834
- fvm_set_transient($tkey, $json);
1835
- }
1836
-
1837
- # decode
1838
- $res = json_decode($json, true);
1839
-
1840
- # colect it, together with other inline children styles
1841
- if($res['status'] != false) {
1842
-
1843
- # collect main css code from file
1844
- $csscollect[$media][] = array('handle' => $handle, 'log' => $res['log'], 'type'=> 'link', 'code' => $res['code']);
1845
-
1846
- # merge inline css code, unless disabled
1847
- if($disable_css_inline_merge != true) {
1848
 
1849
- # get inline_styles for this handle
1850
- $inline_styles = array();
1851
- global $wp_styles;
1852
- if(is_object($wp_styles)) {
1853
- if(isset($wp_styles->registered[$handle]->extra['after'])) {
1854
- $inline_styles = $wp_styles->registered[$handle]->extra['after'];
1855
- unset($wp_styles->registered[$handle]->extra['after']);
1856
- }
 
 
1857
  }
1858
 
1859
- if($inline_styles != false) {
1860
-
1861
- # string type
1862
- if(is_string($inline_styles) && !empty($inline_styles)) {
1863
- $code = fastvelocity_min_get_css($href, $inline_styles, $disable_css_minification);
1864
- if(!empty($code) && $code != false) {
1865
- $hash = md5($code);
1866
- $codesize = fastvelocity_format_filesize(strlen($code));
1867
- $nlog = "--- Merged $codesize of inlined CSS code for [$handle] with md5 hash: $hash ---" . PHP_EOL;
1868
- $csscollect[$media][] = array('handle' => $handle, 'log' => $nlog, 'type'=> 'inline', 'code' => $code, 'hash'=>$hash);
1869
- }
1870
- }
 
 
 
1871
 
1872
- # array type
1873
- if(is_array($inline_styles)) {
1874
- $inline_styles = array_filter($inline_styles);
1875
- foreach ($inline_styles as $st) {
1876
- $code = fastvelocity_min_get_css($href, $st, $disable_css_minification);
1877
- if(!empty($code) && $code != false) {
1878
- $hash = md5($code);
1879
- $codesize = fastvelocity_format_filesize(strlen($code));
1880
- $nlog = "--- Merged $codesize of inlined CSS code for [$handle] with md5 hash: $hash ---" . PHP_EOL;
1881
- $csscollect[$media][] = array('handle' => $handle, 'log' => $nlog, 'type'=> 'inline', 'code' => $code, 'hash'=>$hash);
1882
- }
1883
- }
1884
- }
1885
  }
 
 
 
 
1886
  }
1887
 
1888
- # prevent default
1889
- return false;
1890
-
1891
- } else {
1892
- if($fvm_debug == true) { echo "<!-- FVM DEBUG: $handle / $href returned empty from minification -->" . PHP_EOL; }
1893
- return $html;
1894
  }
1895
-
1896
- # fallback, for whatever reason
1897
- echo "<!-- ERROR: FVM couldn't catch the CSS file below. Please report this on https://wordpress.org/support/plugin/fast-velocity-minify/ -->";
1898
- return $html;
1899
  }
1900
 
1901
 
1902
- # generate merged css files and enqueue them
1903
- add_action('wp_head', 'fastvelocity_add_merged_css', 8);
1904
- add_action('wp_print_footer_scripts','fastvelocity_add_merged_css', PHP_INT_MAX );
1905
- function fastvelocity_add_merged_css(){
1906
- global $csscollect, $cachedir, $cachedirurl, $fvmloadcss, $fvm_remove_css, $fvm_enabled_css_preload, $collect_preload_css;
 
 
 
 
 
 
 
 
 
 
 
 
1907
 
1908
- # return if disabled
1909
- if (!is_array($csscollect)) {
1910
- return false;
1911
- }
1912
 
1913
- # are we on the header or footer?
1914
- $current_action = current_action();
 
 
 
1915
 
1916
- # current timestamp
1917
- $ctime = get_option('fvm-last-cache-update', '0');
 
 
1918
 
1919
- # foreach meadiatype, generate css file name, merge, save and print it
1920
- $i = 0; foreach ($csscollect as $mediatype=>$arr) {
 
 
 
1921
 
1922
- # no empty array
1923
- if(count($arr) == 0) {
1924
- return false;
 
 
 
 
 
 
 
 
 
 
1925
  }
1926
 
1927
- # initialization
1928
- $uid = '';
1929
- $log = '';
1930
- $code = '';
1931
-
1932
- # filename for this mediatype
1933
- foreach ($arr as $k=>$narr) {
1934
-
1935
- # no empty array
1936
- if(count($narr) == 0) {
1937
- return false;
1938
- }
1939
-
1940
- # no empty arrays
1941
- $narr = array_filter($narr);
1942
-
1943
- # unset as we go
1944
- if(isset($csscollect[$mediatype][$k])) {
1945
- unset($csscollect[$mediatype][$k]);
1946
- }
1947
-
1948
- # uid needs handle name
1949
- if(isset($narr['handle'])) {
1950
- $uid.= '_'.$narr['handle'];
1951
- }
1952
-
1953
- # uid needs type
1954
- if(isset($narr['type'])) {
1955
- $uid.= '_'.$narr['type'];
1956
- }
1957
-
1958
- # uid needs hash if its an inline type
1959
- if(isset($narr['type']) && $narr['type'] == 'inline' && isset($narr['hash'])) {
1960
- $uid.= '_'.$narr['hash'];
1961
- }
1962
-
1963
- # merge code for this mediatype
1964
- if(isset($narr['code']) && isset($narr['log'])) {
1965
- $code.=$narr['code'];
1966
- $log.=$narr['log'];
1967
- }
1968
-
1969
  }
 
 
 
 
 
 
 
 
 
 
 
1970
 
1971
- # define file and id prefix
1972
- if ($current_action == 'wp_head') {
1973
- $cssid = 'header-css-'.$i;
1974
- $fprefix = 'header-';
1975
- } else {
1976
- $cssid = 'footer-css-'.$i;
1977
- $fprefix = 'footer-';
1978
- }
1979
 
 
 
 
 
1980
  # create cache files and urls
1981
- $hash = $fprefix.hash('adler32', $mediatype.'_'.$uid);
1982
  $file = $cachedir.'/'.$hash.'-'.$ctime.'.min.css';
1983
- $file_url = fvm_get_protocol($cachedirurl.'/'.$hash.'-'.$ctime.'.min.css');
1984
 
1985
  # generate a new cache file
1986
  clearstatcache();
1987
  if (!file_exists($file)) {
1988
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1989
  # prepare log
1990
- $log = "PROCESSED - " . home_url(add_query_arg(NULL, NULL)) . PHP_EOL . "GENERATED - " . date('r') . PHP_EOL . 'MEDIATYPE - '.$mediatype . PHP_EOL . '---' . PHP_EOL . $log;
1991
 
1992
  # generate cache, write log
1993
  if(!empty($code)) {
@@ -2008,59 +2000,420 @@ function fastvelocity_add_merged_css(){
2008
  }
2009
  }
2010
 
2011
- # note: the developers tab, takes precedence
2012
- # Async CSS with loadCSS ?
2013
- if($fvmloadcss != false && $fvm_remove_css != true) {
2014
- echo '<link id="'.$cssid.'" rel="preload" href="'.$file_url.'" as="style" media="'.$mediatype.'" onload="this.onload=null;this.rel=\'stylesheet\'" />';
2015
- echo '<noscript><link rel="stylesheet" href="'.$file_url.'" media="'.$mediatype.'" /></noscript>';
2016
- echo '<!--[if IE]><link rel="stylesheet" href="'.$file_url.'" media="'.$mediatype.'" /><![endif]-->';
2017
-
2018
- # else enqueue file, if not empty
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2019
  } else {
2020
- if(file_exists($file) && filesize($file) > 0) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2021
 
2022
- # inline CSS if mediatype is not of type "all" or if the file is smaller than 20KB
2023
- if(filesize($file) < 20000 && $mediatype != 'all') {
2024
- echo '<style id="'.$cssid.'" media="'.$mediatype.'">'.file_get_contents($file).'</style>';
2025
  } else {
2026
-
2027
- # add css to the html
2028
- echo '<link id="'.$cssid.'" rel="stylesheet" href="'.$file_url.'" media="'.$mediatype.'" />';
2029
-
2030
- # collect it for preload (if enabled + header only)
2031
- if ($fvm_enabled_css_preload == true && $current_action == 'wp_head') {
2032
- $collect_preload_css[] = $file_url;
2033
- }
2034
  }
 
 
2035
  } else {
2036
- # file could not be generated, output something meaningful
2037
- echo "<!-- ERROR: FVM was not allowed to save it's cache on - $file -->";
2038
- echo "<!-- Please check if the path above is correct and ensure your server has writting permission there! -->";
2039
- echo "<!-- If you found a bug, please report this on https://wordpress.org/support/plugin/fast-velocity-minify/ -->";
2040
  }
 
2041
  }
2042
-
2043
- # increment by mediatype
2044
- $i++;
2045
  }
 
 
 
 
 
 
 
 
 
2046
 
 
 
 
 
2047
 
 
 
 
 
2048
 
2049
- # fallback
2050
- return false;
2051
- }
2052
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2053
 
2054
 
2055
- ###########################################
 
 
2056
 
 
 
 
 
 
2057
 
 
 
 
 
 
 
 
 
 
2058
 
 
 
 
 
 
 
2059
 
 
 
 
 
 
 
 
 
 
 
 
 
2060
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2061
 
 
 
2062
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2063
 
 
 
 
 
2064
 
2065
 
2066
 
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.7
9
  License: GPL2
10
 
11
  ------------------------------------------------------------------------
93
  $fvm_collect_google_fonts = array();
94
  $collect_preload_css = array();
95
  $collect_preload_js = array();
 
96
  $fvm_debug = get_option('fastvelocity_fvm_debug');
97
 
98
  ###########################################
115
  $remove_print_mediatypes = get_option('fastvelocity_min_remove_print_mediatypes');
116
  $skip_html_minification = get_option('fastvelocity_min_skip_html_minification');
117
  $strip_htmlcomments = get_option('fastvelocity_min_strip_htmlcomments');
118
+ $skip_cssorder = get_option('fastvelocity_min_skip_cssorder');
119
  $skip_google_fonts = get_option('fastvelocity_min_skip_google_fonts');
120
  $skip_emoji_removal = get_option('fastvelocity_min_skip_emoji_removal');
121
  $fvm_clean_header_one = get_option('fastvelocity_fvm_clean_header_one');
123
  $exclude_defer_jquery = get_option('fastvelocity_min_exclude_defer_jquery');
124
  $force_inline_css = get_option('fastvelocity_min_force_inline_css');
125
  $force_inline_css_footer = get_option('fastvelocity_min_force_inline_css_footer');
 
126
  $remove_googlefonts = get_option('fastvelocity_min_remove_googlefonts');
127
  $defer_for_pagespeed = get_option('fastvelocity_min_defer_for_pagespeed');
128
  $defer_for_pagespeed_optimize = get_option('fastvelocity_min_defer_for_pagespeed_optimize');
160
 
161
 
162
  # default ua list
163
+ $fvmualist = array('nux.*oto\sG', 'x11.*fox\/54', 'x11.*ome\/39', 'x11.*ome\/62', 'oid\s6.*1.*xus\s5.*MRA58N.*ome', 'JWR66Y.*ome\/62', 'woobot', 'speed', 'ighth', 'tmetr', 'eadle');
164
 
165
 
166
  # add admin page and rewrite defaults
197
 
198
  # merge, if inline is not selected
199
  if($force_inline_css != true) {
200
+ add_action('wp_print_styles', 'fastvelocity_min_merge_header_css', PHP_INT_MAX );
201
+ add_action('wp_print_footer_scripts', 'fastvelocity_min_merge_footer_css', 9.999999 );
 
202
  } else {
203
  add_filter('style_loader_tag', 'fastvelocity_optimizecss', PHP_INT_MAX, 4 );
204
  add_action('wp_print_styles','fastvelocity_add_google_fonts_merged', PHP_INT_MAX);
252
  if($fvm_fix_editor == true && is_user_logged_in()) {
253
  remove_action('wp_print_scripts', 'fastvelocity_min_merge_header_scripts', PHP_INT_MAX );
254
  remove_action('wp_print_footer_scripts', 'fastvelocity_min_merge_footer_scripts', 9.999999 );
255
+ remove_action('wp_print_styles', 'fastvelocity_min_merge_header_css', PHP_INT_MAX );
256
+ remove_action('wp_print_footer_scripts', 'fastvelocity_min_merge_footer_css', 9.999999 );
257
  remove_action('wp_print_styles', 'fastvelocity_add_google_fonts_merged', PHP_INT_MAX);
258
  remove_action('wp_print_footer_scripts', 'fastvelocity_add_google_fonts_merged', PHP_INT_MAX );
259
  remove_action('init', 'fastvelocity_min_disable_wp_emojicons');
347
  register_setting('fvm-group', 'fastvelocity_min_remove_print_mediatypes');
348
  register_setting('fvm-group', 'fastvelocity_min_skip_html_minification');
349
  register_setting('fvm-group', 'fastvelocity_min_strip_htmlcomments');
350
+ register_setting('fvm-group', 'fastvelocity_min_skip_cssorder');
351
  register_setting('fvm-group', 'fastvelocity_min_skip_google_fonts');
352
  register_setting('fvm-group', 'fastvelocity_min_skip_fontawesome_fonts');
353
  register_setting('fvm-group', 'fastvelocity_min_skip_emoji_removal');
354
  register_setting('fvm-group', 'fastvelocity_fvm_clean_header_one');
355
  register_setting('fvm-group', 'fastvelocity_min_enable_defer_js');
356
  register_setting('fvm-group', 'fastvelocity_min_exclude_defer_jquery');
 
357
  register_setting('fvm-group', 'fastvelocity_min_force_inline_css');
358
  register_setting('fvm-group', 'fastvelocity_min_force_inline_css_footer');
359
  register_setting('fvm-group', 'fastvelocity_min_remove_googlefonts');
719
  <input name="fastvelocity_min_disable_css_minification" type="checkbox" id="fastvelocity_min_disable_css_minification" value="1" <?php echo checked(1 == get_option('fastvelocity_min_disable_css_minification'), true, false); ?>>
720
  Disable minification on CSS files <span class="note-info">[ If selected, CSS files will be merged but not minified ]</span></label>
721
  <br />
722
+ <label for="fastvelocity_min_skip_cssorder">
723
+ <input name="fastvelocity_min_skip_cssorder" type="checkbox" id="fastvelocity_min_skip_cssorder" value="1" <?php echo checked(1 == get_option('fastvelocity_min_skip_cssorder'), true, false); ?> >
724
+ Preserve the order of CSS files <span class="note-info">[ If selected, you will have better CSS compatibility when merging but possibly more CSS files ]</span></label>
725
+ <br />
726
  <label for="fastvelocity_min_remove_print_mediatypes">
727
  <input name="fastvelocity_min_remove_print_mediatypes" type="checkbox" id="fastvelocity_min_remove_print_mediatypes" value="1" <?php echo checked(1 == get_option('fastvelocity_min_remove_print_mediatypes'), true, false); ?> >
728
  Disable the "Print" related stylesheets <span class="note-info">[ If selected, CSS files of mediatype "print" will be removed from the site ]</span></label>
729
  <br />
 
 
 
 
730
  <label for="fastvelocity_min_force_inline_css_footer">
731
  <input name="fastvelocity_min_force_inline_css_footer" type="checkbox" id="fastvelocity_min_force_inline_css_footer" value="1" <?php echo checked(1 == get_option('fastvelocity_min_force_inline_css_footer'), true, false); ?>>
732
  Inline CSS in the footer <span class="note-info">[ If selected, any FVM generated CSS files in the footer, will be inlined ]</span></label>
1613
 
1614
  # defer tag globally
1615
  $jsdefer = str_ireplace('<script ', '<script defer ', $tag);
1616
+ $jsdeferpsi = $jsdefer;
1617
+
1618
+ # add cdn for PSI
1619
+ $fvm_cdn_url = get_option('fastvelocity_min_fvm_cdn_url');
1620
+ if(!empty($fvm_cdn_url)) {
1621
+ $fvm_cdn_url = trim(trim(str_ireplace(array('http://', 'https://'), '', trim($fvm_cdn_url, '/'))), '/');
1622
+ $jsdeferpsi = str_ireplace($src, $fvm_cdn_url, $jsdefer);
1623
+ }
1624
+
1625
 
1626
  # defer tag for PSI only
1627
+ $jsdeferpsionly = '<script type="text/javascript">if(navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){document.write('.json_encode($jsdeferpsi).');}else{document.write('.json_encode($tag).');}</script>';
1628
 
1629
  # hide tag from PSI
1630
  $jsdeferhidepsi = '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){document.write('.json_encode($tag).');}</script>';
1665
  ###########################################
1666
 
1667
 
 
1668
  ###########################################
1669
+ # process header css ######################
1670
  ###########################################
1671
+ function fastvelocity_min_merge_header_css() {
1672
+ global $wp_styles, $wp_domain, $wp_home, $wp_home_path, $cachedir, $cachedirurl, $ignore, $disable_css_merge, $disable_css_minification, $skip_google_fonts, $skip_cssorder, $remove_print_mediatypes, $force_inline_googlefonts, $css_hide_googlefonts, $min_async_googlefonts, $remove_googlefonts, $fvmloadcss, $fvm_remove_css, $fvmualist, $fvm_min_excludecsslist, $fvm_debug, $fvm_min_excludecsslist, $fvm_fawesome_method;
1673
+ if(!is_object($wp_styles)) { return false; }
1674
+ $ctime = get_option('fvm-last-cache-update', '0');
1675
+ $styles = wp_clone($wp_styles);
1676
+ $styles->all_deps($styles->queue);
1677
+ $done = $styles->done;
1678
+ $header = array();
1679
+ $google_fonts = array();
1680
+ $process = array();
1681
+ $inline_css = array();
1682
+
1683
+ # dequeue all styles
1684
+ if($fvm_remove_css != false) {
1685
+ foreach( $styles->to_do as $handle ) :
1686
+ $done = array_merge($done, array($handle));
1687
+ endforeach;
1688
+
1689
+ # remove from queue
1690
+ $wp_styles->done = $done;
1691
+ return false;
1692
+ }
1693
+
1694
+ # add defaults to ignore list
1695
+ $ignore = fastvelocity_default_ignore($ignore);
1696
+
1697
+ # get list of handles to process, dequeue duplicate css urls and keep empty source handles (for dependencies)
1698
+ $uniq = array(); $gfonts = array();
1699
+ foreach( $styles->to_do as $handle):
1700
+
1701
+ # conditionals
1702
+ $conditional = NULL; if(isset($wp_styles->registered[$handle]->extra["conditional"])) {
1703
+ $conditional = $wp_styles->registered[$handle]->extra["conditional"]; # such as ie7, ie8, ie9, etc
1704
+ }
1705
+
1706
+ # mediatype
1707
+ $mt = isset($wp_styles->registered[$handle]->args) ? $wp_styles->registered[$handle]->args : 'all';
1708
+ if ($mt == 'screen' || $mt == 'screen, print' || empty($mt) || is_null($mt) || $mt == false) { $mt = 'all'; }
1709
+ $mediatype = $mt;
1710
+
1711
+ # full url or empty
1712
+ $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
1713
+
1714
+ # mark duplicates as done and remove from the queue
1715
+ if(!empty($hurl)) {
1716
+ $key = hash('adler32', $hurl);
1717
+ if (isset($uniq[$key])) { $done = array_merge($done, array($handle)); continue; } else { $uniq[$key] = $handle; }
1718
+ }
1719
+
1720
+ # Exclude specific CSS files from PSI?
1721
+ if($fvm_min_excludecsslist != false && is_array($fvm_min_excludecsslist) && fastvelocity_min_in_arrayi($hurl, $fvm_min_excludecsslist)) {
1722
+ $cssguid = 'fvm'.hash('adler32', $hurl);
1723
+ echo '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){';
1724
+ echo 'var '.$cssguid.'=document.createElement("link");'.$cssguid.'.rel="stylesheet",'.$cssguid.'.type="text/css",'.$cssguid.'.media="async",'.$cssguid.'.href="'.$hurl.'",'.$cssguid.'.onload=function(){'.$cssguid.'.media="'.$mediatype.'"},document.getElementsByTagName("head")[0].appendChild('.$cssguid.');';
1725
+ echo '}</script>';
1726
+ $done = array_merge($done, array($handle)); continue;
1727
+ }
1728
+
1729
+ # font awesome processing, async css
1730
+ if($fvm_fawesome_method == 2 && stripos($hurl, 'font-awesome') !== false) {
1731
+ echo '<link rel="preload" href="'.$hurl.'" as="style" media="'.$mediatype.'" onload="this.onload=null;this.rel=\'stylesheet\'" />';
1732
+ echo '<noscript><link rel="stylesheet" href="'.$hurl.'" media="'.$mediatype.'" /></noscript>';
1733
+ echo '<!--[if IE]><link rel="stylesheet" href="'.$hurl.'" media="'.$mediatype.'" /><![endif]-->';
1734
+ $done = array_merge($done, array($handle)); continue;
1735
+ }
1736
+
1737
+ # font awesome processing, async and exclude from PSI
1738
+ if($fvm_fawesome_method == 3 && stripos($hurl, 'font-awesome') !== false) {
1739
+ $cssguid = 'fvm'.hash('adler32', $hurl);
1740
+ echo '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){';
1741
+ echo 'var '.$cssguid.'=document.createElement("link");'.$cssguid.'.rel="stylesheet",'.$cssguid.'.type="text/css",'.$cssguid.'.media="async",'.$cssguid.'.href="'.$hurl.'",'.$cssguid.'.onload=function(){'.$cssguid.'.media="'.$mediatype.'"},document.getElementsByTagName("head")[0].appendChild('.$cssguid.');';
1742
+ echo '}</script>';
1743
+ $done = array_merge($done, array($handle)); continue;
1744
+ }
1745
+
1746
+ # array of info to save
1747
+ $arr = array('handle'=>$handle, 'url'=>$hurl, 'conditional'=>$conditional, 'mediatype'=>$mediatype);
1748
+
1749
+ # google fonts to the top (collect and skip process array)
1750
+ if (stripos($hurl, 'fonts.googleapis.com') !== false) {
1751
+ if($remove_googlefonts != false) { $done = array_merge($done, array($handle)); continue; } # mark as done if to be removed
1752
+ if($skip_google_fonts != true || $force_inline_googlefonts != false) {
1753
+ $google_fonts[$handle] = $hurl;
1754
+
1755
+ } else {
1756
+ wp_enqueue_style($handle); # skip google fonts optimization?
1757
+ }
1758
+ continue;
1759
+ }
1760
+
1761
+ # all else
1762
+ $process[$handle] = $arr;
1763
+
1764
+ endforeach;
1765
+
1766
+
1767
+ # concat google fonts, if enabled
1768
+ if(!$skip_google_fonts && count($google_fonts) > 0 || ($force_inline_googlefonts != false && count($google_fonts) > 0)) {
1769
+ foreach ($google_fonts as $h=>$a) { $done = array_merge($done, array($h)); } # mark as done
1770
+
1771
+ # merge google fonts if force inlining is enabled?
1772
+ $nfonts = array();
1773
+ if($skip_google_fonts != true) {
1774
+ $nfonts[] = fvm_get_protocol(fastvelocity_min_concatenate_google_fonts($google_fonts));
1775
+ } else {
1776
+ foreach ($google_fonts as $a) { if(!empty($a)) { $nfonts[] = $a; } }
1777
+ }
1778
+
1779
+ # foreach google font (will be one if merged is not disabled)
1780
+ if(count($nfonts) > 0) {
1781
+ foreach($nfonts as $gfurl) {
1782
+
1783
+ # hide from PSI, async, inline, or default
1784
  if($css_hide_googlefonts == true) {
1785
+
1786
+ # make a stylesheet, hide from PSI
1787
+ $cssguid = 'fvm'.hash('adler32', $gfurl);
1788
  echo '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){';
1789
+ echo 'var '.$cssguid.'=document.createElement("link");'.$cssguid.'.rel="stylesheet",'.$cssguid.'.type="text/css",'.$cssguid.'.media="async",'.$cssguid.'.href="'.$gfurl.'",'.$cssguid.'.onload=function(){'.$cssguid.'.media="all"},document.getElementsByTagName("head")[0].appendChild('.$cssguid.');';
1790
+ echo '}</script>';
1791
+
1792
+ # async CSS
1793
+ } elseif ($min_async_googlefonts == true) {
1794
+ echo '<link rel="preload" href="'.$gfurl.'" as="style" media="all" onload="this.onload=null;this.rel=\'stylesheet\'" />';
1795
+ echo '<noscript><link rel="stylesheet" href="'.$gfurl.'" media="all" /></noscript>';
1796
+ echo '<!--[if IE]><link rel="stylesheet" href="'.$gfurl.'" media="all" /><![endif]-->';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1797
 
1798
+ # inline css
1799
+ } elseif($force_inline_googlefonts == true) {
1800
+
1801
+ # download, minify, cache
1802
+ $tkey = 'css-'.$ctime.'-'.hash('adler32', $gfurl).'.css';
1803
+ $json = false; $json = fvm_get_transient($tkey);
1804
+ if ( $json === false) {
1805
+ $json = fvm_download_and_minify($gfurl, null, $disable_css_minification, 'css', null);
1806
+ if($fvm_debug == true) { echo "<!-- FVM DEBUG: Uncached file processing now for $gfurl -->" . PHP_EOL; }
1807
+ fvm_set_transient($tkey, $json);
1808
  }
1809
 
1810
+ # decode
1811
+ $res = json_decode($json, true);
1812
+
1813
+ # response has failed
1814
+ if($res['status'] != true) {
1815
+ $log.= $res['log'];
1816
+ continue;
1817
+ }
1818
+
1819
+ # inline css or fail
1820
+ if($res['code'] !== false) {
1821
+
1822
+ # add font-display
1823
+ # https://developers.google.com/web/updates/2016/02/font-display
1824
+ $res['code'] = str_ireplace('font-style:normal;', 'font-display:block;font-style:normal;', $res['code']);
1825
 
1826
+ # inline
1827
+ echo '<style type="text/css" media="all">'.$res['code'].'</style>'.PHP_EOL;
1828
+ } else {
1829
+ echo "<!-- GOOGLE FONTS REQUEST FAILED for $gfurl -->\n";
 
 
 
 
 
 
 
 
 
1830
  }
1831
+
1832
+ # fallback, enqueue google fonts
1833
+ } else {
1834
+ wp_enqueue_style('header-fvm-fonts', $gfurl, array(), null, 'all');
1835
  }
1836
 
 
 
 
 
 
 
1837
  }
1838
+ }
 
 
 
1839
  }
1840
 
1841
 
1842
+ # get groups of handles
1843
+ foreach( $styles->to_do as $handle ) :
1844
+
1845
+ # skip already processed google fonts and empty dependencies
1846
+ if(isset($google_fonts[$handle])) { continue; } # skip google fonts
1847
+ if(empty($wp_styles->registered[$handle]->src)) { continue; } # skip empty src
1848
+ if (fastvelocity_min_in_arrayi($handle, $done)) { continue; } # skip if marked as done before
1849
+ if (!isset($process[$handle])) { continue; } # skip if not on our unique process list
1850
+
1851
+ # get full url
1852
+ $hurl = $process[$handle]['url'];
1853
+ $conditional = $process[$handle]['conditional'];
1854
+ $mediatype = $process[$handle]['mediatype'];
1855
+
1856
+ # IE only files don't increment things
1857
+ $ieonly = fastvelocity_ie_blacklist($hurl);
1858
+ if($ieonly == true) { continue; }
1859
 
1860
+ # skip ignore list, conditional css, external css, font-awesome merge
1861
+ if ( (!fastvelocity_min_in_arrayi($hurl, $ignore) && !isset($conditional) && fvm_internal_url($hurl, $wp_home))
1862
+ || empty($hurl)
1863
+ || ($fvm_fawesome_method == 1 && stripos($hurl, 'font-awesome') !== false)) {
1864
 
1865
+ # colect inline css for this handle
1866
+ if(isset($wp_styles->registered[$handle]->extra['after']) && is_array($wp_styles->registered[$handle]->extra['after'])) {
1867
+ $inline_css[$handle] = fastvelocity_min_minify_css_string(implode('', $wp_styles->registered[$handle]->extra['after'])); # save
1868
+ $wp_styles->registered[$handle]->extra['after'] = null; # dequeue
1869
+ }
1870
 
1871
+ # process
1872
+ if(isset($header[count($header)-1]['handle']) || count($header) == 0 || $header[count($header)-1]['media'] != $mediatype) {
1873
+ array_push($header, array('handles'=>array(), 'media'=>$mediatype));
1874
+ }
1875
 
1876
+ # push it to the array
1877
+ array_push($header[count($header)-1]['handles'], $handle);
1878
+
1879
+ # external and ignored css
1880
+ } else {
1881
 
1882
+ # normal enqueuing
1883
+ array_push($header, array('handle'=>$handle));
1884
+ }
1885
+ endforeach;
1886
+
1887
+ # reorder CSS by mediatypes
1888
+ if(!$skip_cssorder) {
1889
+ if(count($header) > 0) {
1890
+
1891
+ # get unique mediatypes
1892
+ $allmedia = array();
1893
+ foreach($header as $array) {
1894
+ if(isset($array['media'])) { $allmedia[$array['media']] = ''; }
1895
  }
1896
 
1897
+ # extract handles by mediatype
1898
+ $grouphandles = array();
1899
+ foreach ($allmedia as $md=>$var) {
1900
+ foreach($header as $array) {
1901
+ if (isset($array['media']) && $array['media'] === $md) {
1902
+ foreach($array['handles'] as $h) { $grouphandles[$md][] = $h; }
1903
+ }
1904
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1905
  }
1906
+
1907
+ # reset and reorder header by mediatypes
1908
+ $newheader = array();
1909
+ foreach ($allmedia as $md=>$var) { $newheader[] = array('handles' => $grouphandles[$md], 'media'=>$md); }
1910
+ if(count($newheader) > 0) { $header = $newheader; }
1911
+ }
1912
+ }
1913
+
1914
+ # loop through header css and merge
1915
+ for($i=0,$l=count($header);$i<$l;$i++) {
1916
+ if(!isset($header[$i]['handle'])) {
1917
 
1918
+ # get has for the inline css in this group
1919
+ $inline_css_group = array();
1920
+ foreach($header[$i]['handles'] as $h) { if(isset($inline_css[$h]) && !empty($inline_css[$h])) { $inline_css_group[] = $inline_css[$h]; } }
1921
+ $inline_css_hash = md5(implode('',$inline_css_group));
 
 
 
 
1922
 
1923
+ # static cache file info + done
1924
+ $done = array_merge($done, $header[$i]['handles']);
1925
+ $hash = 'header-'.hash('adler32',implode('',$header[$i]['handles']).$inline_css_hash);
1926
+
1927
  # create cache files and urls
 
1928
  $file = $cachedir.'/'.$hash.'-'.$ctime.'.min.css';
1929
+ $file_url = fvm_get_protocol($cachedirurl.'/'.$hash.'-'.$ctime.'.min.css');
1930
 
1931
  # generate a new cache file
1932
  clearstatcache();
1933
  if (!file_exists($file)) {
1934
 
1935
+ # code and log initialization
1936
+ $log = '';
1937
+ $code = '';
1938
+
1939
+ # minify and write to file
1940
+ foreach($header[$i]['handles'] as $handle) :
1941
+ if(!empty($wp_styles->registered[$handle]->src)) {
1942
+
1943
+ # get hurl per handle
1944
+ $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
1945
+ $printurl = str_ireplace(array(site_url(), home_url(), 'http:', 'https:'), '', $hurl);
1946
+
1947
+ # download, minify, cache
1948
+ $tkey = 'css-'.$ctime.'-'.hash('adler32', $handle.$hurl).'.css';
1949
+ $json = false; $json = fvm_get_transient($tkey);
1950
+ if ( $json === false) {
1951
+ $json = fvm_download_and_minify($hurl, null, $disable_css_minification, 'css', $handle);
1952
+ if($fvm_debug == true) { echo "<!-- FVM DEBUG: Uncached file processing now for $handle / $hurl -->" . PHP_EOL; }
1953
+ fvm_set_transient($tkey, $json);
1954
+ }
1955
+
1956
+ # decode
1957
+ $res = json_decode($json, true);
1958
+
1959
+ # response has failed
1960
+ if($res['status'] != true) {
1961
+ $log.= $res['log'];
1962
+ continue;
1963
+ }
1964
+
1965
+ # append code to merged file
1966
+ $code.= $res['code'];
1967
+ $log.= $res['log'];
1968
+
1969
+ # append inlined styles
1970
+ if(isset($inline_css[$handle]) && !empty($inline_css[$handle])) {
1971
+ $code.= $inline_css[$handle];
1972
+ }
1973
+
1974
+ # consider dependencies on handles with an empty src
1975
+ } else {
1976
+ wp_dequeue_script($handle);
1977
+ wp_enqueue_script($handle);
1978
+ }
1979
+ endforeach;
1980
+
1981
  # prepare log
1982
+ $log = "PROCESSED on ".date('r').PHP_EOL.$log."PROCESSED from ".home_url(add_query_arg( NULL, NULL )).PHP_EOL;
1983
 
1984
  # generate cache, write log
1985
  if(!empty($code)) {
2000
  }
2001
  }
2002
 
2003
+ # register and enqueue minified file, consider excluding of mediatype "print" and inline css
2004
+ if ($remove_print_mediatypes != true || ($remove_print_mediatypes == true && $header[$i]['media'] != 'print')) {
2005
+
2006
+ # the developers tab, takes precedence
2007
+
2008
+ # Async CSS with loadCSS ?
2009
+ if($fvmloadcss != false && $fvm_remove_css != true) {
2010
+ $mt = $header[$i]['media'];
2011
+ echo '<link rel="preload" href="'.$file_url.'" as="style" media="'.$mt.'" onload="this.onload=null;this.rel=\'stylesheet\'" />';
2012
+ echo '<noscript><link rel="stylesheet" href="'.$file_url.'" media="'.$mt.'" /></noscript>';
2013
+ echo '<!--[if IE]><link rel="stylesheet" href="'.$file_url.'" media="'.$mt.'" /><![endif]-->';
2014
+
2015
+ # enqueue file, if not empty
2016
+ } else {
2017
+ if(file_exists($file) && filesize($file) > 0) {
2018
+
2019
+ # inline CSS if mediatype is not of type "all" (such as mobile only), if the file is smaller than 20KB
2020
+ if(filesize($file) < 20000 && $header[$i]['media'] != 'all') {
2021
+ echo '<style id="fvm-header-'.$i.'" media="'.$header[$i]['media'].'">'.file_get_contents($file).'</style>';
2022
+ } else {
2023
+ # enqueue it
2024
+ wp_enqueue_style("fvm-header-$i", $file_url, array(), null, $header[$i]['media']);
2025
+ }
2026
+ } else {
2027
+ # file could not be generated, output something meaningful
2028
+ echo "<!-- ERROR: FVM was not allowed to save it's cache on - $file -->";
2029
+ echo "<!-- Please check if the path above is correct and ensure your server has writting permission there! -->";
2030
+ echo "<!-- If you found a bug, please report this on https://wordpress.org/support/plugin/fast-velocity-minify/ -->";
2031
+ }
2032
+ }
2033
+ }
2034
+
2035
+ # other css need to be requeued for the order of files to be kept
2036
+ } else {
2037
+ wp_dequeue_style($header[$i]['handle']);
2038
+ wp_enqueue_style($header[$i]['handle']);
2039
+ }
2040
+ }
2041
+
2042
+ # remove from queue
2043
+ $wp_styles->done = $done;
2044
+
2045
+ }
2046
+ ###########################################
2047
+
2048
+
2049
+ ###########################################
2050
+ # process css in the footer ###############
2051
+ ###########################################
2052
+ function fastvelocity_min_merge_footer_css() {
2053
+ global $wp_styles, $wp_domain, $wp_home, $wp_home_path, $cachedir, $cachedirurl, $ignore, $disable_css_merge, $disable_css_minification, $skip_google_fonts, $skip_cssorder, $remove_print_mediatypes, $force_inline_googlefonts, $css_hide_googlefonts, $min_async_googlefonts, $remove_googlefonts, $fvmloadcss, $fvm_remove_css, $fvmualist, $fvm_debug, $fvm_fawesome_method, $fvm_min_excludecsslist, $force_inline_css_footer;
2054
+
2055
+ if(!is_object($wp_styles)) { return false; }
2056
+ $ctime = get_option('fvm-last-cache-update', '0');
2057
+ $styles = wp_clone($wp_styles);
2058
+ $styles->all_deps($styles->queue);
2059
+ $done = $styles->done;
2060
+ $footer = array();
2061
+ $google_fonts = array();
2062
+ $inline_css = array();
2063
+
2064
+ # dequeue all styles
2065
+ if($fvm_remove_css != false) {
2066
+ foreach( $styles->to_do as $handle ) :
2067
+ $done = array_merge($done, array($handle));
2068
+ endforeach;
2069
+
2070
+ # remove from queue
2071
+ $wp_styles->done = $done;
2072
+ return false;
2073
+ }
2074
+
2075
+
2076
+ # add defaults to ignore list
2077
+ $ignore = fastvelocity_default_ignore($ignore);
2078
+
2079
+ # google fonts to the top
2080
+ foreach( $styles->to_do as $handle ) :
2081
+
2082
+ # dequeue and get a list of google fonts, or requeue external
2083
+ $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
2084
+
2085
+ if (stripos($hurl, 'fonts.googleapis.com') !== false) {
2086
+ wp_dequeue_style($handle);
2087
+ if($remove_googlefonts != false) { $done = array_merge($done, array($handle)); continue; } # mark as done if to be removed
2088
+ if($skip_google_fonts != true || $force_inline_googlefonts != false) {
2089
+ $google_fonts[$handle] = $hurl;
2090
  } else {
2091
+ wp_enqueue_style($handle); # skip google fonts optimization?
2092
+ }
2093
+ } else {
2094
+ wp_dequeue_style($handle); wp_enqueue_style($handle); # failsafe
2095
+ }
2096
+
2097
+ endforeach;
2098
+
2099
+
2100
+ # concat google fonts, if enabled
2101
+ if(!$skip_google_fonts && count($google_fonts) > 0 || ($force_inline_googlefonts != false && count($google_fonts) > 0)) {
2102
+ foreach ($google_fonts as $h=>$a) { $done = array_merge($done, array($h)); } # mark as done
2103
+
2104
+ # merge google fonts if force inlining is enabled?
2105
+ $nfonts = array();
2106
+ if($skip_google_fonts != true) {
2107
+ $nfonts[] = fvm_get_protocol(fastvelocity_min_concatenate_google_fonts($google_fonts));
2108
+ } else {
2109
+ foreach ($google_fonts as $a) { if(!empty($a)) { $nfonts[] = $a; } }
2110
+ }
2111
+
2112
+ # foreach google font (will be one if merged is not disabled)
2113
+ if(count($nfonts) > 0) {
2114
+ foreach($nfonts as $gfurl) {
2115
+
2116
+ # hide from PSI, async, inline, or default
2117
+ if($css_hide_googlefonts == true) {
2118
+
2119
+ # make a stylesheet, hide from PSI
2120
+ $cssguid = 'fvm'.hash('adler32', $gfurl);
2121
+ echo '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){';
2122
+ echo 'var '.$cssguid.'=document.createElement("link");'.$cssguid.'.rel="stylesheet",'.$cssguid.'.type="text/css",'.$cssguid.'.media="async",'.$cssguid.'.href="'.$gfurl.'",'.$cssguid.'.onload=function(){'.$cssguid.'.media="all"},document.getElementsByTagName("head")[0].appendChild('.$cssguid.');';
2123
+ echo '}</script>';
2124
+
2125
+ # async CSS
2126
+ } elseif ($min_async_googlefonts == true) {
2127
+ echo '<link rel="preload" href="'.$gfurl.'" as="style" media="all" onload="this.onload=null;this.rel=\'stylesheet\'" />';
2128
+ echo '<noscript><link rel="stylesheet" href="'.$gfurl.'" media="all" /></noscript>';
2129
+ echo '<!--[if IE]><link rel="stylesheet" href="'.$gfurl.'" media="all" /><![endif]-->';
2130
+
2131
+ # inline css
2132
+ } elseif($force_inline_googlefonts == true) {
2133
+
2134
+ # download, minify, cache
2135
+ $tkey = 'css-'.$ctime.'-'.hash('adler32', $gfurl).'.css';
2136
+ $json = false; $json = fvm_get_transient($tkey);
2137
+ if ( $json === false) {
2138
+ $json = fvm_download_and_minify($gfurl, null, $disable_css_minification, 'css', null);
2139
+ if($fvm_debug == true) { echo "<!-- FVM DEBUG: Uncached file processing now for $gfurl -->" . PHP_EOL; }
2140
+ fvm_set_transient($tkey, $json);
2141
+ }
2142
+
2143
+ # decode
2144
+ $res = json_decode($json, true);
2145
+
2146
+ # response has failed
2147
+ if($res['status'] != true) {
2148
+ $log.= $res['log'];
2149
+ continue;
2150
+ }
2151
+
2152
+ # append code to merged file
2153
+ $code.= $res['code'];
2154
+ $log.= $res['log'];
2155
 
2156
+ # inline css or fail
2157
+ if($res['code'] !== false) {
2158
+ echo '<style type="text/css" media="all">'.$res['code'].'</style>'.PHP_EOL;
2159
  } else {
2160
+ echo "<!-- GOOGLE FONTS REQUEST FAILED for $gfurl -->\n";
 
 
 
 
 
 
 
2161
  }
2162
+
2163
+ # fallback, enqueue google fonts
2164
  } else {
2165
+ wp_enqueue_style('footer-fvm-fonts', $gfurl, array(), null, 'all');
 
 
 
2166
  }
2167
+
2168
  }
 
 
 
2169
  }
2170
+ }
2171
+
2172
+
2173
+ # get groups of handles
2174
+ $uniq = array();
2175
+ foreach( $styles->to_do as $handle ) :
2176
+
2177
+ # skip already processed google fonts
2178
+ if(isset($google_fonts[$handle])) { continue; }
2179
 
2180
+ # conditionals
2181
+ $conditional = NULL; if(isset($wp_styles->registered[$handle]->extra["conditional"])) {
2182
+ $conditional = $wp_styles->registered[$handle]->extra["conditional"]; # such as ie7, ie8, ie9, etc
2183
+ }
2184
 
2185
+ # mediatype
2186
+ $mt = isset($wp_styles->registered[$handle]->args) ? $wp_styles->registered[$handle]->args : 'all';
2187
+ if ($mt == 'screen' || $mt == 'screen, print' || empty($mt) || is_null($mt) || $mt == false) { $mt = 'all'; }
2188
+ $mediatype = $mt;
2189
 
2190
+ # get full url
2191
+ $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
 
2192
 
2193
+ # mark duplicates as done and remove from the queue
2194
+ if(!empty($hurl)) {
2195
+ $key = hash('adler32', $hurl);
2196
+ if (isset($uniq[$key])) { $done = array_merge($done, array($handle)); continue; } else { $uniq[$key] = $handle; }
2197
+ }
2198
+
2199
+ # IE only files don't increment things
2200
+ $ieonly = fastvelocity_ie_blacklist($hurl);
2201
+ if($ieonly == true) { continue; }
2202
+
2203
+
2204
+ # Exclude specific CSS files from PSI?
2205
+ if($fvm_min_excludecsslist != false && is_array($fvm_min_excludecsslist) && fastvelocity_min_in_arrayi($hurl, $fvm_min_excludecsslist)) {
2206
+ $cssguid = 'fvm'.hash('adler32', $hurl);
2207
+ echo '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){';
2208
+ echo 'var '.$cssguid.'=document.createElement("link");'.$cssguid.'.rel="stylesheet",'.$cssguid.'.type="text/css",'.$cssguid.'.media="async",'.$cssguid.'.href="'.$hurl.'",'.$cssguid.'.onload=function(){'.$cssguid.'.media="'.$mediatype.'"},document.getElementsByTagName("head")[0].appendChild('.$cssguid.');';
2209
+ echo '}</script>';
2210
+ $done = array_merge($done, array($handle)); continue;
2211
+ }
2212
+
2213
+ # font awesome processing, async css
2214
+ if($fvm_fawesome_method == 2 && stripos($hurl, 'font-awesome') !== false) {
2215
+ echo '<link rel="preload" href="'.$hurl.'" as="style" media="'.$mediatype.'" onload="this.onload=null;this.rel=\'stylesheet\'" />';
2216
+ echo '<noscript><link rel="stylesheet" href="'.$hurl.'" media="'.$mediatype.'" /></noscript>';
2217
+ echo '<!--[if IE]><link rel="stylesheet" href="'.$hurl.'" media="'.$mediatype.'" /><![endif]-->';
2218
+ $done = array_merge($done, array($handle)); continue;
2219
+ }
2220
+
2221
+ # font awesome processing, async and exclude from PSI
2222
+ if($fvm_fawesome_method == 3 && stripos($hurl, 'font-awesome') !== false) {
2223
+ $cssguid = 'fvm'.hash('adler32', $hurl);
2224
+ echo '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){';
2225
+ echo 'var '.$cssguid.'=document.createElement("link");'.$cssguid.'.rel="stylesheet",'.$cssguid.'.type="text/css",'.$cssguid.'.media="async",'.$cssguid.'.href="'.$hurl.'",'.$cssguid.'.onload=function(){'.$cssguid.'.media="'.$mediatype.'"},document.getElementsByTagName("head")[0].appendChild('.$cssguid.');';
2226
+ echo '}</script>';
2227
+ $done = array_merge($done, array($handle)); continue;
2228
+ }
2229
+
2230
+ # skip ignore list, conditional css, external css, font-awesome merge
2231
+ if ( (!fastvelocity_min_in_arrayi($hurl, $ignore) && !isset($conditional) && fvm_internal_url($hurl, $wp_home))
2232
+ || empty($hurl)
2233
+ || ($fvm_fawesome_method == 1 && stripos($hurl, 'font-awesome') !== false)) {
2234
+
2235
+ # colect inline css for this handle
2236
+ if(isset($wp_styles->registered[$handle]->extra['after']) && is_array($wp_styles->registered[$handle]->extra['after'])) {
2237
+ $inline_css[$handle] = fastvelocity_min_minify_css_string(implode('', $wp_styles->registered[$handle]->extra['after'])); # save
2238
+ $wp_styles->registered[$handle]->extra['after'] = null; # dequeue
2239
+ }
2240
+
2241
+ # process
2242
+ if(isset($footer[count($footer)-1]['handle']) || count($footer) == 0 || $footer[count($footer)-1]['media'] != $wp_styles->registered[$handle]->args) {
2243
+ array_push($footer, array('handles'=>array(),'media'=>$mediatype));
2244
+ }
2245
+
2246
+ # push it to the array get latest modified time
2247
+ array_push($footer[count($footer)-1]['handles'], $handle);
2248
+
2249
+ # external and ignored css
2250
+ } else {
2251
+
2252
+ # normal enqueueing
2253
+ array_push($footer, array('handle'=>$handle));
2254
+ }
2255
+ endforeach;
2256
 
2257
 
2258
+ # reorder CSS by mediatypes
2259
+ if(!$skip_cssorder) {
2260
+ if(count($footer) > 0) {
2261
 
2262
+ # get unique mediatypes
2263
+ $allmedia = array();
2264
+ foreach($footer as $key=>$array) {
2265
+ if(isset($array['media'])) { $allmedia[$array['media']] = ''; }
2266
+ }
2267
 
2268
+ # extract handles by mediatype
2269
+ $grouphandles = array();
2270
+ foreach ($allmedia as $md=>$var) {
2271
+ foreach($footer as $array) {
2272
+ if (isset($array['media']) && $array['media'] === $md) {
2273
+ foreach($array['handles'] as $h) { $grouphandles[$md][] = $h; }
2274
+ }
2275
+ }
2276
+ }
2277
 
2278
+ # reset and reorder footer by mediatypes
2279
+ $newfooter = array();
2280
+ foreach ($allmedia as $md=>$var) { $newfooter[] = array('handles' => $grouphandles[$md], 'media'=>$md); }
2281
+ if(count($newfooter) > 0) { $footer = $newfooter; }
2282
+ }
2283
+ }
2284
 
2285
+ # loop through footer css and merge
2286
+ for($i=0,$l=count($footer);$i<$l;$i++) {
2287
+ if(!isset($footer[$i]['handle'])) {
2288
+
2289
+ # get has for the inline css in this group
2290
+ $inline_css_group = array();
2291
+ foreach($footer[$i]['handles'] as $h) { if(isset($inline_css[$h]) && !empty($inline_css[$h])) { $inline_css_group[] = $inline_css[$h]; } }
2292
+ $inline_css_hash = md5(implode('',$inline_css_group));
2293
+
2294
+ # static cache file info + done
2295
+ $done = array_merge($done, $footer[$i]['handles']);
2296
+ $hash = 'footer-'.hash('adler32',implode('',$footer[$i]['handles']).$inline_css_hash);
2297
 
2298
+ # create cache files and urls
2299
+ $file = $cachedir.'/'.$hash.'-'.$ctime.'.min.css';
2300
+ $file_url = fvm_get_protocol($cachedirurl.'/'.$hash.'-'.$ctime.'.min.css');
2301
+
2302
+ # generate a new cache file
2303
+ clearstatcache();
2304
+ if (!file_exists($file)) {
2305
+
2306
+ # code and log initialization
2307
+ $log = '';
2308
+ $code = '';
2309
+
2310
+ # minify and write to file
2311
+ foreach($footer[$i]['handles'] as $handle) :
2312
+ if(!empty($wp_styles->registered[$handle]->src)) {
2313
+
2314
+ # get hurl per handle
2315
+ $hurl = fastvelocity_min_get_hurl($wp_styles->registered[$handle]->src, $wp_domain, $wp_home);
2316
+ $printurl = str_ireplace(array(site_url(), home_url(), 'http:', 'https:'), '', $hurl);
2317
+
2318
+ # download, minify, cache
2319
+ $tkey = 'css-'.$ctime.'-'.hash('adler32', $handle.$hurl).'.css';
2320
+ $json = false; $json = fvm_get_transient($tkey);
2321
+ if ( $json === false) {
2322
+ $json = fvm_download_and_minify($hurl, null, $disable_css_minification, 'css', $handle);
2323
+ if($fvm_debug == true) { echo "<!-- FVM DEBUG: Uncached file processing now for $handle / $hurl -->" . PHP_EOL; }
2324
+ fvm_set_transient($tkey, $json);
2325
+ }
2326
+
2327
+ # decode
2328
+ $res = json_decode($json, true);
2329
+
2330
+ # response has failed
2331
+ if($res['status'] != true) {
2332
+ $log.= $res['log'];
2333
+ continue;
2334
+ }
2335
+
2336
+ # append code to merged file
2337
+ $code.= $res['code'];
2338
+ $log.= $res['log'];
2339
+
2340
+ # append inlined styles
2341
+ if(isset($inline_css[$handle]) && !empty($inline_css[$handle])) {
2342
+ $code.= $inline_css[$handle];
2343
+ }
2344
+
2345
+ # consider dependencies on handles with an empty src
2346
+ } else {
2347
+ wp_dequeue_script($handle);
2348
+ wp_enqueue_script($handle);
2349
+ }
2350
+ endforeach;
2351
+
2352
+ # prepare log
2353
+ $log = "PROCESSED on ".date('r').PHP_EOL.$log."PROCESSED from ".home_url(add_query_arg( NULL, NULL )).PHP_EOL;
2354
+
2355
+ # generate cache, add inline css, write log
2356
+ if(!empty($code)) {
2357
+ file_put_contents($file.'.txt', $log);
2358
+ file_put_contents($file, $code); # preserve style tags
2359
+ file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
2360
+
2361
+ # permissions
2362
+ fastvelocity_fix_permission_bits($file.'.txt');
2363
+ fastvelocity_fix_permission_bits($file);
2364
+ fastvelocity_fix_permission_bits($file.'.gz');
2365
+
2366
+ # brotli static support
2367
+ if(function_exists('brotli_compress')) {
2368
+ file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
2369
+ fastvelocity_fix_permission_bits($file.'.br');
2370
+ }
2371
+ }
2372
+ }
2373
 
2374
+ # register and enqueue minified file, consider excluding of mediatype "print" and inline css
2375
+ if ($remove_print_mediatypes != true || ($remove_print_mediatypes == true && $footer[$i]['media'] != 'print')) {
2376
 
2377
+ # the developers tab, takes precedence
2378
+
2379
+ # Async CSS with loadCSS ?
2380
+ if($fvmloadcss != false && $fvm_remove_css != true) {
2381
+ $mt = $footer[$i]['media'];
2382
+ echo '<link rel="preload" href="'.$file_url.'" as="style" media="'.$mt.'" onload="this.onload=null;this.rel=\'stylesheet\'" />';
2383
+ echo '<noscript><link rel="stylesheet" href="'.$file_url.'" media="'.$mt.'" /></noscript>';
2384
+ echo '<!--[if IE]><link rel="stylesheet" href="'.$file_url.'" media="'.$mt.'" /><![endif]-->';
2385
+
2386
+ # enqueue file, if not empty
2387
+ } else {
2388
+ if(file_exists($file) && filesize($file) > 0) {
2389
+
2390
+ # inline if the file is smaller than 20KB or option has been enabled
2391
+ if(filesize($file) < 20000 || $force_inline_css_footer != false) {
2392
+ echo '<style id="fvm-footer-'.$i.'" media="'.$footer[$i]['media'].'">'.file_get_contents($file).'</style>';
2393
+ } else {
2394
+ # enqueue it
2395
+ wp_enqueue_style("fvm-footer-$i", $file_url, array(), null, $footer[$i]['media']);
2396
+ }
2397
+ } else {
2398
+ # file could not be generated, output something meaningful
2399
+ echo "<!-- ERROR: FVM was not allowed to save it's cache on - $file -->";
2400
+ echo "<!-- Please check if the path above is correct and ensure your server has writting permission there! -->";
2401
+ echo "<!-- If you found a bug, please report this on https://wordpress.org/support/plugin/fast-velocity-minify/ -->";
2402
+ }
2403
+ }
2404
+ }
2405
+
2406
+ # other css need to be requeued for the order of files to be kept
2407
+ } else {
2408
+ wp_dequeue_style($footer[$i]['handle']);
2409
+ wp_enqueue_style($footer[$i]['handle']);
2410
+ }
2411
+ }
2412
 
2413
+ # remove from queue
2414
+ $wp_styles->done = $done;
2415
+ }
2416
+ ###########################################
2417
 
2418
 
2419
 
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.6
6
  Tested up to: 5.0.3
7
  License: GPLv3 or later
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -209,6 +209,9 @@ Please backup your site before updating. Version 3.0 will have a major code rewr
209
 
210
  == Changelog ==
211
 
 
 
 
212
  = 2.5.6 [2019.01.18] =
213
  * fixed some php notices
214
  * disabled FVM on amp pages
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.7
6
  Tested up to: 5.0.3
7
  License: GPLv3 or later
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
209
 
210
  == Changelog ==
211
 
212
+ = 2.5.7 [2019.02.04] =
213
+ * reverted back the css merging method to version 2.5.2 due to some compatibility issues
214
+
215
  = 2.5.6 [2019.01.18] =
216
  * fixed some php notices
217
  * disabled FVM on amp pages