PHP新手,我尝试通过一个代码片段插件执行以下操作,但不断出现严重错误:
将所有未登录用户限制在主页、关于和定价页面。如果试图访问其他页面,请重定向到;“无许可”;消息页面
如果用户已登录,如果他们是帖子作者,则只允许他们查看前端的帖子。如果尝试,请重定向到;“无许可”;第页管理员在前端具有完全读取权限我尝试过插件,但没有什么能满足我的需要,
非常感谢您的帮助,代码如下:
add_action( \'template_redirect\', \'redirect_non_permitted_users\' );
function redirect_non_permitted_users () {
$userID = get_user_id();
$authorID = get_the_author_meta(ID);
if(current_user_can(\'manage_options\')){
}
elseif( $userID <> $authorID || ! is_user_logged_in() || ! is_front_page() || ! is_page(\'about\') || ! is_page(\'pricing\')){
wp_redirect(\'https://www.example.com/no-permission/\');
exit;
}
}