Skip to content

Commit 6c287e8

Browse files
authored
Merge pull request #51 from OpenSourceOrg/add/websub-migration
Add: WebSub backwards compatibility for the blog subdomain
2 parents dd65f25 + 4ed4dd6 commit 6c287e8

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mu-plugins/*
1818
!mu-plugins/mu-autoloader.php
1919
!mu-plugins/osi-event-list
2020
!mu-plugins/osi-sponsors-list
21+
!websub-compat.php
2122

2223
themes/*
2324
!themes/osi

mu-plugins/websub-compat.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Plugin Name: WebSub Backwards Compatibility
4+
* Plugin Description: Still send pings for the old `blog.opensource.org` Feed-URLs.
5+
* Version: 1.0.0
6+
* Author: WordPress.com Special Projects
7+
* Author URI: https://wpspecialprojects.wordpress.com/
8+
*/
9+
10+
if ( ! defined( 'ABSPATH' ) ) {
11+
return;
12+
}
13+
14+
/**
15+
* Filter `pubsubhubbub_feed_urls` and `pubsubhubbub_comment_feed_urls`.
16+
*
17+
* Still send pings for the old `blog.opensource.org` Feed-URLs.
18+
*
19+
* @param array $links Array of Feed URLs.
20+
*
21+
* @return array $links Array of filtered Feed URLs.
22+
*/
23+
function websub_compat( array $links ) {
24+
if ( ! $links ) {
25+
return $links;
26+
}
27+
28+
$host = wp_parse_url( get_home_url(), PHP_URL_HOST );
29+
$compat_links = array();
30+
31+
foreach ( $links as $link ) {
32+
$compat_links[] = str_replace( $host, 'blog.' . $host, $link );
33+
}
34+
35+
return array_unique( array_merge( $links, $compat_links ) );
36+
}
37+
add_filter( 'pubsubhubbub_feed_urls', 'websub_compat' );
38+
add_filter( 'pubsubhubbub_comment_feed_urls', 'websub_compat' );

0 commit comments

Comments
 (0)