I have an ACF relationship field set to show on the User Role (user's profile page). From there we can select what forums the user can access, if a forum is not given to a user then access to that forum is denied. The ACF field is set to Post Object.
I have the following code in page.php, this is the page that is used for the forums. The code below should check the field "forum_access" and if a user has access to the given forum and allow access.
Unfortunately, it's not working correctly. If a user is not logged in they still have access.
<?php
$is_allowed_access = get_field('forum_access');
$show_content = true;
if ( !is_user_logged_in() && $is_allowed_access) {
$show_content = false;
}elseif( is_user_logged_in() && $is_allowed_access ){
$current_user = wp_get_current_user();
$show_content = false;
foreach( $is_allowed_access as $user_allowed ){
if( $user_allowed['ID'] == $current_user->ID ){
$show_content = true;
break;
}
}
}
?>
<?php if( $show_content ){ ?>
Allowed
<?php } else { ?>
Denied
<?php } ?>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744673631a4587195.html
评论列表(0条)