阻止RSS提要仅访问经过身份验证的用途

时间:2019-07-07 作者:Syed Abdullah

我试图限制在网站上拥有用户帐户的用户访问提要。我不想让未经身份验证的用户获取提要。我的网站将有多种类型的会员,每种会员都可以访问不同的提要,他们可以从中选择。

1 个回复
SO网友:João Teixeira

假设:

Different types of memberships = different User Roles

您可以简单地应用一些条件逻辑来实现这一点:

    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);