Skip to content

Commit

Permalink
Fix author names in blog post rss feed (fixes #652)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Abraham <[email protected]>
  • Loading branch information
cjyabraham committed Nov 4, 2024
1 parent f2ed45a commit d7bb10d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ private function define_public_hooks() {
$this->loader->add_filter( 'the_seo_framework_sitemap_nhpt_query_args', $plugin_public, 'remove_news_from_sitemap' );
$this->loader->add_filter( 'the_seo_framework_sitemap_supported_post_types', $plugin_public, 'remove_newsletters_from_sitemap' );
$this->loader->add_action( 'send_headers', $plugin_public, 'add_header_cache', 15 );
$this->loader->add_filter( 'the_author', $plugin_public, 'rss_author_prep' );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,31 @@ public function add_header_cache() {
header( 'Cache-Control: public, max-age=60, s-maxage=43200, stale-while-revalidate=86400, stale-if-error=604800' );
}
}

/**
* Filters the author for RSS feeds to use the guest author if appropriate
* or ignore certain other authors.
*
* @param string $display_name Display name.
*
*/
public function rss_author_prep( $display_name ) {
if ( is_feed() ) {
$author = get_post_meta( get_the_ID(), 'lf_post_guest_author', true );
if ( $author ) {
// Return guest author if there is one.
return $author;
}

$authors_to_ignore = array( 'Jessie', 'Katie Meinders' );
if ( in_array( $display_name, $authors_to_ignore, false ) ) {
// return "CNCF" if the author is in the ignore list.
return 'CNCF';
} else {
return $display_name;
}
}

return $display_name;
}
}

0 comments on commit d7bb10d

Please sign in to comment.