@@ -71,7 +71,9 @@ |
||
| 71 | 71 | $styles = array_filter($this->stylesheets, array( $this, 'filter_print' ) ); |
| 72 | 72 | |
| 73 | 73 | // Bail if there are no styles to be printed |
| 74 | - if( count( $styles ) === 0 ) return; |
|
| 74 | + if( count( $styles ) === 0 ) { |
|
| 75 | + return; |
|
| 76 | + } |
|
| 75 | 77 | |
| 76 | 78 | foreach( $styles as $style ) |
| 77 | 79 | { |
@@ -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 a page 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 a page 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(); |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @param boolean $print Whether to print the compiled CSS to the document |
| 108 | 108 | * head, or include it as an external CSS file |
| 109 | 109 | */ |
| 110 | - public function enqueue_style( $handle, $path, $print ) |
|
| 110 | + public function enqueue_style($handle, $path, $print) |
|
| 111 | 111 | { |
| 112 | 112 | $this->stylesheets[] = array( |
| 113 | 113 | 'handle'=> $handle, |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @param type $handle The stylesheet's name/id |
| 123 | 123 | * @param type $callback |
| 124 | 124 | */ |
| 125 | - public function register_callback( $handle, $callback ) |
|
| 125 | + public function register_callback($handle, $callback) |
|
| 126 | 126 | { |
| 127 | 127 | $this->callbacks[$handle] = $callback; |
| 128 | 128 | } |
@@ -134,13 +134,13 @@ discard block |
||
| 134 | 134 | * stored in $this->stylesheets |
| 135 | 135 | * @return string Compiled CSS |
| 136 | 136 | */ |
| 137 | - protected function compile_styles( $styles ) |
|
| 137 | + protected function compile_styles($styles) |
|
| 138 | 138 | { |
| 139 | 139 | $compiled_css = ''; |
| 140 | - foreach( $styles as $style ) |
|
| 140 | + foreach ($styles as $style) |
|
| 141 | 141 | { |
| 142 | - $css = file_get_contents( $style['path'] ); |
|
| 143 | - $compiled_css .= $this->compile_css( $css, $this->callbacks[$style['handle']] )."\n"; |
|
| 142 | + $css = file_get_contents($style['path']); |
|
| 143 | + $compiled_css .= $this->compile_css($css, $this->callbacks[$style['handle']])."\n"; |
|
| 144 | 144 | } |
| 145 | 145 | return $compiled_css; |
| 146 | 146 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * @param array $style |
| 153 | 153 | * @return boolean |
| 154 | 154 | */ |
| 155 | - protected function filter_print( $style ) |
|
| 155 | + protected function filter_print($style) |
|
| 156 | 156 | { |
| 157 | 157 | return true === $style['print']; |
| 158 | 158 | } |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * @param array $style |
| 165 | 165 | * @return boolean |
| 166 | 166 | */ |
| 167 | - protected function filter_external( $style ) |
|
| 167 | + protected function filter_external($style) |
|
| 168 | 168 | { |
| 169 | 169 | return true !== $style['print']; |
| 170 | 170 | } |
@@ -180,15 +180,15 @@ discard block |
||
| 180 | 180 | * @return string The compiled CSS after converting the variables to their |
| 181 | 181 | * corresponding values |
| 182 | 182 | */ |
| 183 | - protected function compile_css( $css, $callback ) |
|
| 183 | + protected function compile_css($css, $callback) |
|
| 184 | 184 | { |
| 185 | - return preg_replace_callback( "#\\$([\\w-]+)((?:\\['?[\\w-]+'?\\])*)#", function( $matches ) use ( $callback ) { |
|
| 185 | + return preg_replace_callback("#\\$([\\w-]+)((?:\\['?[\\w-]+'?\\])*)#", function($matches) use ($callback) { |
|
| 186 | 186 | // If this variable is an array, get the subscripts |
| 187 | - if( '' !== $matches[2] ) |
|
| 187 | + if ('' !== $matches[2]) |
|
| 188 | 188 | { |
| 189 | 189 | preg_match_all('/[\w-]+/i', $matches[2], $subscripts); |
| 190 | 190 | } |
| 191 | - return call_user_func_array( $callback, array($matches[1],@$subscripts[0]) ); |
|
| 191 | + return call_user_func_array($callback, array($matches[1], @$subscripts[0])); |
|
| 192 | 192 | }, $css); |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -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 |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * stylesheets externally. |
| 41 | 41 | */ |
| 42 | 42 | $dcss = DynamicCSSCompiler::get_instance(); |
| 43 | -add_action( 'wp_print_styles', array( $dcss, 'compile_printed_styles' ) ); |
|
| 44 | -add_action( 'wp_enqueue_scripts', array( $dcss, 'wp_enqueue_style' ) ); |
|
| 45 | -add_action( 'wp_ajax_wp_dynamic_css', array( $dcss, 'compile_external_styles' ) ); |
|
| 46 | -add_action( 'wp_ajax_nopriv_wp_dynamic_css', array( $dcss, 'compile_external_styles' ) ); |
|
| 47 | 43 | \ No newline at end of file |
| 44 | +add_action('wp_print_styles', array($dcss, 'compile_printed_styles')); |
|
| 45 | +add_action('wp_enqueue_scripts', array($dcss, 'wp_enqueue_style')); |
|
| 46 | +add_action('wp_ajax_wp_dynamic_css', array($dcss, 'compile_external_styles')); |
|
| 47 | +add_action('wp_ajax_nopriv_wp_dynamic_css', array($dcss, 'compile_external_styles')); |
|
| 48 | 48 | \ No newline at end of file |
@@ -26,7 +26,9 @@ |
||
| 26 | 26 | /** |
| 27 | 27 | * Prevent loading the library more than once |
| 28 | 28 | */ |
| 29 | -if( defined( 'WP_DYNAMIC_CSS' ) ) return; |
|
| 29 | +if( defined( 'WP_DYNAMIC_CSS' ) ) { |
|
| 30 | + return; |
|
| 31 | +} |
|
| 30 | 32 | define( 'WP_DYNAMIC_CSS', true ); |
| 31 | 33 | |
| 32 | 34 | /** |
@@ -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 |
@@ -21,14 +21,14 @@ discard block |
||
| 21 | 21 | * @paran boolean $print Whether to print the compiled CSS to the document |
| 22 | 22 | * head, or include it as an external CSS file |
| 23 | 23 | */ |
| 24 | - function wp_dynamic_css_enqueue( $handle, $path, $print = true ) |
|
| 24 | + function wp_dynamic_css_enqueue($handle, $path, $print = true) |
|
| 25 | 25 | { |
| 26 | 26 | $dcss = DynamicCSSCompiler::get_instance(); |
| 27 | - $dcss->enqueue_style( $handle, $path, $print ); |
|
| 27 | + $dcss->enqueue_style($handle, $path, $print); |
|
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | -if( !function_exists('wp_dynamic_css_set_callback') ) |
|
| 31 | +if (!function_exists('wp_dynamic_css_set_callback')) |
|
| 32 | 32 | { |
| 33 | 33 | /** |
| 34 | 34 | * Set the value retrieval callback function |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | * can either be a reference to a function name or method within an |
| 44 | 44 | * class/object. |
| 45 | 45 | */ |
| 46 | - function wp_dynamic_css_set_callback( $handle, $callback ) |
|
| 46 | + function wp_dynamic_css_set_callback($handle, $callback) |
|
| 47 | 47 | { |
| 48 | 48 | $dcss = DynamicCSSCompiler::get_instance(); |
| 49 | - $dcss->register_callback( $handle, $callback ); |
|
| 49 | + $dcss->register_callback($handle, $callback); |
|
| 50 | 50 | } |
| 51 | 51 | } |