Skip to content

Commit

Permalink
Add shortcode for getting number of user groups
Browse files Browse the repository at this point in the history
+ convert default visibility to integer
  • Loading branch information
cs1m0n committed Mar 4, 2024
1 parent 50ee61e commit 9d4fae8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions plugins/bcc-login/includes/class-bcc-login-visibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function __construct( BCC_Login_Settings $settings, BCC_Login_Client $client, BC
add_shortcode('target_groups_filter_widget', array($this, 'target_groups_filter_widget'));
add_shortcode('tags_for_queried_target_groups', array($this, 'tags_for_queried_target_groups'));
add_shortcode('get_bcc_group_name', array($this, 'get_bcc_group_name_by_id'));
add_shortcode('get_number_of_user_groups', array($this, 'get_number_of_user_groups'));
}

/**
Expand Down Expand Up @@ -132,7 +133,7 @@ function on_template_redirect() {

$post = get_post();
$level = $this->_client->get_current_user_level();
$visibility = $this->_settings->default_visibility;
$visibility = (int)$this->_settings->default_visibility;

// Post may not be defined when the user is visiting the homepage
if ( !$post ) {
Expand All @@ -152,7 +153,6 @@ function on_template_redirect() {
$visibility = $post_visibility;
}


if ( $visibility && $visibility > $level ) {
if ( is_user_logged_in() ) {
return $this->not_allowed_to_view_page();
Expand Down Expand Up @@ -498,6 +498,10 @@ private function get_user_bcc_filtering_groups_list() {
return $user_site_groups;
}

public function get_number_of_user_groups() {
return count($this->get_user_bcc_filtering_groups_list());
}

/**
* Checks the `bccLoginVisibility` attribute and hides the block if
* the current users shouldn't be allowed to see it.
Expand Down

0 comments on commit 9d4fae8

Please sign in to comment.