Skip to content

Commit

Permalink
Merge pull request #279 from 10up/fix/rss-title-filter
Browse files Browse the repository at this point in the history
Fix feed title output & allow feed title to be filtered.
  • Loading branch information
dkotter authored Feb 26, 2024
2 parents 6a9175d + 097a603 commit b9cbb5d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,30 @@ function podcasting_feed_episodes_per_page( $qty ) {

```

## Customize the RSS feed title

The `<title>` element of the RSS feed can be adjusted using the `simple_podcasting_feed_title` filter.

```php
<?php

add_filter( 'simple_podcasting_feed_title', 'podcasting_feed_update_feed_title', 10, 2 );

/**
* Filter the name of the of the feed channel
*
* @param $output Output to be modified.
* @param $term WP_Term object representing the podcast
* @return string
*/
function podcasting_feed_update_feed_title( $output, $term ) {
$term_name = $term->name;

return '10up Presents: ' . $term_name;
}

```

## Customize RSS feed

If you want to modify RSS feed items output, there is a filter for that:
Expand Down
5 changes: 3 additions & 2 deletions includes/customize-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ function bloginfo_rss_name( $output ) {
$title = get_term_meta( $term->term_id, 'podcasting_title', true );
if ( empty( $title ) ) {
$title = get_bloginfo( 'name' );
$title = "$title &#187; {$term->name}";
$output = "$title &#187; {$term->name}";
} else {
$output = $title;
}

return $output;
return apply_filters( 'simple_podcasting_feed_title', $output, $term );

}
add_filter( 'wp_title_rss', __NAMESPACE__ . '\bloginfo_rss_name' );

Expand Down
27 changes: 26 additions & 1 deletion tests/unit/test-customize-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function test_pre_get_posts_no_feed() {
}

public function test_pre_get_posts_feed() {
$query_mock = \Mockery::mock( '\WP_Query' );
$query_mock = \Mockery::mock( '\WP_Query' );

$query_mock->shouldReceive( 'is_feed' )->andReturn( true );

Expand Down Expand Up @@ -176,6 +176,31 @@ function ( $text, $num_words, $more ) {
}
}

public function test_rss_title_can_be_filtered() {
$queried_object = (object) array(
'term_id' => 42,
'name' => 'Original Podcast Name'
);
\WP_Mock::userFunction( 'get_queried_object' )
->andReturn( $queried_object );

\WP_Mock::userFunction( 'get_bloginfo' )
->with( 'name' )
->andReturn( 'Blogname' );


\WP_Mock::onFilter( 'simple_podcasting_feed_title' )
->with( 'Blogname &#187; Original Podcast Name', $queried_object )
->reply( 'Filtered Podcast Title' );

$this->assertEquals(
'Filtered Podcast Title',
tenup_podcasting\bloginfo_rss_name( 'Podcast Title' ),
'tenup_podcasting\bloginfo_rss_name() should return the filtered value.'
);

}

public function data_provider_for_test_feed_item() {
return array(
'Term not found' => array(
Expand Down

0 comments on commit b9cbb5d

Please sign in to comment.