Skip to Content
Menu

scss_post_compile()

Modifies the compiled CSS files with additional customization (such as date of render).

PHP March 16, 2017

Usage

PHP
nebula()->scss_post_compile($scss)

Parameters

$scss
(Required) (String) The compiled CSS
Default: None

Request or provide clarification »

Additional Notes

  • Reduces theme path comment lines (in both parent and child themes).
  • Adds a processed timestamp at the end of the file.

Can be hooked into with nebula_scss_post_compile to add more customization.

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Utilities/Sass.php on line 362.

    3 Hooks

    Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

    Filters
    "pre_nebula_scss_post_compile"
    Need a new filter hook? Request one here.

    Actions
    "nebula_scss_post_compile_every"
    "nebula_scss_post_compile_once"
    Need a new action hook? Request one here.

    PHP
            public function scss_post_compile($scss){
                $override = apply_filters('pre_nebula_scss_post_compile', null, $scss);
                if ( isset($override) ){return $override;}
    
                if ( empty($scss) ){
                    return $scss;
                }
    
                $scss = preg_replace("(" . str_replace('/', '\/', get_template_directory()) . ")", '', $scss); //Reduce theme path for SCSSPHP debug line comments
                $scss = preg_replace("(" . str_replace('/', '\/', get_stylesheet_directory()) . ")", '', $scss); //Reduce theme path for SCSSPHP debug line comments (For child themes)
                do_action('nebula_scss_post_compile_every');
    
                $scss .= PHP_EOL . '/* ' . date('l, F j, Y \a\t g:i:s A', time()) . ' */';
    
                //Run these once
                if ( $this->get_data('need_sass_compile') != 'false' ){
                    do_action('nebula_scss_post_compile_once');
    
                    $this->update_data('scss_last_processed', time());
                    $this->update_data('need_sass_compile', 'false');
    
                    //Update the Service Worker JavaScript file (to clear cache)
                    if ( $this->get_option('service_worker') && is_writable(get_home_path()) ){
                        if ( file_exists($this->sw_location(false)) ){
                            $this->update_sw_js();
                        }
                    }
                }
    
                return $scss;
            }
    

    Override

    To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):

    PHP
    add_filter('pre_nebula_scss_post_compile', 'my_custom_scss_post_compile', 10, 2); //The last integer must be 1 more than the actual parameters
    function my_custom_scss_post_compile($null, $scss){ //$null is required, but can be ignored
        //Write your own code here
    
        return true; //Return true to prevent the original function from running afterwords
    }

    You can completely disable this PHP function with a single line actions:

    PHP
     add_filter('pre_nebula_scss_post_compile', '__return_false');