Feeds: Don't attempt to generate RSS feeds for invalid feed URLs such as wp-content/feed.

Props stevenkword, JRGould, lyubomir_popov, johnbillion
Fixes #30210


git-svn-id: https://develop.svn.wordpress.org/trunk@38929 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2016-10-25 21:53:22 +00:00
parent ad25902a65
commit 895203b3e4
2 changed files with 232 additions and 3 deletions
+12
View File
@@ -1213,6 +1213,18 @@ function bool_from_yn( $yn ) {
function do_feed() {
global $wp_query;
// Determine if we are looking at the main comment feed
$is_main_comments_feed = ( $wp_query->is_comment_feed() && ! $wp_query->is_singular() );
/*
* Check the queried object for the existence of posts if it is not a feed for an archive,
* search result, or main comments. By checking for the absense of posts we can prevent rendering the feed
* templates at invalid endpoints. e.g.) /wp-content/plugins/feed/
*/
if ( ! $wp_query->have_posts() && ! ( $wp_query->is_archive() || $wp_query->is_search() || $is_main_comments_feed ) ) {
wp_die( __( 'ERROR: This is not a valid feed.' ), '', array( 'response' => 404 ) );
}
$feed = get_query_var( 'feed' );
// Remove the pad, if present.