Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix feed title output & allow feed title to be filtered. #279

Merged
merged 5 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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