PluginProbe
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score / trunk
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score vtrunk
trunk 1.0 1.0.1 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1 2.1.1 2.1.2 2.2 2.2.1 All 69 releases
← All changes | includes/classes/Optimizer/CSS.php +13 -15 2.0.3trunk View file →
@@ -55,8 +55,9 @@
55 55 *
56 56 * @return string[]
57 57 */
58 58 public function do_items( $handles = false, $group = false ) {
59 + $abspath = wp_normalize_path( ABSPATH );
59 60 $handles = false === $handles ? $this->queue : (array) $handles;
60 61 $stylesheets = array();
61 62 /**
62 63 * Filters site url
@@ -74,18 +75,10 @@
74 75 $stylesheet_group_index = 0;
75 76 foreach ( $this->to_do as $key => $handle ) {
76 77 $obj = $this->registered[ $handle ];
77 78
78 - if ( $this->enable_cdn ) { // since CDN replaces hostname, it breaks is_internal_url checks.
79 - remove_filter( 'style_loader_src', array( CDN::factory(), 'cdn_url' ), PHP_INT_MAX );
80 - }
81 -
82 79 $obj->src = apply_filters( 'style_loader_src', $obj->src, $obj->handle );
83 80
84 - if ( $this->enable_cdn ) { // add filter back
85 - add_filter( 'style_loader_src', array( CDN::factory(), 'cdn_url' ), PHP_INT_MAX );
86 - }
87 -
88 81 // Core is kind of broken and returns "true" for src of "colors" handle
89 82 // http://core.trac.wordpress.org/attachment/ticket/16827/colors-hacked-fixed.diff
90 83 // http://core.trac.wordpress.org/ticket/20729
91 84 $css_url = $obj->src;
@@ -120,14 +113,14 @@
120 113 $do_concat = false;
121 114 }
122 115
123 116 // Concat and canonicalize the paths only for
124 - // existing scripts that aren't outside ABSPATH
117 + // existing scripts that aren't outside $abspath
125 118 $css_realpath = Helper::realpath( $css_url, $siteurl );
126 - if ( ! $css_realpath || 0 !== strpos( $css_realpath, ABSPATH ) ) {
119 + if ( ! $css_realpath || 0 !== strpos( $css_realpath, $abspath ) ) {
127 120 $do_concat = false;
128 121 } else {
129 - $css_url_parsed['path'] = substr( $css_realpath, strlen( ABSPATH ) - 1 );
122 + $css_url_parsed['path'] = substr( $css_realpath, strlen( $abspath ) - 1 );
130 123 }
131 124
132 125 if ( Helper::is_excluded_css( $css_url ) ) {
133 126 $do_concat = false;
@@ -139,13 +132,14 @@
139 132 * @hook powered_cache_fo_css_do_concat
140 133 *
141 134 * @param {boolean} $do_concat Contact status.
142 135 * @param {string} $handle Handle of registered CSS item.
136 + * @param {string} $css_url CSS Url. @since 3.2.1
143 137 *
144 138 * @return {boolean} New value.
145 139 * @since 2.0
146 140 */
147 - $do_concat = apply_filters( 'powered_cache_fo_css_do_concat', $do_concat, $handle );
141 + $do_concat = apply_filters( 'powered_cache_fo_css_do_concat', $do_concat, $handle, $css_url );
148 142
149 143 if ( true === $do_concat ) {
150 144 $media = $obj->args;
151 145 if ( empty( $media ) ) {
@@ -176,10 +170,10 @@
176 170 }
177 171 continue;
178 172 } elseif ( count( $css ) > 1 ) {
179 173 $paths = array_map(
180 - function ( $url ) {
181 - return ABSPATH . $url;
174 + function ( $url ) use ( $abspath ) {
175 + return $abspath . $url;
182 176 },
183 177 $css
184 178 );
185 179 $mtime = max( array_map( 'filemtime', $paths ) );
@@ -193,9 +187,13 @@
193 187 }
194 188
195 189 $href = Helper::get_optimized_url( $path_str, $this->do_minify );
196 190 } else {
197 - $href = $this->cache_bust_mtime( $siteurl . current( $css ), $siteurl );
191 + if ( $this->do_minify ) {
192 + $href = Helper::get_optimized_url( current( $css ), $this->do_minify );
193 + } else {
194 + $href = $this->cache_bust_mtime( $siteurl . current( $css ), $siteurl );
195 + }
198 196 }
199 197
200 198 $handles = array_keys( $css );
201 199 $css_tag = "<link rel='stylesheet' id='$media-css-$idx' href='$href' type='text/css' media='$media' />\n"; // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet