Skip to content

Commit

Permalink
Added basic content restriction for membership for whole site restric…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
y000yal committed Jan 8, 2025
1 parent a08b927 commit 5bc6688
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions modules/content-restriction/class-urcr-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ public function basic_restrictions_templates( $template, $post ) {
}

$allowed_roles = get_option( 'user_registration_content_restriction_allow_to_roles', 'administrator' );
$allowed_memberships = get_option( 'user_registration_content_restriction_allow_to_memberships');

$current_user_role = is_user_logged_in() ? wp_get_current_user()->roles[0] : '';

Expand All @@ -869,6 +870,14 @@ public function basic_restrictions_templates( $template, $post ) {

$override_global_settings = get_post_meta( $post_id, 'urcr_meta_override_global_settings', $single = true );

$is_membership_active = ur_check_module_activation('membership');

if( $is_membership_active ) {
$members_subscription = new \WPEverest\URMembership\Admin\Repositories\MembersSubscriptionRepository();
$subscription = $members_subscription->get_member_subscription( wp_get_current_user()->ID);
$current_user_membership = ( !empty ( $subscription ) ) ? $subscription['item_id'] : array();
}

if ( ur_string_to_bool( $get_meta_data_checkbox ) ) {

if ( ! ur_string_to_bool( $override_global_settings ) ) {
Expand All @@ -887,6 +896,12 @@ public function basic_restrictions_templates( $template, $post ) {
$template = $this->urcr_restrict_contents_template( $template, $post );
}
}
elseif ( '3' === get_option( 'user_registration_content_restriction_allow_access_to' ) ) {
if ( is_array( $allowed_memberships ) && in_array( $current_user_membership, $allowed_memberships ) ) {
return $template;
}
$template = $this->urcr_restrict_contents_template( $template, $post );
}
} elseif ( $get_meta_data_allow_to == '0' ) {

if ( ! is_user_logged_in() ) {
Expand All @@ -904,6 +919,12 @@ public function basic_restrictions_templates( $template, $post ) {
$template = $this->urcr_restrict_contents_template( $template, $post );
}
}
elseif ( $get_meta_data_allow_to === '3' ) {
if ( is_array( $allowed_memberships ) && in_array( $current_user_membership, $allowed_memberships ) ) {
return $template;
}
return $this->urcr_restrict_contents_template( $template, $post );
}
}

return $template;
Expand Down

0 comments on commit 5bc6688

Please sign in to comment.