@@ -57,7 +57,7 @@ |
||
57 | 57 | * Update the compiled CSS for the given handle. |
58 | 58 | * |
59 | 59 | * @param string $handle The handle of the stylesheet |
60 | - * @param type $compiled_css |
|
60 | + * @param string $compiled_css |
|
61 | 61 | */ |
62 | 62 | public function update( $handle, $compiled_css ) |
63 | 63 | { |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | /** |
142 | 142 | * Register a value retrieval function and associate it with the given handle |
143 | 143 | * |
144 | - * @param type $handle The stylesheet's name/id |
|
144 | + * @param string $handle The stylesheet's name/id |
|
145 | 145 | * @param type $callback |
146 | 146 | */ |
147 | 147 | public function register_callback( $handle, $callback ) |
@@ -151,6 +151,9 @@ discard block |
||
151 | 151 | |
152 | 152 | /** |
153 | 153 | * Register a filter function for a given stylesheet handle. |
154 | + * @param string $handle |
|
155 | + * @param string $filter_name |
|
156 | + * @param callable $callback |
|
154 | 157 | */ |
155 | 158 | public function register_filter( $handle, $filter_name, $callback ) |
156 | 159 | { |
@@ -62,16 +62,16 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function enqueue_styles() |
64 | 64 | { |
65 | - foreach( $this->stylesheets as $stylesheet ) |
|
65 | + foreach ($this->stylesheets as $stylesheet) |
|
66 | 66 | { |
67 | - if( !$stylesheet['print'] && $this->callback_exists( $stylesheet['handle'] ) ) |
|
67 | + if (!$stylesheet['print'] && $this->callback_exists($stylesheet['handle'])) |
|
68 | 68 | { |
69 | 69 | wp_enqueue_style( |
70 | 70 | 'wp-dynamic-css-'.$stylesheet['handle'], |
71 | - esc_url_raw( add_query_arg(array( |
|
71 | + esc_url_raw(add_query_arg(array( |
|
72 | 72 | 'action' => 'wp_dynamic_css', |
73 | 73 | 'handle' => $stylesheet['handle'] |
74 | - ), admin_url( 'admin-ajax.php'))) |
|
74 | + ), admin_url('admin-ajax.php'))) |
|
75 | 75 | ); |
76 | 76 | } |
77 | 77 | } |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function print_styles() |
84 | 84 | { |
85 | - foreach( $this->stylesheets as $stylesheet ) |
|
85 | + foreach ($this->stylesheets as $stylesheet) |
|
86 | 86 | { |
87 | - if( $stylesheet['print'] && $this->callback_exists( $stylesheet['handle'] ) ) |
|
87 | + if ($stylesheet['print'] && $this->callback_exists($stylesheet['handle'])) |
|
88 | 88 | { |
89 | - $compiled_css = $this->get_compiled_style( $stylesheet ); |
|
89 | + $compiled_css = $this->get_compiled_style($stylesheet); |
|
90 | 90 | |
91 | 91 | echo "<style id=\"wp-dynamic-css-".$stylesheet['handle']."\">\n"; |
92 | 92 | include 'style.phtml'; |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function ajax_callback() |
103 | 103 | { |
104 | - header( "Content-type: text/css; charset: UTF-8" ); |
|
105 | - $handle = filter_input( INPUT_GET, 'handle' ); |
|
104 | + header("Content-type: text/css; charset: UTF-8"); |
|
105 | + $handle = filter_input(INPUT_GET, 'handle'); |
|
106 | 106 | |
107 | - foreach( $this->stylesheets as $stylesheet ) |
|
107 | + foreach ($this->stylesheets as $stylesheet) |
|
108 | 108 | { |
109 | - if( $handle === $stylesheet['handle'] ) |
|
109 | + if ($handle === $stylesheet['handle']) |
|
110 | 110 | { |
111 | - $compiled_css = $this->get_compiled_style( $stylesheet ); |
|
111 | + $compiled_css = $this->get_compiled_style($stylesheet); |
|
112 | 112 | include 'style.phtml'; |
113 | 113 | } |
114 | 114 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @param boolean $cache Whether to store the compiled version of this |
128 | 128 | * stylesheet in cache to avoid compilation on every page load. |
129 | 129 | */ |
130 | - public function enqueue_style( $handle, $path, $print, $minify, $cache ) |
|
130 | + public function enqueue_style($handle, $path, $print, $minify, $cache) |
|
131 | 131 | { |
132 | 132 | $this->stylesheets[] = array( |
133 | 133 | 'handle'=> $handle, |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @param type $handle The stylesheet's name/id |
145 | 145 | * @param type $callback |
146 | 146 | */ |
147 | - public function register_callback( $handle, $callback ) |
|
147 | + public function register_callback($handle, $callback) |
|
148 | 148 | { |
149 | 149 | $this->callbacks[$handle] = $callback; |
150 | 150 | } |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | /** |
153 | 153 | * Register a filter function for a given stylesheet handle. |
154 | 154 | */ |
155 | - public function register_filter( $handle, $filter_name, $callback ) |
|
155 | + public function register_filter($handle, $filter_name, $callback) |
|
156 | 156 | { |
157 | - if( !array_key_exists( $handle, $this->filters ) ) |
|
157 | + if (!array_key_exists($handle, $this->filters)) |
|
158 | 158 | { |
159 | 159 | $this->filters[$handle] = array(); |
160 | 160 | } |
@@ -169,31 +169,31 @@ discard block |
||
169 | 169 | * stored in $this->stylesheets |
170 | 170 | * @return string The compiled CSS for this stylesheet |
171 | 171 | */ |
172 | - protected function get_compiled_style( $style ) |
|
172 | + protected function get_compiled_style($style) |
|
173 | 173 | { |
174 | 174 | $cache = DynamicCSSCache::get_instance(); |
175 | 175 | |
176 | 176 | // Use cached compiled CSS if applicable |
177 | - if( $style['cache'] ) |
|
177 | + if ($style['cache']) |
|
178 | 178 | { |
179 | - $cached_css = $cache->get( $style['handle'] ); |
|
180 | - if( false !== $cached_css ) |
|
179 | + $cached_css = $cache->get($style['handle']); |
|
180 | + if (false !== $cached_css) |
|
181 | 181 | { |
182 | 182 | return $cached_css; |
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
186 | - $css = file_get_contents( $style['path'] ); |
|
187 | - if( $style['minify'] ) $css = $this->minify_css( $css ); |
|
186 | + $css = file_get_contents($style['path']); |
|
187 | + if ($style['minify']) $css = $this->minify_css($css); |
|
188 | 188 | |
189 | 189 | // Compile the dynamic CSS |
190 | 190 | $compiled_css = $this->compile_css( |
191 | 191 | $css, |
192 | 192 | $this->callbacks[$style['handle']], |
193 | - key_exists( $style['handle'], $this->filters ) ? $this->filters[$style['handle']] : array() |
|
193 | + key_exists($style['handle'], $this->filters) ? $this->filters[$style['handle']] : array() |
|
194 | 194 | ); |
195 | 195 | |
196 | - $cache->update( $style['handle'], $compiled_css ); |
|
196 | + $cache->update($style['handle'], $compiled_css); |
|
197 | 197 | return $compiled_css; |
198 | 198 | } |
199 | 199 | |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | * @param string $css CSS style to minify |
205 | 205 | * @return string Minified CSS |
206 | 206 | */ |
207 | - protected function minify_css( $css ) |
|
207 | + protected function minify_css($css) |
|
208 | 208 | { |
209 | - return preg_replace( '@({)\s+|(\;)\s+|/\*.+?\*\/|\R@is', '$1$2 ', $css ); |
|
209 | + return preg_replace('@({)\s+|(\;)\s+|/\*.+?\*\/|\R@is', '$1$2 ', $css); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -215,9 +215,9 @@ discard block |
||
215 | 215 | * @param string $handle |
216 | 216 | * @return boolean |
217 | 217 | */ |
218 | - protected function callback_exists( $handle ) |
|
218 | + protected function callback_exists($handle) |
|
219 | 219 | { |
220 | - if( array_key_exists( $handle, $this->callbacks ) ) |
|
220 | + if (array_key_exists($handle, $this->callbacks)) |
|
221 | 221 | { |
222 | 222 | return true; |
223 | 223 | } |
@@ -239,36 +239,36 @@ discard block |
||
239 | 239 | * @return string The compiled CSS after converting the variables to their |
240 | 240 | * corresponding values |
241 | 241 | */ |
242 | - protected function compile_css( $css, $callback, $filters ) |
|
242 | + protected function compile_css($css, $callback, $filters) |
|
243 | 243 | { |
244 | 244 | return preg_replace_callback( |
245 | 245 | |
246 | - "#". // Begin |
|
247 | - "\\$". // Must start with $ |
|
248 | - "([\\w-]+)". // Match alphanumeric characters and dashes |
|
249 | - "((?:\\['?[\\w-]+'?\\])*)". // Optionally match array subscripts i.e. $myVar['index'] |
|
250 | - "((?:". // Optionally match pipe filters i.e. $myVar|myFilter |
|
251 | - "\\|[\\w-]+". // Starting with the | character |
|
252 | - "(\([\w\.,']+\))?". // Filters can have strings and numbers i.e myFilter('string',1,2.5) |
|
253 | - ")*)". // Allow for 0 or more piped filters |
|
254 | - "#", // End |
|
246 | + "#".// Begin |
|
247 | + "\\$".// Must start with $ |
|
248 | + "([\\w-]+)".// Match alphanumeric characters and dashes |
|
249 | + "((?:\\['?[\\w-]+'?\\])*)".// Optionally match array subscripts i.e. $myVar['index'] |
|
250 | + "((?:".// Optionally match pipe filters i.e. $myVar|myFilter |
|
251 | + "\\|[\\w-]+".// Starting with the | character |
|
252 | + "(\([\w\.,']+\))?".// Filters can have strings and numbers i.e myFilter('string',1,2.5) |
|
253 | + ")*)".// Allow for 0 or more piped filters |
|
254 | + "#", // End |
|
255 | 255 | |
256 | - function( $matches ) use ( $callback, $filters ) |
|
256 | + function($matches) use ($callback, $filters) |
|
257 | 257 | { |
258 | 258 | $subscripts = array(); |
259 | 259 | |
260 | 260 | // If this variable is an array, get the subscripts |
261 | - if( '' !== $matches[2] ) |
|
261 | + if ('' !== $matches[2]) |
|
262 | 262 | { |
263 | 263 | preg_match_all('/[\w-]+/i', $matches[2], $subscripts); |
264 | 264 | } |
265 | 265 | |
266 | - $val = call_user_func_array( $callback, array( $matches[1],@$subscripts[0] ) ); |
|
266 | + $val = call_user_func_array($callback, array($matches[1], @$subscripts[0])); |
|
267 | 267 | |
268 | 268 | // Apply custom filters |
269 | - if( '' !== $matches[3] ) |
|
269 | + if ('' !== $matches[3]) |
|
270 | 270 | { |
271 | - $val = $this->apply_filters( substr( $matches[3], 1 ), $val, $filters ); |
|
271 | + $val = $this->apply_filters(substr($matches[3], 1), $val, $filters); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | return $val; |
@@ -284,24 +284,24 @@ discard block |
||
284 | 284 | * @param array $filters Array of callback functions |
285 | 285 | * @return string The value after all filters have been applied |
286 | 286 | */ |
287 | - protected function apply_filters( $filters_string, $value, $filters ) |
|
287 | + protected function apply_filters($filters_string, $value, $filters) |
|
288 | 288 | { |
289 | - foreach( explode( '|', $filters_string) as $filter ) |
|
289 | + foreach (explode('|', $filters_string) as $filter) |
|
290 | 290 | { |
291 | - $args = array( $value ); |
|
291 | + $args = array($value); |
|
292 | 292 | |
293 | - if( false !== strrpos( $filters_string, "(" ) ) |
|
293 | + if (false !== strrpos($filters_string, "(")) |
|
294 | 294 | { |
295 | - $pieces = explode( '(', $filter ); |
|
295 | + $pieces = explode('(', $filter); |
|
296 | 296 | $filter = $pieces[0]; |
297 | - $params = explode( ',', str_replace( ')', '', $pieces[1] ) ); |
|
298 | - array_walk( $params, array( $this, 'strtoval' ) ); // Convert string values to actual values |
|
299 | - $args = array_merge( $args, $params ); |
|
297 | + $params = explode(',', str_replace(')', '', $pieces[1])); |
|
298 | + array_walk($params, array($this, 'strtoval')); // Convert string values to actual values |
|
299 | + $args = array_merge($args, $params); |
|
300 | 300 | } |
301 | 301 | |
302 | - if( key_exists( $filter, $filters ) ) |
|
302 | + if (key_exists($filter, $filters)) |
|
303 | 303 | { |
304 | - $value = call_user_func_array( $filters[$filter], $args ); |
|
304 | + $value = call_user_func_array($filters[$filter], $args); |
|
305 | 305 | } |
306 | 306 | } |
307 | 307 | return $value; |
@@ -312,11 +312,11 @@ discard block |
||
312 | 312 | * |
313 | 313 | * @param string $str The string to be converted (passed by reference) |
314 | 314 | */ |
315 | - protected function strtoval( &$str ) |
|
315 | + protected function strtoval(&$str) |
|
316 | 316 | { |
317 | - if( 'false' === strtolower($str) ) $str = false; |
|
318 | - if( 'true' === strtolower($str) ) $str = true; |
|
319 | - if( false !== strrpos( $str, "'" ) ) $str = str_replace ( "'", "", $str ); |
|
320 | - if( is_numeric( $str ) ) $str = floatval( $str ); |
|
317 | + if ('false' === strtolower($str)) $str = false; |
|
318 | + if ('true' === strtolower($str)) $str = true; |
|
319 | + if (false !== strrpos($str, "'")) $str = str_replace("'", "", $str); |
|
320 | + if (is_numeric($str)) $str = floatval($str); |
|
321 | 321 | } |
322 | 322 | } |