[英]How to redirect a user off a page by user role?
A lot of these guides are 'redirect after login' I have mulitple user types with different levels of access, I'd like to write some code which if a 'Subscriber' role goes onto the page (Which they do not have access it'll redirect them. 这些指南中有很多是“登录后重定向”的,我的用户类型多种多样,具有不同的访问级别,我想写一些代码,如果页面上有“订阅者”角色(他们没有访问权限), ll重定向他们。
Here's one of the many code snippets I've tried, but can't get it to work! 这是我尝试过的众多代码片段之一,但无法正常工作! Help :)
救命 :)
function consultant_page_redirect() {
$current_user = wp_get_current_user();
$role_name = $current_user->roles[0];
if (('subscriber' === $role_name ) &&( is_single( array(2864, 2630)) ) ) {
wp_redirect('/trial-user-page/');
}
}
function consultant_page_redirect( $user_login, $user ) {
$role_name = $user->roles[0];
if (('subscriber' === $role_name ) &&( is_single( array(2864, 2630)) ) ) {
wp_redirect('/trial-user-page/');
}
}
add_action('wp_login', 'consultant_page_redirect', 10, 2);
Add this snippet code on child theme functions.php 在子主题functions.php上添加此代码段代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.