admin管理员组文章数量:1122846
I'm trying to do something and I don't seem to yield any successful results when searching neither at wordpress forums nor here.
I would like to extend the standard RSS widget so that I can set an user/password for HTTP Authentication in order to fetch the feed items.
If there is an existing solution that I'm missing and already provides this feature, any pointer will be much appreciated.
Thanks.
I'm trying to do something and I don't seem to yield any successful results when searching neither at wordpress.org forums nor here.
I would like to extend the standard RSS widget so that I can set an user/password for HTTP Authentication in order to fetch the feed items.
If there is an existing solution that I'm missing and already provides this feature, any pointer will be much appreciated.
Thanks.
Share Improve this question asked Oct 9, 2013 at 15:57 versvsversvs 2215 silver badges14 bronze badges1 Answer
Reset to default 0There is a solution as described here where you can put code at the top of wp-includes/feed-rss2.php
to authenticate that the requester is a registered WordPress user. A better solution is to add it to your theme's functions.php
file:
function my_check_feed_auth() {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="RSS Feeds"');
header('HTTP/1.0 401 Unauthorized');
echo 'Feeds from this site are private';
exit;
} else {
if (is_wp_error(wp_authenticate($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW']))) {
header('WWW-Authenticate: Basic realm="RSS Feeds"');
header('HTTP/1.0 401 Unauthorized');
echo 'Username and password were not correct';
exit;
}
}
}
add_action('do_feed_rss2', 'my_check_feed_auth', 1);
add_action('do_feed_atom', 'my_check_feed_auth', 1);
add_action('do_feed_rss', 'my_check_feed_auth', 1);
add_action('do_feed_rdf', 'my_check_feed_auth', 1);
This will require Basic Auth, which most RSS readers can configure, with the user's WordPress login information. You can add more feeds on to the end there with more add_action
calls, if you want.
本文标签: rssHow to show a feed that requires userpass within a sidebar widget
版权声明:本文标题:rss - How to show a feed that requires userpass within a sidebar widget? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736284146a1927187.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论