| 1 |
<?php |
| 2 |
/** |
| 3 |
* This provides minor tweaks to improve the experience for Jetpack feed in the WordPress.com Reader. |
| 4 |
* |
| 5 |
* This does not make sites available in the Reader—that depends on the public access to /feed/ as a method on the WP.com side |
| 6 |
* to check if a site is public. It also does not add any content to the feed. Any content that should not be displayed in the Reader |
| 7 |
* or other RSS readers should be filtered out elsewhere. |
| 8 |
* |
| 9 |
* These hooks were originally part of the now-deprecated Enhanced Distribution. |
| 10 |
* |
| 11 |
* @since 13.3 |
| 12 |
* @package Automattic/jetpack |
| 13 |
*/ |
| 14 |
|
| 15 |
use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 16 |
use Automattic\Jetpack\Status; |
| 17 |
use Automattic\Jetpack\Status\Host; |
| 18 |
|
| 19 |
foreach ( array( 'rss_head', 'rss1_head', 'rss2_head' ) as $rss_head_action ) { |
| 20 |
add_action( $rss_head_action, 'jetpack_wpcomreader_feed_id' ); |
| 21 |
} |
| 22 |
foreach ( array( 'rss_item', 'rss1_item', 'rss2_item' ) as $rss_item_action ) { |
| 23 |
add_action( $rss_item_action, 'jetpack_wpcomreader_post_id' ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Output feed identifier based on blog ID. |
| 28 |
* |
| 29 |
* @return void |
| 30 |
*/ |
| 31 |
function jetpack_wpcomreader_feed_id() { |
| 32 |
if ( |
| 33 |
( new Host() )->is_wpcom_simple() |
| 34 |
|| ( |
| 35 |
( new Connection_Manager() )->is_connected() |
| 36 |
&& ! ( new Status() )->is_offline_mode() |
| 37 |
) |
| 38 |
) { |
| 39 |
$blog_id = Connection_Manager::get_site_id( true ); // Silence since we're not wanting to handle the error state. |
| 40 |
if ( ! $blog_id ) { |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
printf( |
| 45 |
'<site xmlns="com-wordpress:feed-additions:1">%d</site>', |
| 46 |
(int) $blog_id |
| 47 |
); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Output feed item identifier based on current post ID. |
| 53 |
* |
| 54 |
* @return void |
| 55 |
*/ |
| 56 |
function jetpack_wpcomreader_post_id() { |
| 57 |
$id = get_the_ID(); |
| 58 |
if ( ! $id ) { |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
printf( |
| 63 |
'<post-id xmlns="com-wordpress:feed-additions:1">%d</post-id>', |
| 64 |
(int) $id |
| 65 |
); |
| 66 |
} |
| 67 |
|