Skip to content

Commit da97ff4

Browse files
feat(rss): Hooks extending RSS (#4055)
* feat(rss): add hooks for extending rss fn * chore(rss): add doc block comments
1 parent 2d858ea commit da97ff4

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

includes/optional-modules/class-rss.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ public static function get_feed_settings( $feed_post = null ) {
9090
'custom_tracking_snippet' => '',
9191
];
9292

93+
/**
94+
* Filter the default RSS feed settings.
95+
*
96+
* @param array $default_settings The default settings for RSS feeds.
97+
* @return array Modified default settings.
98+
*/
99+
$default_settings = apply_filters( 'newspack_rss_feed_settings', $default_settings );
100+
93101
if ( ! $feed_post ) {
94102
$query_feed = filter_input( INPUT_GET, self::FEED_QUERY_ARG, FILTER_SANITIZE_FULL_SPECIAL_CHARS );
95103
if ( ! $query_feed ) {
@@ -108,6 +116,15 @@ public static function get_feed_settings( $feed_post = null ) {
108116
return $default_settings;
109117
}
110118

119+
/**
120+
* Filter the saved RSS feed settings.
121+
*
122+
* @param array $saved_settings The saved settings for this feed.
123+
* @param int $feed_post_id The post ID of the feed.
124+
* @return array Modified saved settings.
125+
*/
126+
$saved_settings = apply_filters( 'newspack_rss_saved_settings', $saved_settings, $feed_post_id );
127+
111128
return shortcode_atts( $default_settings, $saved_settings );
112129
}
113130

@@ -379,6 +396,15 @@ public static function render_content_settings_metabox( $feed_post ) {
379396
<input type="checkbox" name="use_post_id_as_guid" value="1" <?php checked( $settings['use_post_id_as_guid'] ); ?> />
380397
</td>
381398
</tr>
399+
<?php
400+
/**
401+
* Action for plugins to add their own content settings to the RSS feed settings UI.
402+
*
403+
* @param array $settings Current feed settings.
404+
* @param WP_Post $feed_post The feed post object.
405+
*/
406+
do_action( 'newspack_rss_render_content_settings', $settings, $feed_post );
407+
?>
382408

383409
<?php
384410
// Only show this new option if the Republication Tracker Tool plugin is active.
@@ -475,6 +501,15 @@ public static function render_technical_settings_metabox( $feed_post ) {
475501
<textarea name="custom_tracking_snippet" rows="4" cols="50"><?php echo esc_textarea( $settings['custom_tracking_snippet'] ); ?></textarea>
476502
</td>
477503
</tr>
504+
<?php
505+
/**
506+
* Action for plugins to add their own technical settings to the RSS feed settings UI.
507+
*
508+
* @param array $settings Current feed settings.
509+
* @param WP_Post $feed_post The feed post object.
510+
*/
511+
do_action( 'newspack_rss_render_technical_settings', $settings, $feed_post );
512+
?>
478513
<?php if ( defined( 'WPSEO_VERSION' ) && WPSEO_VERSION ) : ?>
479514
<tr>
480515
<th>
@@ -607,6 +642,15 @@ public static function save_settings( $feed_post_id ) {
607642

608643
}
609644

645+
/**
646+
* Filter the feed settings before they are saved.
647+
*
648+
* @param array $settings The feed settings to be saved.
649+
* @param int $feed_post_id The post ID of the feed.
650+
* @return array Modified feed settings.
651+
*/
652+
$settings = apply_filters( 'newspack_rss_modify_save_settings', $settings, $feed_post_id );
653+
610654
update_post_meta( $feed_post_id, self::FEED_SETTINGS_META, $settings );
611655
// @todo flush feed cache here.
612656
}
@@ -682,6 +726,14 @@ function( $post_guid, $post_id ) {
682726
];
683727
$query->set( 'meta_query', $meta_query );
684728
}
729+
730+
/**
731+
* Modify the RSS feed query.
732+
*
733+
* @param WP_Query $query The WP_Query object for the feed.
734+
* @param array $settings The current feed settings.
735+
*/
736+
do_action( 'newspack_rss_modify_feed_query', $query, $settings );
685737
}
686738

687739
/**
@@ -817,6 +869,16 @@ public static function maybe_add_tracking_snippets( $content ) {
817869

818870
$content .= $attribution . $custom_tracking_content;
819871

872+
/**
873+
* Filter the feed content after tracking snippets have been added.
874+
*
875+
* @param string $content The feed content with tracking snippets applied.
876+
* @param int $post_id The ID of the current post.
877+
* @param array $settings The current feed settings.
878+
* @return string Modified feed content.
879+
*/
880+
$content = apply_filters( 'newspack_rss_after_tracking_snippet', $content, $post_id, $settings );
881+
820882
return $content;
821883
}
822884

0 commit comments

Comments
 (0)