Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 58 additions & 19 deletions includes/optional-modules/class-rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static function init() {
add_action( 'atom_entry', [ __CLASS__, 'add_extra_tags' ] );
add_filter( 'the_excerpt_rss', [ __CLASS__, 'maybe_remove_content_featured_image' ], 1 );
add_filter( 'the_content_feed', [ __CLASS__, 'maybe_remove_content_featured_image' ], 1 );
add_filter( 'the_content_feed', [ __CLASS__, 'maybe_remove_non_distributable_images' ], 1 );
add_filter( 'the_content_feed', [ __CLASS__, 'maybe_add_tracking_snippets' ], 1 );
add_filter( 'wpseo_include_rss_footer', [ __CLASS__, 'maybe_suppress_yoast' ] );
add_action( 'rss2_ns', [ __CLASS__, 'maybe_inject_yahoo_namespace' ] );
Expand Down Expand Up @@ -69,25 +70,26 @@ public static function get_feed_url( $feed_post, $feed_type = 'rss' ) {
*/
public static function get_feed_settings( $feed_post = null ) {
$default_settings = [
'category_include' => [],
'category_exclude' => [],
'use_image_tags' => false,
'use_media_tags' => false,
'use_updated_tags' => false,
'use_tags_tags' => false,
'full_content' => true,
'num_items_in_feed' => 10,
'offset' => 0,
'timeframe' => false,
'content_featured_image' => false,
'suppress_yoast' => false,
'yahoo_namespace' => false,
'update_frequency' => false,
'use_post_id_as_guid' => false,
'cdata_titles' => false,
'republication_tracker' => false,
'only_republishable' => false,
'custom_tracking_snippet' => '',
'category_include' => [],
'category_exclude' => [],
'use_image_tags' => false,
'use_media_tags' => false,
'use_updated_tags' => false,
'use_tags_tags' => false,
'full_content' => true,
'num_items_in_feed' => 10,
'offset' => 0,
'timeframe' => false,
'content_featured_image' => false,
'suppress_yoast' => false,
'yahoo_namespace' => false,
'update_frequency' => false,
'use_post_id_as_guid' => false,
'cdata_titles' => false,
'republication_tracker' => false,
'only_republishable' => false,
'only_distributable_images' => false,
'custom_tracking_snippet' => '',
];

if ( ! $feed_post ) {
Expand Down Expand Up @@ -393,6 +395,20 @@ public static function render_content_settings_metabox( $feed_post ) {
<input type="checkbox" name="only_republishable" value="1" <?php checked( $settings['only_republishable'] ); ?> />
</td>
</tr>
<tr>
<th>
<?php esc_html_e( 'Include only distributable images', 'newspack-plugin' ); ?>
<p class="description">
<?php echo esc_html_x( 'When toggled on, images not marked as distributable will be excluded from feed content.', 'help text for remove non-distributable images setting', 'newspack-plugin' ); ?>
<br/>
<?php esc_html_e( 'Note: this will respect the same settings for distributable images RTT uses for other distributiion purposes', 'newspack-plugin' ); ?>
</p>
</th>
<td>
<input type="hidden" name="only_distributable_images" value="0" />
<input type="checkbox" name="only_distributable_images" value="1" <?php checked( $settings['only_distributable_images'] ); ?> />
</td>
</tr>
<?php endif; ?>
</table>

Expand Down Expand Up @@ -604,6 +620,8 @@ public static function save_settings( $feed_post_id ) {
$only_republishable = filter_input( INPUT_POST, 'only_republishable', FILTER_SANITIZE_NUMBER_INT );
$settings['only_republishable'] = (bool) $only_republishable;

$only_distributable_images = filter_input( INPUT_POST, 'only_distributable_images', FILTER_SANITIZE_NUMBER_INT );
$settings['only_distributable_images'] = (bool) $only_distributable_images;
}

update_post_meta( $feed_post_id, self::FEED_SETTINGS_META, $settings );
Expand Down Expand Up @@ -839,6 +857,27 @@ public static function maybe_remove_content_featured_image( $content ) {
return $content;
}

/**
* Filter feed content to remove non-distributable images if needed.
*
* @param string $content Feed content.
* @return string Modified $content.
*/
public static function maybe_remove_non_distributable_images( $content ) {
$settings = self::get_feed_settings();
if ( ! $settings || ! self::is_republication_tracker_plugin_active() || empty( $settings['only_distributable_images'] ) ) {
return $content;
}

if ( class_exists( '\Republication_Tracker_Tool_Content' ) &&
method_exists( '\Republication_Tracker_Tool_Content', 'remove_non_distributable_images' )
) {
return \Republication_Tracker_Tool_Content::remove_non_distributable_images( $content );
}

return $content;
}

/**
* Suppress the Yoast prepended and appended content depending on setting.
*
Expand Down