plugins - Restricting users to a specific front end page

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Upd

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 5 years ago.

Improve this question

I am looking for a way to restrict users of a certain role to only be able to access one page on my wordpress site. When a user of the role logs in they should be redirected to the page and they should not be able to access any other pages. I have tried multiple plugins that can restrict pages to users, but I have not found one that can restrict users to pages. Does this functionality exist within Wordpress and how would I implement it if it does?

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 5 years ago.

Improve this question

I am looking for a way to restrict users of a certain role to only be able to access one page on my wordpress site. When a user of the role logs in they should be redirected to the page and they should not be able to access any other pages. I have tried multiple plugins that can restrict pages to users, but I have not found one that can restrict users to pages. Does this functionality exist within Wordpress and how would I implement it if it does?

Share Improve this question asked Apr 30, 2019 at 0:35 user-2147482633user-2147482633 33 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You'd have to add a function during the init action of WP. There you'll get the current user and check whether they have a specific role assigned to them and redirect to the page when they do.

add_action('init', function () {
    $user = wp_get_current_user();
    $role = 'your role';

    if (in_array($role, $user->roles)) {
        wp_redirect('url');
    }
});

WordPress Function References:

  • https://developer.wordpress/reference/functions/add_action/
  • https://developer.wordpress/reference/functions/wp_get_current_user/
  • https://developer.wordpress/reference/functions/wp_redirect/

Relevant SE posts:

  • https://stackoverflow/questions/36720949/get-user-role-by-id-wordpress

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745539584a4632065.html

相关推荐

  • plugins - Restricting users to a specific front end page

    Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Upd

    14小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信