| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @package   WordPress Dynamic CSS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @version   1.0.5 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @author    Askupa Software <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @link      https://github.com/askupasoftware/wp-dynamic-css | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @copyright 2016 Askupa Software | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | if( !function_exists('wp_dynamic_css_enqueue') ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * Enqueue a dynamic stylesheet | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * This will either print the compiled version of the stylesheet to the  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * document's <head> section, or load it as an external stylesheet if $print  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * is set to false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * @param string $handle The stylesheet's name/id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @param string $path The absolute path to the dynamic CSS file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @paran boolean $print Whether to print the compiled CSS to the document  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * head, or include it as an external CSS file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @param boolean $minify Whether to minify the CSS output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @param boolean $cache Whether to store the compiled version of this  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * stylesheet in cache to avoid compilation on every page load. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     function wp_dynamic_css_enqueue( $handle, $path, $print = true, $minify = false, $cache = false ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $dcss = DynamicCSSCompiler::get_instance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $dcss->enqueue_style( $handle, $path, $print, $minify, $cache ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | if( !function_exists('wp_dynamic_css_set_callback') ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * Set the value retrieval callback function | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * Set a callback function that will be used to get the values of the  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * variables when the dynamic CSS file is compiled. The function accepts 1  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * parameter which is the name of the variable, without the $ sign | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @param string $handle The name of the stylesheet to be associated with this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * callback function | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @param string|array $callback A callback (or "callable" as of PHP 5.4)  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * can either be a reference to a function name or method within an  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * class/object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     function wp_dynamic_css_set_callback( $handle, $callback ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $dcss = DynamicCSSCompiler::get_instance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $dcss->register_callback( $handle, $callback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | if( !function_exists('wp_dynamic_css_clear_cache') ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * Clear the cached compiled CSS for the given handle. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * Initially, registered dynamic stylesheets are compiled and stored in cache. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * Subsequesnt requests are served statically from cache until  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * wp_dynamic_css_clear_cache() is called and clears it, forcing the compiler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * to recompile the CSS. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @param string $handle The name of the stylesheet to be cleared from cache | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 67 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |     function wp_dynamic_css_clear_cache( $handle ) | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |         $cache = DynamicCSSCache::get_instance(); | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |         $cache->clear( $handle ); | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 73 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |  |