php - ACF relationship on user profile page used for allowed access

I have an ACF relationship field set to show on the User Role (user's profile page). From there we can select what

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

相关推荐

  • php - ACF relationship on user profile page used for allowed access

    I have an ACF relationship field set to show on the User Role (user's profile page). From there we can select what

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信