@@ -20,14 +20,14 @@ discard block |
||
| 20 | 20 | * Domain Path: /languages |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | -defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
|
| 23 | +defined('ABSPATH') or die('No script kiddies please!'); |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * Prevent loading the library more than once |
| 28 | 28 | */ |
| 29 | -if( defined( 'WP_DYNAMIC_CSS' ) ) return; |
|
| 30 | -define( 'WP_DYNAMIC_CSS', true ); |
|
| 29 | +if (defined('WP_DYNAMIC_CSS')) return; |
|
| 30 | +define('WP_DYNAMIC_CSS', true); |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Load required files |
@@ -43,6 +43,6 @@ discard block |
||
| 43 | 43 | * styles. |
| 44 | 44 | */ |
| 45 | 45 | $dcss = DynamicCSSCompiler::get_instance(); |
| 46 | -add_action( 'wp_enqueue_scripts', array( $dcss, 'enqueue_styles' ), 100 ); |
|
| 47 | -add_action( 'wp_ajax_wp_dynamic_css', array( $dcss, 'ajax_callback' ) ); |
|
| 48 | -add_action( 'wp_ajax_nopriv_wp_dynamic_css', array( $dcss, 'ajax_callback' ) ); |
|
| 49 | 46 | \ No newline at end of file |
| 47 | +add_action('wp_enqueue_scripts', array($dcss, 'enqueue_styles'), 100); |
|
| 48 | +add_action('wp_ajax_wp_dynamic_css', array($dcss, 'ajax_callback')); |
|
| 49 | +add_action('wp_ajax_nopriv_wp_dynamic_css', array($dcss, 'ajax_callback')); |
|
| 50 | 50 | \ No newline at end of file |
@@ -205,10 +205,10 @@ |
||
| 205 | 205 | protected function add_meta_info( $compiled_css ) |
| 206 | 206 | { |
| 207 | 207 | return "/**\n". |
| 208 | - " * Compiled using wp-dynamic-css\n". |
|
| 209 | - " * https://github.com/askupasoftware/wp-dynamic-css\n". |
|
| 210 | - " */\n\n". |
|
| 211 | - $compiled_css; |
|
| 208 | + " * Compiled using wp-dynamic-css\n". |
|
| 209 | + " * https://github.com/askupasoftware/wp-dynamic-css\n". |
|
| 210 | + " */\n\n". |
|
| 211 | + $compiled_css; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -62,11 +62,11 @@ 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( $this->callback_exists( $stylesheet['handle'] ) ) |
|
| 67 | + if ($this->callback_exists($stylesheet['handle'])) |
|
| 68 | 68 | { |
| 69 | - $this->enqueue_style( $stylesheet ); |
|
| 69 | + $this->enqueue_style($stylesheet); |
|
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @param type $stylesheet |
| 77 | 77 | */ |
| 78 | - public function enqueue_style( $stylesheet ) |
|
| 78 | + public function enqueue_style($stylesheet) |
|
| 79 | 79 | { |
| 80 | 80 | $handle = 'wp-dynamic-css-'.$stylesheet['handle']; |
| 81 | 81 | $print = $stylesheet['print']; |
@@ -83,15 +83,15 @@ discard block |
||
| 83 | 83 | wp_register_style( |
| 84 | 84 | $handle, |
| 85 | 85 | // Don't pass a URL if this style is to be printed |
| 86 | - $print ? false : $this->get_ajax_callback_url( $stylesheet['handle'] ) |
|
| 86 | + $print ? false : $this->get_ajax_callback_url($stylesheet['handle']) |
|
| 87 | 87 | ); |
| 88 | 88 | |
| 89 | - wp_enqueue_style( $handle ); |
|
| 89 | + wp_enqueue_style($handle); |
|
| 90 | 90 | |
| 91 | - if( $stylesheet['print'] ) |
|
| 91 | + if ($stylesheet['print']) |
|
| 92 | 92 | { |
| 93 | 93 | // Inline styles only work if the handle has already been registered and enqueued |
| 94 | - wp_add_inline_style( $handle, $this->get_compiled_style( $stylesheet ) ); |
|
| 94 | + wp_add_inline_style($handle, $this->get_compiled_style($stylesheet)); |
|
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
@@ -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 | - echo $this->get_compiled_style( $stylesheet ); |
|
| 111 | + echo $this->get_compiled_style($stylesheet); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @param boolean $cache Whether to store the compiled version of this |
| 127 | 127 | * stylesheet in cache to avoid compilation on every page load. |
| 128 | 128 | */ |
| 129 | - public function register_style( $handle, $path, $print, $minify, $cache ) |
|
| 129 | + public function register_style($handle, $path, $print, $minify, $cache) |
|
| 130 | 130 | { |
| 131 | 131 | $this->stylesheets[] = array( |
| 132 | 132 | 'handle'=> $handle, |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @param type $handle The stylesheet's name/id |
| 144 | 144 | * @param type $callback |
| 145 | 145 | */ |
| 146 | - public function register_callback( $handle, $callback ) |
|
| 146 | + public function register_callback($handle, $callback) |
|
| 147 | 147 | { |
| 148 | 148 | $this->callbacks[$handle] = $callback; |
| 149 | 149 | } |
@@ -151,9 +151,9 @@ discard block |
||
| 151 | 151 | /** |
| 152 | 152 | * Register a filter function for a given stylesheet handle. |
| 153 | 153 | */ |
| 154 | - public function register_filter( $handle, $filter_name, $callback ) |
|
| 154 | + public function register_filter($handle, $filter_name, $callback) |
|
| 155 | 155 | { |
| 156 | - if( !array_key_exists( $handle, $this->filters ) ) |
|
| 156 | + if (!array_key_exists($handle, $this->filters)) |
|
| 157 | 157 | { |
| 158 | 158 | $this->filters[$handle] = array(); |
| 159 | 159 | } |
@@ -168,32 +168,32 @@ discard block |
||
| 168 | 168 | * stored in $this->stylesheets |
| 169 | 169 | * @return string The compiled CSS for this stylesheet |
| 170 | 170 | */ |
| 171 | - protected function get_compiled_style( $style ) |
|
| 171 | + protected function get_compiled_style($style) |
|
| 172 | 172 | { |
| 173 | 173 | $cache = DynamicCSSCache::get_instance(); |
| 174 | 174 | |
| 175 | 175 | // Use cached compiled CSS if applicable |
| 176 | - if( $style['cache'] ) |
|
| 176 | + if ($style['cache']) |
|
| 177 | 177 | { |
| 178 | - $cached_css = $cache->get( $style['handle'] ); |
|
| 179 | - if( false !== $cached_css ) |
|
| 178 | + $cached_css = $cache->get($style['handle']); |
|
| 179 | + if (false !== $cached_css) |
|
| 180 | 180 | { |
| 181 | 181 | return $cached_css; |
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - $css = file_get_contents( $style['path'] ); |
|
| 186 | - if( $style['minify'] ) $css = $this->minify_css( $css ); |
|
| 185 | + $css = file_get_contents($style['path']); |
|
| 186 | + if ($style['minify']) $css = $this->minify_css($css); |
|
| 187 | 187 | |
| 188 | 188 | // Compile the dynamic CSS |
| 189 | 189 | $compiled_css = $this->compile_css( |
| 190 | 190 | $css, |
| 191 | 191 | $this->callbacks[$style['handle']], |
| 192 | - key_exists( $style['handle'], $this->filters ) ? $this->filters[$style['handle']] : array() |
|
| 192 | + key_exists($style['handle'], $this->filters) ? $this->filters[$style['handle']] : array() |
|
| 193 | 193 | ); |
| 194 | 194 | |
| 195 | - $cache->update( $style['handle'], $compiled_css ); |
|
| 196 | - return $this->add_meta_info( $compiled_css ); |
|
| 195 | + $cache->update($style['handle'], $compiled_css); |
|
| 196 | + return $this->add_meta_info($compiled_css); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @param string $compiled_css The compiled CSS |
| 203 | 203 | * @return string The compiled CSS with the meta information added to it |
| 204 | 204 | */ |
| 205 | - protected function add_meta_info( $compiled_css ) |
|
| 205 | + protected function add_meta_info($compiled_css) |
|
| 206 | 206 | { |
| 207 | 207 | return "/**\n". |
| 208 | 208 | " * Compiled using wp-dynamic-css\n". |
@@ -217,14 +217,14 @@ discard block |
||
| 217 | 217 | * @param string $handle The stylesheet's handle |
| 218 | 218 | * @return string The URL for the given handle |
| 219 | 219 | */ |
| 220 | - protected function get_ajax_callback_url( $handle ) |
|
| 220 | + protected function get_ajax_callback_url($handle) |
|
| 221 | 221 | { |
| 222 | 222 | return esc_url_raw( |
| 223 | 223 | add_query_arg(array( |
| 224 | 224 | 'action' => 'wp_dynamic_css', |
| 225 | 225 | 'handle' => $handle |
| 226 | 226 | ), |
| 227 | - admin_url( 'admin-ajax.php')) |
|
| 227 | + admin_url('admin-ajax.php')) |
|
| 228 | 228 | ); |
| 229 | 229 | } |
| 230 | 230 | |
@@ -235,9 +235,9 @@ discard block |
||
| 235 | 235 | * @param string $css CSS style to minify |
| 236 | 236 | * @return string Minified CSS |
| 237 | 237 | */ |
| 238 | - protected function minify_css( $css ) |
|
| 238 | + protected function minify_css($css) |
|
| 239 | 239 | { |
| 240 | - return preg_replace( '@({)\s+|(\;)\s+|/\*.+?\*\/|\R@is', '$1$2 ', $css ); |
|
| 240 | + return preg_replace('@({)\s+|(\;)\s+|/\*.+?\*\/|\R@is', '$1$2 ', $css); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
@@ -246,9 +246,9 @@ discard block |
||
| 246 | 246 | * @param string $handle |
| 247 | 247 | * @return boolean |
| 248 | 248 | */ |
| 249 | - protected function callback_exists( $handle ) |
|
| 249 | + protected function callback_exists($handle) |
|
| 250 | 250 | { |
| 251 | - if( array_key_exists( $handle, $this->callbacks ) ) |
|
| 251 | + if (array_key_exists($handle, $this->callbacks)) |
|
| 252 | 252 | { |
| 253 | 253 | return true; |
| 254 | 254 | } |
@@ -270,36 +270,36 @@ discard block |
||
| 270 | 270 | * @return string The compiled CSS after converting the variables to their |
| 271 | 271 | * corresponding values |
| 272 | 272 | */ |
| 273 | - protected function compile_css( $css, $callback, $filters ) |
|
| 273 | + protected function compile_css($css, $callback, $filters) |
|
| 274 | 274 | { |
| 275 | 275 | return preg_replace_callback( |
| 276 | 276 | |
| 277 | - "#". // Begin |
|
| 278 | - "\\$". // Must start with $ |
|
| 279 | - "([\\w-]+)". // Match alphanumeric characters and dashes |
|
| 280 | - "((?:\\['?[\\w-]+'?\\])*)". // Optionally match array subscripts i.e. $myVar['index'] |
|
| 281 | - "((?:". // Optionally match pipe filters i.e. $myVar|myFilter |
|
| 282 | - "\\|[\\w-]+". // Starting with the | character |
|
| 283 | - "(\([\w\.,']+\))?". // Filters can have strings and numbers i.e myFilter('string',1,2.5) |
|
| 284 | - ")*)". // Allow for 0 or more piped filters |
|
| 285 | - "#", // End |
|
| 277 | + "#".// Begin |
|
| 278 | + "\\$".// Must start with $ |
|
| 279 | + "([\\w-]+)".// Match alphanumeric characters and dashes |
|
| 280 | + "((?:\\['?[\\w-]+'?\\])*)".// Optionally match array subscripts i.e. $myVar['index'] |
|
| 281 | + "((?:".// Optionally match pipe filters i.e. $myVar|myFilter |
|
| 282 | + "\\|[\\w-]+".// Starting with the | character |
|
| 283 | + "(\([\w\.,']+\))?".// Filters can have strings and numbers i.e myFilter('string',1,2.5) |
|
| 284 | + ")*)".// Allow for 0 or more piped filters |
|
| 285 | + "#", // End |
|
| 286 | 286 | |
| 287 | - function( $matches ) use ( $callback, $filters ) |
|
| 287 | + function($matches) use ($callback, $filters) |
|
| 288 | 288 | { |
| 289 | 289 | $subscripts = array(); |
| 290 | 290 | |
| 291 | 291 | // If this variable is an array, get the subscripts |
| 292 | - if( '' !== $matches[2] ) |
|
| 292 | + if ('' !== $matches[2]) |
|
| 293 | 293 | { |
| 294 | 294 | preg_match_all('/[\w-]+/i', $matches[2], $subscripts); |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - $val = call_user_func_array( $callback, array( $matches[1],@$subscripts[0] ) ); |
|
| 297 | + $val = call_user_func_array($callback, array($matches[1], @$subscripts[0])); |
|
| 298 | 298 | |
| 299 | 299 | // If there are filters, apply them |
| 300 | - if( '' !== $matches[3] ) |
|
| 300 | + if ('' !== $matches[3]) |
|
| 301 | 301 | { |
| 302 | - $val = $this->apply_filters( substr( $matches[3], 1 ), $val, $filters ); |
|
| 302 | + $val = $this->apply_filters(substr($matches[3], 1), $val, $filters); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | return $val; |
@@ -315,24 +315,24 @@ discard block |
||
| 315 | 315 | * @param array $filters Array of callback functions |
| 316 | 316 | * @return string The value after all filters have been applied |
| 317 | 317 | */ |
| 318 | - protected function apply_filters( $filters_string, $value, $filters ) |
|
| 318 | + protected function apply_filters($filters_string, $value, $filters) |
|
| 319 | 319 | { |
| 320 | - foreach( explode( '|', $filters_string) as $filter ) |
|
| 320 | + foreach (explode('|', $filters_string) as $filter) |
|
| 321 | 321 | { |
| 322 | - $args = array( $value ); |
|
| 322 | + $args = array($value); |
|
| 323 | 323 | |
| 324 | - if( false !== strrpos( $filters_string, "(" ) ) |
|
| 324 | + if (false !== strrpos($filters_string, "(")) |
|
| 325 | 325 | { |
| 326 | - $pieces = explode( '(', $filter ); |
|
| 326 | + $pieces = explode('(', $filter); |
|
| 327 | 327 | $filter = $pieces[0]; |
| 328 | - $params = explode( ',', str_replace( ')', '', $pieces[1] ) ); |
|
| 329 | - array_walk( $params, array( $this, 'strtoval' ) ); // Convert string values to actual values |
|
| 330 | - $args = array_merge( $args, $params ); |
|
| 328 | + $params = explode(',', str_replace(')', '', $pieces[1])); |
|
| 329 | + array_walk($params, array($this, 'strtoval')); // Convert string values to actual values |
|
| 330 | + $args = array_merge($args, $params); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - if( key_exists( $filter, $filters ) ) |
|
| 333 | + if (key_exists($filter, $filters)) |
|
| 334 | 334 | { |
| 335 | - $value = call_user_func_array( $filters[$filter], $args ); |
|
| 335 | + $value = call_user_func_array($filters[$filter], $args); |
|
| 336 | 336 | } |
| 337 | 337 | } |
| 338 | 338 | return $value; |
@@ -343,11 +343,11 @@ discard block |
||
| 343 | 343 | * |
| 344 | 344 | * @param string $str The string to be converted (passed by reference) |
| 345 | 345 | */ |
| 346 | - protected function strtoval( &$str ) |
|
| 346 | + protected function strtoval(&$str) |
|
| 347 | 347 | { |
| 348 | - if( 'false' === strtolower($str) ) $str = false; |
|
| 349 | - if( 'true' === strtolower($str) ) $str = true; |
|
| 350 | - if( false !== strrpos( $str, "'" ) ) $str = str_replace ( "'", "", $str ); |
|
| 351 | - if( is_numeric( $str ) ) $str = floatval( $str ); |
|
| 348 | + if ('false' === strtolower($str)) $str = false; |
|
| 349 | + if ('true' === strtolower($str)) $str = true; |
|
| 350 | + if (false !== strrpos($str, "'")) $str = str_replace("'", "", $str); |
|
| 351 | + if (is_numeric($str)) $str = floatval($str); |
|
| 352 | 352 | } |
| 353 | 353 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * @copyright 2016 Askupa Software |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -if( !function_exists('wp_dynamic_css_enqueue') ) |
|
| 10 | +if (!function_exists('wp_dynamic_css_enqueue')) |
|
| 11 | 11 | { |
| 12 | 12 | /** |
| 13 | 13 | * Enqueue a dynamic stylesheet |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | * @param boolean $cache Whether to store the compiled version of this |
| 25 | 25 | * stylesheet in cache to avoid compilation on every page load. |
| 26 | 26 | */ |
| 27 | - function wp_dynamic_css_enqueue( $handle, $path, $print = true, $minify = false, $cache = false ) |
|
| 27 | + function wp_dynamic_css_enqueue($handle, $path, $print = true, $minify = false, $cache = false) |
|
| 28 | 28 | { |
| 29 | 29 | $dcss = DynamicCSSCompiler::get_instance(); |
| 30 | - $dcss->register_style( $handle, $path, $print, $minify, $cache ); |
|
| 30 | + $dcss->register_style($handle, $path, $print, $minify, $cache); |
|
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | -if( !function_exists('wp_dynamic_css_set_callback') ) |
|
| 34 | +if (!function_exists('wp_dynamic_css_set_callback')) |
|
| 35 | 35 | { |
| 36 | 36 | /** |
| 37 | 37 | * Set the value retrieval callback function |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | * can either be a reference to a function name or method within an |
| 47 | 47 | * class/object. |
| 48 | 48 | */ |
| 49 | - function wp_dynamic_css_set_callback( $handle, $callback ) |
|
| 49 | + function wp_dynamic_css_set_callback($handle, $callback) |
|
| 50 | 50 | { |
| 51 | 51 | $dcss = DynamicCSSCompiler::get_instance(); |
| 52 | - $dcss->register_callback( $handle, $callback ); |
|
| 52 | + $dcss->register_callback($handle, $callback); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | -if( !function_exists('wp_dynamic_css_clear_cache') ) |
|
| 56 | +if (!function_exists('wp_dynamic_css_clear_cache')) |
|
| 57 | 57 | { |
| 58 | 58 | /** |
| 59 | 59 | * Clear the cached compiled CSS for the given handle. |
@@ -65,14 +65,14 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @param string $handle The name of the stylesheet to be cleared from cache |
| 67 | 67 | */ |
| 68 | - function wp_dynamic_css_clear_cache( $handle ) |
|
| 68 | + function wp_dynamic_css_clear_cache($handle) |
|
| 69 | 69 | { |
| 70 | 70 | $cache = DynamicCSSCache::get_instance(); |
| 71 | - $cache->clear( $handle ); |
|
| 71 | + $cache->clear($handle); |
|
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | -if( !function_exists('wp_dynamic_css_register_filter') ) |
|
| 75 | +if (!function_exists('wp_dynamic_css_register_filter')) |
|
| 76 | 76 | { |
| 77 | 77 | /** |
| 78 | 78 | * Register a filter function for a given stylesheet handle. |
@@ -109,9 +109,9 @@ discard block |
||
| 109 | 109 | * @param Callable $callback The actual filter function. Accepts the $value |
| 110 | 110 | * as an argument. Should return the filtered value. |
| 111 | 111 | */ |
| 112 | - function wp_dynamic_css_register_filter( $handle, $filter_name, $callback ) |
|
| 112 | + function wp_dynamic_css_register_filter($handle, $filter_name, $callback) |
|
| 113 | 113 | { |
| 114 | 114 | $dcss = DynamicCSSCompiler::get_instance(); |
| 115 | - $dcss->register_filter( $handle, $filter_name, $callback ); |
|
| 115 | + $dcss->register_filter($handle, $filter_name, $callback); |
|
| 116 | 116 | } |
| 117 | 117 | } |