membership - Preventing RSS feeds access to the authenticated uses only

I was trying to limit the access of feeds to the users who have user account on the website.i do not want unauthenticat

I was trying to limit the access of feeds to the users who have user account on the website. i do not want unauthenticated users to get the feeds. My site will have multiple types of membership and each with access to different feeds they can choose from.

I was trying to limit the access of feeds to the users who have user account on the website. i do not want unauthenticated users to get the feeds. My site will have multiple types of membership and each with access to different feeds they can choose from.

Share Improve this question asked Jul 7, 2019 at 7:01 Syed AbdullahSyed Abdullah 11 bronze badge 1
  • What is thought of doing is to disable all the default feeds, and then create custom feeds and put authentication checks. it that a good idea? – Syed Abdullah Commented Jul 7, 2019 at 7:02
Add a comment  | 

1 Answer 1

Reset to default 0

Assuming that:

Different types of memberships = different User Roles

You can simply apply some conditional logic to achieve this:

    function disable_rss_conditionally() {
    // First let's check if the user is logged in
    // you can use current_user_can() to pass to forbidden roles    

    if (! is_user_logged_in() || current_user_can( 'subscriber' ) ) {
// you can also use wp_die( __( 'Some message'));
    wp_redirect( home_url(), $status = 404 );
    }
    }


    add_action('do_feed', 'disable_rss_conditionally', 1);
    add_action('do_feed_rdf', 'disable_rss_conditionally', 1);
    add_action('do_feed_rss', 'disable_rss_conditionally', 1);
    add_action('do_feed_rss2', 'disable_rss_conditionally', 1);
    add_action('do_feed_atom', 'disable_rss_conditionally', 1);
    add_action('do_feed_rss2_comments', 'disable_rss_conditionally', 1);
    add_action('do_feed_atom_comments', 'disable_rss_conditionally', 1);

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

相关推荐

  • membership - Preventing RSS feeds access to the authenticated uses only

    I was trying to limit the access of feeds to the users who have user account on the website.i do not want unauthenticat

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信