admin管理员组文章数量:1394172
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 } ?>
本文标签: phpACF relationship on user profile page used for allowed access
版权声明:本文标题:php - ACF relationship on user profile page used for allowed access 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744673631a2618977.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论