pubsubhubbub / wordpress-pubsubhubbub

WebSub/PubSubHubbub for WordPress
https://wordpress.org/plugins/pubsubhubbub/
MIT License
64 stars 11 forks source link

Hub links in category/tags RSS feeds #9

Closed archon810 closed 3 years ago

archon810 commented 5 years ago

Hi @pfefferle,

I'm back again with another issue. First, please see https://twitter.com/ArtemR/status/1109836106055340032.

I did get a hold of someone at Superfeedr who agreed to take a look at the flood, and their reason ended up being that we only have the PuSH hub entry in the main feed, but not category or tag feeds, of which there are tens of thousands.

Because of that, they think those feeds are not available for PuSH (even though we do notify Superfeedr using a custom function that fires on publish_post action. What we do for pings of feeds other than the main feed is upon publish_post, create a list of category, tag, author, and a few custom feeds, and then send it to pubsubhubbub_publish_to_hub($feed_urls)).

I see in pubsubhubbub.php that Pubsubhubbub_Topics->add_rss_link_tag() is attached to rss2_head - is there any reason why that shouldn't be adding the hubs to all feeds, including category and tag ones?

For example: https://www.androidpolice.com/feed/ has

<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/><atom:link rel="hub" href="https://androidpolice.superfeedr.com"/>

but https://www.androidpolice.com/tags/sony/feed/ or https://www.androidpolice.com/topics/phones-devices/sony/feed/ do not.

Any ideas?

Thanks.

archon810 commented 5 years ago

Hi,

I found the issue. In includes/functions.php pubsubhubbub_show_discovery():

if (
        ( is_feed( $supported_feed_types ) && ! is_archive() && ! is_singular() && 0 == $withcomments ) ||
        ( is_feed( $supported_comment_feed_types ) && 1 == $withcomments ) ||
        ( is_home() && current_theme_supports( 'microformats2' ) )
    ) {
        $show_discovery = true;
    }

The fix is to remove && ! is_archive() because categories, tags, etc. are all types of an archive.

The question is what is the cleanest way to remove it in our case? Looks like at the end it also applies this filter: apply_filters( 'pubsubhubbub_show_discovery', $show_discovery ); so we could force $show_discovery there.

I wonder if you'd be interested in creating a better solution that would give us options to ping various feed types upon publish_post, like author, tag, category, and those returned by $wp_rewrite->feeds and then automatically enabling the hub output on checked feed types. Then the plugin would be a lot more complete, and we could remove all our custom code.

archon810 commented 5 years ago
/**
 * Force enable outputting of hub info to all feeds.
 *
 * @link https://github.com/pubsubhubbub/wordpress-pubsubhubbub/issues/9
 * @link https://twitter.com/ArtemR/status/1109836106055340032
 *
 */
function apkm_pubsubhubbub_show_discovery()
{
    //Only return true on feeds, or else we end up with hubs in HTTP headers
    if (is_feed()) {
        return true;
    }
    return false;
}
add_filter('pubsubhubbub_show_discovery', 'apkm_pubsubhubbub_show_discovery');
pfefferle commented 5 years ago

It is not that easy...

Your code only enables the discovery header for all the feeds, but the ping mechanism is missing. I have to figure out a good way how to also send updates for categories, tags and feeds in an efficient way. There might be cases (huge amount of tags, a lot of custom feeds) that causes very big POST messages.

But thanks for bringing this up, I like the idea!

archon810 commented 5 years ago

Right, I didn't post the ping mechanism here, but we've had it in place for several years now and haven't experienced any issues. We have usually not more than 20 categories per post and probably as many tags. Plus a few custom feeds and the author feed.