@@ -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->enqueue_style( $handle, $path, $print, $minify, $cache ); |
|
| 30 | + $dcss->enqueue_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,9 +65,9 @@ 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 | } |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | { |
| 61 | 61 | // Only enqueue if there is at least one dynamic stylesheet that is |
| 62 | 62 | // set to be loaded externally |
| 63 | - if( 0 < count( array_filter($this->stylesheets, array( $this, 'filter_external' ) ) ) ) |
|
| 63 | + if (0 < count(array_filter($this->stylesheets, array($this, 'filter_external')))) |
|
| 64 | 64 | { |
| 65 | - wp_enqueue_style( 'wp-dynamic-css', admin_url( 'admin-ajax.php?action=wp_dynamic_css' ) ); |
|
| 65 | + wp_enqueue_style('wp-dynamic-css', admin_url('admin-ajax.php?action=wp_dynamic_css')); |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | public function compile_printed_styles() |
| 74 | 74 | { |
| 75 | 75 | // Compile only if there are styles to be printed |
| 76 | - if( 0 < count( array_filter($this->stylesheets, array( $this, 'filter_print' ) ) ) ) |
|
| 76 | + if (0 < count(array_filter($this->stylesheets, array($this, 'filter_print')))) |
|
| 77 | 77 | { |
| 78 | - $compiled_css = $this->get_compiled_styles( true ); |
|
| 78 | + $compiled_css = $this->get_compiled_styles(true); |
|
| 79 | 79 | |
| 80 | 80 | echo "<style id=\"wp-dynamic-css\">\n"; |
| 81 | 81 | include 'style.phtml'; |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | public function compile_external_styles() |
| 91 | 91 | { |
| 92 | - header( "Content-type: text/css; charset: UTF-8" ); |
|
| 92 | + header("Content-type: text/css; charset: UTF-8"); |
|
| 93 | 93 | |
| 94 | - $compiled_css = $this->get_compiled_styles( false ); |
|
| 94 | + $compiled_css = $this->get_compiled_styles(false); |
|
| 95 | 95 | |
| 96 | 96 | include 'style.phtml'; |
| 97 | 97 | wp_die(); |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * @param boolean $cache Whether to store the compiled version of this |
| 109 | 109 | * stylesheet in cache to avoid compilation on every page load. |
| 110 | 110 | */ |
| 111 | - public function enqueue_style( $handle, $path, $print, $minify, $cache ) |
|
| 111 | + public function enqueue_style($handle, $path, $print, $minify, $cache) |
|
| 112 | 112 | { |
| 113 | 113 | $this->stylesheets[] = array( |
| 114 | 114 | 'handle'=> $handle, |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @param type $handle The stylesheet's name/id |
| 126 | 126 | * @param type $callback |
| 127 | 127 | */ |
| 128 | - public function register_callback( $handle, $callback ) |
|
| 128 | + public function register_callback($handle, $callback) |
|
| 129 | 129 | { |
| 130 | 130 | $this->callbacks[$handle] = $callback; |
| 131 | 131 | } |
@@ -136,14 +136,14 @@ discard block |
||
| 136 | 136 | * @param boolean $printed |
| 137 | 137 | * @return string Compiled CSS |
| 138 | 138 | */ |
| 139 | - protected function get_compiled_styles( $printed ) |
|
| 139 | + protected function get_compiled_styles($printed) |
|
| 140 | 140 | { |
| 141 | 141 | $compiled_css = ''; |
| 142 | - foreach( $this->stylesheets as $style ) |
|
| 142 | + foreach ($this->stylesheets as $style) |
|
| 143 | 143 | { |
| 144 | - if( $style['print'] === $printed ) |
|
| 144 | + if ($style['print'] === $printed) |
|
| 145 | 145 | { |
| 146 | - $compiled_css .= $this->get_compiled_style( $style )."\n"; |
|
| 146 | + $compiled_css .= $this->get_compiled_style($style)."\n"; |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | return $compiled_css; |
@@ -157,23 +157,23 @@ discard block |
||
| 157 | 157 | * stored in $this->stylesheets |
| 158 | 158 | * @return type |
| 159 | 159 | */ |
| 160 | - protected function get_compiled_style( $style ) |
|
| 160 | + protected function get_compiled_style($style) |
|
| 161 | 161 | { |
| 162 | 162 | $cache = DynamicCSSCache::get_instance(); |
| 163 | 163 | |
| 164 | - if( $style['cache'] ) |
|
| 164 | + if ($style['cache']) |
|
| 165 | 165 | { |
| 166 | - $cached_css = $cache->get( $style['handle'] ); |
|
| 167 | - if( false !== $cached_css ) |
|
| 166 | + $cached_css = $cache->get($style['handle']); |
|
| 167 | + if (false !== $cached_css) |
|
| 168 | 168 | { |
| 169 | 169 | return $cached_css; |
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - $css = file_get_contents( $style['path'] ); |
|
| 174 | - if( $style['minify'] ) $css = $this->minify_css( $css ); |
|
| 175 | - $compiled_css = $this->compile_css( $css, $this->callbacks[$style['handle']] ); |
|
| 176 | - $cache->update( $style['handle'], $compiled_css ); |
|
| 173 | + $css = file_get_contents($style['path']); |
|
| 174 | + if ($style['minify']) $css = $this->minify_css($css); |
|
| 175 | + $compiled_css = $this->compile_css($css, $this->callbacks[$style['handle']]); |
|
| 176 | + $cache->update($style['handle'], $compiled_css); |
|
| 177 | 177 | return $compiled_css; |
| 178 | 178 | } |
| 179 | 179 | |
@@ -184,9 +184,9 @@ discard block |
||
| 184 | 184 | * @param string $css CSS style to minify |
| 185 | 185 | * @return string Minified CSS |
| 186 | 186 | */ |
| 187 | - protected function minify_css( $css ) |
|
| 187 | + protected function minify_css($css) |
|
| 188 | 188 | { |
| 189 | - return preg_replace( '@({)\s+|(\;)\s+|/\*.+?\*\/|\R@is', '$1$2 ', $css ); |
|
| 189 | + return preg_replace('@({)\s+|(\;)\s+|/\*.+?\*\/|\R@is', '$1$2 ', $css); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * @param array $style |
| 197 | 197 | * @return boolean |
| 198 | 198 | */ |
| 199 | - protected function filter_print( $style ) |
|
| 199 | + protected function filter_print($style) |
|
| 200 | 200 | { |
| 201 | 201 | return true === $style['print']; |
| 202 | 202 | } |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @param array $style |
| 209 | 209 | * @return boolean |
| 210 | 210 | */ |
| 211 | - protected function filter_external( $style ) |
|
| 211 | + protected function filter_external($style) |
|
| 212 | 212 | { |
| 213 | 213 | return true !== $style['print']; |
| 214 | 214 | } |
@@ -224,15 +224,15 @@ discard block |
||
| 224 | 224 | * @return string The compiled CSS after converting the variables to their |
| 225 | 225 | * corresponding values |
| 226 | 226 | */ |
| 227 | - protected function compile_css( $css, $callback ) |
|
| 227 | + protected function compile_css($css, $callback) |
|
| 228 | 228 | { |
| 229 | - return preg_replace_callback( "#\\$([\\w-]+)((?:\\['?[\\w-]+'?\\])*)#", function( $matches ) use ( $callback ) { |
|
| 229 | + return preg_replace_callback("#\\$([\\w-]+)((?:\\['?[\\w-]+'?\\])*)#", function($matches) use ($callback) { |
|
| 230 | 230 | // If this variable is an array, get the subscripts |
| 231 | - if( '' !== $matches[2] ) |
|
| 231 | + if ('' !== $matches[2]) |
|
| 232 | 232 | { |
| 233 | 233 | preg_match_all('/[\w-]+/i', $matches[2], $subscripts); |
| 234 | 234 | } |
| 235 | - return call_user_func_array( $callback, array($matches[1],@$subscripts[0]) ); |
|
| 235 | + return call_user_func_array($callback, array($matches[1], @$subscripts[0])); |
|
| 236 | 236 | }, $css); |
| 237 | 237 | } |
| 238 | 238 | } |
@@ -171,7 +171,9 @@ |
||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | $css = file_get_contents( $style['path'] ); |
| 174 | - if( $style['minify'] ) $css = $this->minify_css( $css ); |
|
| 174 | + if( $style['minify'] ) { |
|
| 175 | + $css = $this->minify_css( $css ); |
|
| 176 | + } |
|
| 175 | 177 | $compiled_css = $this->compile_css( $css, $this->callbacks[$style['handle']] ); |
| 176 | 178 | $cache->update( $style['handle'], $compiled_css ); |
| 177 | 179 | return $compiled_css; |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | * @param string $handle The handle of the stylesheet |
| 45 | 45 | * @return boolean|string |
| 46 | 46 | */ |
| 47 | - public function get( $handle ) |
|
| 47 | + public function get($handle) |
|
| 48 | 48 | { |
| 49 | - if( array_key_exists( $handle, self::$cache ) ) |
|
| 49 | + if (array_key_exists($handle, self::$cache)) |
|
| 50 | 50 | { |
| 51 | 51 | return self::$cache[$handle]; |
| 52 | 52 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @param string $handle The handle of the stylesheet |
| 60 | 60 | * @param type $compiled_css |
| 61 | 61 | */ |
| 62 | - public function update( $handle, $compiled_css ) |
|
| 62 | + public function update($handle, $compiled_css) |
|
| 63 | 63 | { |
| 64 | 64 | self::$cache[$handle] = $compiled_css; |
| 65 | 65 | $this->update_option(); |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @param string $handle The handle of the stylesheet |
| 72 | 72 | */ |
| 73 | - public function clear( $handle ) |
|
| 73 | + public function clear($handle) |
|
| 74 | 74 | { |
| 75 | 75 | unset(self::$cache[$handle]); |
| 76 | 76 | $this->update_option(); |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | { |
| 85 | 85 | self::$cache = get_option('wp-dynamic-css-cache'); |
| 86 | 86 | |
| 87 | - if( false === self::$cache ) |
|
| 87 | + if (false === self::$cache) |
|
| 88 | 88 | { |
| 89 | 89 | self::$cache = array(); |
| 90 | 90 | } |