Skip to content

Commit

Permalink
🐛 Fix check for block visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
MatzeKitt committed Aug 22, 2019
1 parent 895b86f commit 36f31b6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/class-block-control.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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'] ) ) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 36f31b6

Please sign in to comment.