0

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.

0

There 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.

| improve this answer | |
  • Fails when PHP runs in (Fast-)CGI mode, because PHP_AUTH_USER is not available. – fuxia Oct 9 '13 at 23:13
  • @toscho - that's more of an issue with Basic Auth. There are fixes for this, like Basic Auth and FastCGI and the PHP documentation for HTTP Auth has good documentation around this too. – Joseph Erickson Oct 10 '13 at 0:56
  • Thanks @JosephErickson. The point is that I don't want to password-protect my feeds, I want to show a password-protected feed into the sidebar widget, but the widget lacks that feature and I can't configure the auth parameters :) – versvs Oct 11 '13 at 7:31
  • I'm sorry if I didnt make my point clear enought :( – versvs Oct 11 '13 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.