最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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 } ?> 

发布评论

评论列表(0)

  1. 暂无评论