Skip to content

Commit 916bc63

Browse files
author
Askupa Software
committed
Set cache control header to no-cache so that changes to user data are reflected immediately
1 parent 6397c20 commit 916bc63

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

compiler.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,12 @@ public function wp_enqueue_style()
7272
*/
7373
public function compile_printed_styles()
7474
{
75-
$compiled_css = '';
7675
$styles = array_filter($this->stylesheets, array( $this, 'filter_print' ) );
7776

7877
// Bail if there are no styles to be printed
7978
if( count( $styles ) === 0 ) return;
8079

81-
foreach( $styles as $style )
82-
{
83-
$css = file_get_contents( $style['path'] );
84-
$compiled_css .= $this->compile_css( $css, $this->callbacks[$style['handle']] )."\n";
85-
}
80+
$compiled_css = $this->compile_styles( $styles );
8681

8782
echo "<style id=\"wp-dynamic-css\">\n";
8883
include 'style.phtml';
@@ -96,14 +91,9 @@ public function compile_printed_styles()
9691
public function compile_external_styles()
9792
{
9893
header( "Content-type: text/css; charset: UTF-8" );
99-
$compiled_css = '';
100-
$styles = array_filter($this->stylesheets, array( $this, 'filter_external' ) );
94+
header( "Cache-Control: no-cache, must-revalidate" ); //set headers to NOT cache a page so that changes to options are reflected immediately
10195

102-
foreach( $styles as $style )
103-
{
104-
$css = file_get_contents( $style['path'] );
105-
$compiled_css .= $this->compile_css( $css, $this->callbacks[$style['handle']] )."\n";
106-
}
96+
$compiled_css = $this->compile_styles( array_filter($this->stylesheets, array( $this, 'filter_external' ) ) );
10797

10898
include 'style.phtml';
10999
wp_die();
@@ -137,6 +127,24 @@ public function register_callback( $handle, $callback )
137127
$this->callbacks[$handle] = $callback;
138128
}
139129

130+
/**
131+
* Compile multiple dynamic stylesheets
132+
*
133+
* @param array $styles List of styles with the same structure as they are
134+
* stored in $this->stylesheets
135+
* @return string Compiled CSS
136+
*/
137+
protected function compile_styles( $styles )
138+
{
139+
$compiled_css = '';
140+
foreach( $styles as $style )
141+
{
142+
$css = file_get_contents( $style['path'] );
143+
$compiled_css .= $this->compile_css( $css, $this->callbacks[$style['handle']] )."\n";
144+
}
145+
return $compiled_css;
146+
}
147+
140148
/**
141149
* This filter is used to return only the styles that are set to be printed
142150
* in the document head

0 commit comments

Comments
 (0)