@@ -23,6 +23,9 @@ function stackable_get_responsive_css() {
2323if ( ! class_exists ( 'Stackable_Dynamic_Breakpoints ' ) ) {
2424 class Stackable_Dynamic_Breakpoints {
2525
26+ // Holds the value of the saved or default breakpoints
27+ private $ dynamic_breakpoints = false ;
28+
2629 /**
2730 * Add our hooks.
2831 */
@@ -35,17 +38,15 @@ function __construct() {
3538 // Add a filter for replacing shortcut media queries before the breakpoint adjustment.
3639 add_filter ( 'stackable_frontend_css ' , array ( $ this , 'replace_shortcut_media_queries ' ), 9 );
3740
38- if ( $ this ->has_custom_breakpoints () ) {
39- // Add our filter that adjusts all CSS that we print out.
40- add_filter ( 'stackable_frontend_css ' , array ( $ this , 'adjust_breakpoints ' ) );
41+ // Add our filter that adjusts all CSS that we print out.
42+ add_filter ( 'stackable_frontend_css ' , array ( $ this , 'adjust_breakpoints ' ) );
4143
42- // If there are adjusted breakpoints, enqueue our adjusted responsive css.
43- add_action ( 'stackable_block_enqueue_frontend_assets ' , array ( $ this , 'enqueue_adjusted_responsive_css ' ) );
44+ // If there are adjusted breakpoints, enqueue our adjusted responsive css.
45+ add_action ( 'stackable_block_enqueue_frontend_assets ' , array ( $ this , 'enqueue_adjusted_responsive_css ' ) );
4446
45- // Adjust the styles outputted by Stackable blocks.
46- // 11 Priority, do this last because changing style can affect inline css optimization.
47- add_filter ( 'render_block ' , array ( $ this , 'adjust_block_styles ' ), 11 , 2 );
48- }
47+ // Adjust the styles outputted by Stackable blocks.
48+ // 11 Priority, do this last because changing style can affect inline css optimization.
49+ add_filter ( 'render_block ' , array ( $ this , 'adjust_block_styles ' ), 11 , 2 );
4950 }
5051 }
5152
@@ -73,7 +74,8 @@ public function get_dynamic_breakpoints() {
7374 }
7475 }
7576
76- return $ breakpoints ;
77+ $ this ->dynamic_breakpoints = $ breakpoints ;
78+ return $ this ->dynamic_breakpoints ;
7779 }
7880
7981 /**
@@ -121,7 +123,10 @@ public function sanitize_array_setting( $input ) {
121123 * @return boolean
122124 */
123125 public function has_custom_breakpoints () {
124- $ breakpoints = $ this ->get_dynamic_breakpoints ();
126+ $ breakpoints = $ this ->dynamic_breakpoints ;
127+ if ( $ breakpoints == false ) {
128+ $ breakpoints = $ this ->get_dynamic_breakpoints ();
129+ }
125130 return ! empty ( $ breakpoints ['tablet ' ] ) || ! empty ( $ breakpoints ['mobile ' ] );
126131 }
127132
@@ -145,7 +150,11 @@ public function replace_shortcut_media_queries( $css ) {
145150 * @return String adjusted CSS
146151 */
147152 public function adjust_breakpoints ( $ css ) {
148- $ breakpoints = $ this ->get_dynamic_breakpoints ();
153+ if ( ! $ this ->has_custom_breakpoints () ) {
154+ return $ css ;
155+ }
156+
157+ $ breakpoints = $ this ->dynamic_breakpoints ;
149158 $ new_tablet = $ breakpoints ['tablet ' ];
150159 $ new_mobile = $ breakpoints ['mobile ' ];
151160
@@ -194,6 +203,10 @@ public function adjust_breakpoints( $css ) {
194203 * @return void
195204 */
196205 public function enqueue_adjusted_responsive_css () {
206+ if ( ! $ this ->has_custom_breakpoints () ) {
207+ return ;
208+ }
209+
197210 $ css = stackable_get_responsive_css ();
198211 $ css = apply_filters ( 'stackable_frontend_css ' , $ css );
199212 wp_add_inline_style ( 'ugb-style-css ' , $ css );
@@ -209,6 +222,10 @@ public function enqueue_adjusted_responsive_css() {
209222 * @return void
210223 */
211224 public function adjust_block_styles ( $ block_content , $ block ) {
225+ if ( ! $ this ->has_custom_breakpoints () ) {
226+ return $ block_content ;
227+ }
228+
212229 if ( $ block_content === null ) {
213230 return $ block_content ;
214231 }
0 commit comments