Skip to content

Commit 55e6216

Browse files
committed
use breakpoints property, add individual checks
1 parent fa85df6 commit 55e6216

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/dynamic-breakpoints.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ function stackable_get_responsive_css() {
2323
if ( ! class_exists( 'Stackable_Dynamic_Breakpoints' ) ) {
2424
class Stackable_Dynamic_Breakpoints {
2525

26+
private $dynamic_breakpoints = false;
27+
2628
/**
2729
* Add our hooks.
2830
*/
@@ -35,14 +37,6 @@ function __construct() {
3537
// Add a filter for replacing shortcut media queries before the breakpoint adjustment.
3638
add_filter( 'stackable_frontend_css', array( $this, 'replace_shortcut_media_queries' ), 9 );
3739

38-
// This make sure all add_filter( 'stackable_responsive_breakpoints' , callback ) are called
39-
// before getting the dynamic breakpoints
40-
add_action('after_setup_theme', array( $this, 'setup_frontend_breakpoints') );
41-
}
42-
}
43-
44-
function setup_frontend_breakpoints() {
45-
if ( $this->has_custom_breakpoints() ) {
4640
// Add our filter that adjusts all CSS that we print out.
4741
add_filter( 'stackable_frontend_css', array( $this, 'adjust_breakpoints' ) );
4842

@@ -79,7 +73,8 @@ public function get_dynamic_breakpoints() {
7973
}
8074
}
8175

82-
return $breakpoints;
76+
$this->dynamic_breakpoints = $breakpoints;
77+
return $this->dynamic_breakpoints;
8378
}
8479

8580
/**
@@ -127,7 +122,10 @@ public function sanitize_array_setting( $input ) {
127122
* @return boolean
128123
*/
129124
public function has_custom_breakpoints() {
130-
$breakpoints = $this->get_dynamic_breakpoints();
125+
$breakpoints = $this->dynamic_breakpoints;
126+
if ( $breakpoints == false ) {
127+
$breakpoints = $this->get_dynamic_breakpoints();
128+
}
131129
return ! empty( $breakpoints['tablet'] ) || ! empty( $breakpoints['mobile'] );
132130
}
133131

@@ -151,7 +149,11 @@ public function replace_shortcut_media_queries( $css ) {
151149
* @return String adjusted CSS
152150
*/
153151
public function adjust_breakpoints( $css ) {
154-
$breakpoints = $this->get_dynamic_breakpoints();
152+
if ( ! $this->has_custom_breakpoints() ) {
153+
return $css;
154+
}
155+
156+
$breakpoints = $this->dynamic_breakpoints;
155157
$new_tablet = $breakpoints['tablet'];
156158
$new_mobile = $breakpoints['mobile'];
157159

@@ -200,6 +202,10 @@ public function adjust_breakpoints( $css ) {
200202
* @return void
201203
*/
202204
public function enqueue_adjusted_responsive_css() {
205+
if ( ! $this->has_custom_breakpoints() ) {
206+
return;
207+
}
208+
203209
$css = stackable_get_responsive_css();
204210
$css = apply_filters( 'stackable_frontend_css', $css );
205211
wp_add_inline_style( 'ugb-style-css', $css );
@@ -215,6 +221,10 @@ public function enqueue_adjusted_responsive_css() {
215221
* @return void
216222
*/
217223
public function adjust_block_styles( $block_content, $block ) {
224+
if ( ! $this->has_custom_breakpoints() ) {
225+
return $block_content;
226+
}
227+
218228
if ( $block_content === null ) {
219229
return $block_content;
220230
}

0 commit comments

Comments
 (0)