From 36f31b67c473305a64b005d072d11b9a82dcdaed Mon Sep 17 00:00:00 2001 From: Matthias Kittsteiner Date: Thu, 22 Aug 2019 10:37:16 +0200 Subject: [PATCH] :bug: Fix check for block visibility --- src/class-block-control.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/class-block-control.php b/src/class-block-control.php index a1a09ab..cdbb702 100644 --- a/src/class-block-control.php +++ b/src/class-block-control.php @@ -126,7 +126,7 @@ private function hide_logged_out( $attr, $value ) { * @return bool True if the content should be hidden, false otherwise */ private function hide_mobile( $attr, $value ) { - if ( $attr === 'hide_mobile' && $value === true && $this->mobile_detect->isMobile() ) { + if ( $attr === 'hide_mobile' && $value === true && $this->mobile_detect->isMobile() && ! $this->mobile_detect->isTablet() ) { return true; } @@ -176,6 +176,8 @@ public function set_plugin_file( $file ) { public function toggle_blocks( $block_content, $block ) { // set default content $content = ''; + // set default visibility + $is_hidden = false; // if there are no attributes, the block should be displayed if ( empty( $block['attrs'] ) ) { @@ -185,25 +187,32 @@ public function toggle_blocks( $block_content, $block ) { // iterate through all block attributes foreach ( $block['attrs'] as $attr => $value ) { if ( $this->hide_desktop( $attr, $value ) ) { + $is_hidden = true; break; } if ( $this->hide_mobile( $attr, $value ) ) { + $is_hidden = true; break; } if ( $this->hide_tablet( $attr, $value ) ) { + $is_hidden = true; break; } if ( $this->hide_logged_in( $attr, $value ) ) { + $is_hidden = true; break; } if ( $this->hide_logged_out( $attr, $value ) ) { + $is_hidden = true; break; } - + } + + if ( ! $is_hidden ) { // get the block content to output it $content = $block_content; }