| @@ -1,0 +1,70 @@ | ||
| 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 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 20 | + exit( 0 ); | |
| 21 | +} | |
| 22 | + | |
| 23 | +foreach ( array( 'rss_head', 'rss1_head', 'rss2_head' ) as $rss_head_action ) { | |
| 24 | + add_action( $rss_head_action, 'jetpack_wpcomreader_feed_id' ); | |
| 25 | +} | |
| 26 | +foreach ( array( 'rss_item', 'rss1_item', 'rss2_item' ) as $rss_item_action ) { | |
| 27 | + add_action( $rss_item_action, 'jetpack_wpcomreader_post_id' ); | |
| 28 | +} | |
| 29 | + | |
| 30 | +/** | |
| 31 | + * Output feed identifier based on blog ID. | |
| 32 | + * | |
| 33 | + * @return void | |
| 34 | + */ | |
| 35 | +function jetpack_wpcomreader_feed_id() { | |
| 36 | + if ( | |
| 37 | + ( new Host() )->is_wpcom_simple() | |
| 38 | + || ( | |
| 39 | + ( new Connection_Manager() )->is_connected() | |
| 40 | + && ! ( new Status() )->is_offline_mode() | |
| 41 | + ) | |
| 42 | + ) { | |
| 43 | + $blog_id = Connection_Manager::get_site_id( true ); // Silence since we're not wanting to handle the error state. | |
| 44 | + if ( ! $blog_id ) { | |
| 45 | + return; | |
| 46 | + } | |
| 47 | + | |
| 48 | + printf( | |
| 49 | + '<site xmlns="com-wordpress:feed-additions:1">%d</site>', | |
| 50 | + (int) $blog_id | |
| 51 | + ); | |
| 52 | + } | |
| 53 | +} | |
| 54 | + | |
| 55 | +/** | |
| 56 | + * Output feed item identifier based on current post ID. | |
| 57 | + * | |
| 58 | + * @return void | |
| 59 | + */ | |
| 60 | +function jetpack_wpcomreader_post_id() { | |
| 61 | + $id = get_the_ID(); | |
| 62 | + if ( ! $id ) { | |
| 63 | + return; | |
| 64 | + } | |
| 65 | + | |
| 66 | + printf( | |
| 67 | + '<post-id xmlns="com-wordpress:feed-additions:1">%d</post-id>', | |
| 68 | + (int) $id | |
| 69 | + ); | |
| 70 | +} | |