@@ -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 |
@@ -22,14 +22,14 @@ discard block |
||
| 22 | 22 | * head, or include it as an external CSS file |
| 23 | 23 | * @param boolean $minify Whether to minify the CSS output |
| 24 | 24 | */ |
| 25 | - function wp_dynamic_css_enqueue( $handle, $path, $print = true, $minify = false ) |
|
| 25 | + function wp_dynamic_css_enqueue($handle, $path, $print = true, $minify = false) |
|
| 26 | 26 | { |
| 27 | 27 | $dcss = DynamicCSSCompiler::get_instance(); |
| 28 | - $dcss->enqueue_style( $handle, $path, $print, $minify ); |
|
| 28 | + $dcss->enqueue_style($handle, $path, $print, $minify); |
|
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | -if( !function_exists('wp_dynamic_css_set_callback') ) |
|
| 32 | +if (!function_exists('wp_dynamic_css_set_callback')) |
|
| 33 | 33 | { |
| 34 | 34 | /** |
| 35 | 35 | * Set the value retrieval callback function |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | * can either be a reference to a function name or method within an |
| 45 | 45 | * class/object. |
| 46 | 46 | */ |
| 47 | - function wp_dynamic_css_set_callback( $handle, $callback ) |
|
| 47 | + function wp_dynamic_css_set_callback($handle, $callback) |
|
| 48 | 48 | { |
| 49 | 49 | $dcss = DynamicCSSCompiler::get_instance(); |
| 50 | - $dcss->register_callback( $handle, $callback ); |
|
| 50 | + $dcss->register_callback($handle, $callback); |
|
| 51 | 51 | } |
| 52 | 52 | } |
@@ -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 | |
@@ -72,12 +72,12 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function compile_printed_styles() |
| 74 | 74 | { |
| 75 | - $styles = array_filter($this->stylesheets, array( $this, 'filter_print' ) ); |
|
| 75 | + $styles = array_filter($this->stylesheets, array($this, 'filter_print')); |
|
| 76 | 76 | |
| 77 | 77 | // Bail if there are no styles to be printed |
| 78 | - if( count( $styles ) === 0 ) return; |
|
| 78 | + if (count($styles) === 0) return; |
|
| 79 | 79 | |
| 80 | - $compiled_css = $this->compile_styles( $styles ); |
|
| 80 | + $compiled_css = $this->compile_styles($styles); |
|
| 81 | 81 | |
| 82 | 82 | echo "<style id=\"wp-dynamic-css\">\n"; |
| 83 | 83 | include 'style.phtml'; |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function compile_external_styles() |
| 92 | 92 | { |
| 93 | - header( "Content-type: text/css; charset: UTF-8" ); |
|
| 94 | - header( "Cache-Control: no-cache, must-revalidate" ); //set headers to NOT cache so that changes to options are reflected immediately |
|
| 93 | + header("Content-type: text/css; charset: UTF-8"); |
|
| 94 | + header("Cache-Control: no-cache, must-revalidate"); //set headers to NOT cache so that changes to options are reflected immediately |
|
| 95 | 95 | |
| 96 | - $compiled_css = $this->compile_styles( array_filter($this->stylesheets, array( $this, 'filter_external' ) ) ); |
|
| 96 | + $compiled_css = $this->compile_styles(array_filter($this->stylesheets, array($this, 'filter_external'))); |
|
| 97 | 97 | |
| 98 | 98 | include 'style.phtml'; |
| 99 | 99 | wp_die(); |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * head, or include it as an external CSS file |
| 109 | 109 | * @param boolean $minify Whether to minify the CSS output |
| 110 | 110 | */ |
| 111 | - public function enqueue_style( $handle, $path, $print, $minify ) |
|
| 111 | + public function enqueue_style($handle, $path, $print, $minify) |
|
| 112 | 112 | { |
| 113 | 113 | $this->stylesheets[] = array( |
| 114 | 114 | 'handle'=> $handle, |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @param type $handle The stylesheet's name/id |
| 125 | 125 | * @param type $callback |
| 126 | 126 | */ |
| 127 | - public function register_callback( $handle, $callback ) |
|
| 127 | + public function register_callback($handle, $callback) |
|
| 128 | 128 | { |
| 129 | 129 | $this->callbacks[$handle] = $callback; |
| 130 | 130 | } |
@@ -136,14 +136,14 @@ discard block |
||
| 136 | 136 | * stored in $this->stylesheets |
| 137 | 137 | * @return string Compiled CSS |
| 138 | 138 | */ |
| 139 | - protected function compile_styles( $styles ) |
|
| 139 | + protected function compile_styles($styles) |
|
| 140 | 140 | { |
| 141 | 141 | $compiled_css = ''; |
| 142 | - foreach( $styles as $style ) |
|
| 142 | + foreach ($styles as $style) |
|
| 143 | 143 | { |
| 144 | - $css = file_get_contents( $style['path'] ); |
|
| 145 | - if( $style['minify'] ) $css = $this->minify_css ( $css ); |
|
| 146 | - $compiled_css .= $this->compile_css( $css, $this->callbacks[$style['handle']] )."\n"; |
|
| 144 | + $css = file_get_contents($style['path']); |
|
| 145 | + if ($style['minify']) $css = $this->minify_css($css); |
|
| 146 | + $compiled_css .= $this->compile_css($css, $this->callbacks[$style['handle']])."\n"; |
|
| 147 | 147 | } |
| 148 | 148 | return $compiled_css; |
| 149 | 149 | } |
@@ -155,9 +155,9 @@ discard block |
||
| 155 | 155 | * @param string $css CSS style to minify |
| 156 | 156 | * @return string Minified CSS |
| 157 | 157 | */ |
| 158 | - protected function minify_css( $css ) |
|
| 158 | + protected function minify_css($css) |
|
| 159 | 159 | { |
| 160 | - return preg_replace( '@({)\s+|(\;)\s+|/\*.+?\*\/|\R@is', '$1$2 ', $css ); |
|
| 160 | + return preg_replace('@({)\s+|(\;)\s+|/\*.+?\*\/|\R@is', '$1$2 ', $css); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @param array $style |
| 168 | 168 | * @return boolean |
| 169 | 169 | */ |
| 170 | - protected function filter_print( $style ) |
|
| 170 | + protected function filter_print($style) |
|
| 171 | 171 | { |
| 172 | 172 | return true === $style['print']; |
| 173 | 173 | } |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * @param array $style |
| 180 | 180 | * @return boolean |
| 181 | 181 | */ |
| 182 | - protected function filter_external( $style ) |
|
| 182 | + protected function filter_external($style) |
|
| 183 | 183 | { |
| 184 | 184 | return true !== $style['print']; |
| 185 | 185 | } |
@@ -195,15 +195,15 @@ discard block |
||
| 195 | 195 | * @return string The compiled CSS after converting the variables to their |
| 196 | 196 | * corresponding values |
| 197 | 197 | */ |
| 198 | - protected function compile_css( $css, $callback ) |
|
| 198 | + protected function compile_css($css, $callback) |
|
| 199 | 199 | { |
| 200 | - return preg_replace_callback( "#\\$([\\w-]+)((?:\\['?[\\w-]+'?\\])*)#", function( $matches ) use ( $callback ) { |
|
| 200 | + return preg_replace_callback("#\\$([\\w-]+)((?:\\['?[\\w-]+'?\\])*)#", function($matches) use ($callback) { |
|
| 201 | 201 | // If this variable is an array, get the subscripts |
| 202 | - if( '' !== $matches[2] ) |
|
| 202 | + if ('' !== $matches[2]) |
|
| 203 | 203 | { |
| 204 | 204 | preg_match_all('/[\w-]+/i', $matches[2], $subscripts); |
| 205 | 205 | } |
| 206 | - return call_user_func_array( $callback, array($matches[1],@$subscripts[0]) ); |
|
| 206 | + return call_user_func_array($callback, array($matches[1], @$subscripts[0])); |
|
| 207 | 207 | }, $css); |
| 208 | 208 | } |
| 209 | 209 | } |
@@ -75,7 +75,9 @@ discard block |
||
| 75 | 75 | $styles = array_filter($this->stylesheets, array( $this, 'filter_print' ) ); |
| 76 | 76 | |
| 77 | 77 | // Bail if there are no styles to be printed |
| 78 | - if( count( $styles ) === 0 ) return; |
|
| 78 | + if( count( $styles ) === 0 ) { |
|
| 79 | + return; |
|
| 80 | + } |
|
| 79 | 81 | |
| 80 | 82 | $compiled_css = $this->compile_styles( $styles ); |
| 81 | 83 | |
@@ -142,7 +144,9 @@ discard block |
||
| 142 | 144 | foreach( $styles as $style ) |
| 143 | 145 | { |
| 144 | 146 | $css = file_get_contents( $style['path'] ); |
| 145 | - if( $style['minify'] ) $css = $this->minify_css ( $css ); |
|
| 147 | + if( $style['minify'] ) { |
|
| 148 | + $css = $this->minify_css ( $css ); |
|
| 149 | + } |
|
| 146 | 150 | $compiled_css .= $this->compile_css( $css, $this->callbacks[$style['handle']] )."\n"; |
| 147 | 151 | } |
| 148 | 152 | return $compiled_css; |