Ticket #39157: 39157.4.patch
File 39157.4.patch, 7.7 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class-wp-query.php
346 346 public $is_comment_feed = false; 347 347 348 348 /** 349 * Set if query is home feed display. 350 * 351 * @since 4.7.1 352 * @access public 353 * @var bool 354 */ 355 public $is_home_feed = false; 356 357 /** 358 * Set if query is custom feed display. 359 * 360 * @since 4.7.1 361 * @access public 362 * @var bool 363 */ 364 public $is_custom_feed = false; 365 366 /** 349 367 * Set if query is trackback. 350 368 * 351 369 * @since 1.5.0 … … 511 529 $this->is_search = false; 512 530 $this->is_feed = false; 513 531 $this->is_comment_feed = false; 532 $this->is_home_feed = false; 533 $this->is_custom_feed = false; 514 534 $this->is_trackback = false; 515 535 $this->is_home = false; 516 536 $this->is_404 = false; … … 925 945 $this->is_archive = true; 926 946 } 927 947 928 if ( '' != $qv['feed'] ) 948 if ( '' != $qv['feed'] ) { 929 949 $this->is_feed = true; 950 if ( ! in_array( $qv['feed'], array( 'feed', 'rss', 'rss2', 'atom', 'rdf' ) ) ) { 951 $this->is_custom_feed = true; 952 } 953 } 930 954 931 955 if ( '' != $qv['embed'] ) { 932 956 $this->is_embed = true; … … 955 979 if ( $this->is_feed && ( !empty($qv['withcomments']) || ( empty($qv['withoutcomments']) && $this->is_singular ) ) ) 956 980 $this->is_comment_feed = true; 957 981 958 if ( !( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots ) )959 $this->is_home = true;960 982 983 984 if ( !( $this->is_singular || $this->is_archive || $this->is_search || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots || $this->is_custom_feed ) ) { 985 if ( $this->is_feed ) { 986 if ( ! $this->is_comment_feed ) { 987 $this->is_home_feed = true; 988 } 989 } else { 990 $this->is_home = true; 991 } 992 993 } 994 961 995 // Correct is_* for page_on_front and page_for_posts 962 996 if ( $this->is_home && 'page' == get_option('show_on_front') && get_option('page_on_front') ) { 963 997 $_query = wp_parse_args($this->query); … … 3666 3700 } 3667 3701 3668 3702 /** 3703 * Is the query for a hompage feed? 3704 * 3705 * @since 4.7.1 3706 * 3707 * @return bool 3708 */ 3709 public function is_home_feed() { 3710 return (bool) $this->is_home_feed; 3711 } 3712 3713 /** 3714 * Is the query for a custom feed? 3715 * 3716 * @since 4.7.1 3717 * 3718 * @return bool 3719 */ 3720 public function is_custom_feed() { 3721 return (bool) $this->is_custom_feed; 3722 } 3723 3724 /** 3669 3725 * Is the query for the front page of the site? 3670 3726 * 3671 3727 * This is for what is displayed at your site's main URL. -
src/wp-includes/functions.php
1221 1221 * search result, or main comments. By checking for the absense of posts we can prevent rendering the feed 1222 1222 * templates at invalid endpoints. e.g.) /wp-content/plugins/feed/ 1223 1223 */ 1224 if ( ! $wp_query->have_posts() && ! ( $wp_query->is_archive() || $wp_query->is_search() || $is_main_comments_feed ) ) {1224 if ( ! $wp_query->have_posts() && ! ( $wp_query->is_archive() || $wp_query->is_search() || $is_main_comments_feed || $wp_query->is_home_feed() || $wp_query->is_custom_feed() ) ) { 1225 1225 wp_die( __( 'ERROR: This is not a valid feed.' ), '', array( 'response' => 404 ) ); 1226 1226 } 1227 1227 -
src/wp-includes/query.php
383 383 } 384 384 385 385 /** 386 * Is the query for the blog homepage feed? 387 * 388 * @since 4.7.1 389 * 390 * @global WP_Query $wp_query Global WP_Query instance. 391 * 392 * @return bool 393 */ 394 function is_home_feed() { 395 global $wp_query; 396 397 if ( ! isset( $wp_query ) ) { 398 _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); 399 return false; 400 } 401 402 return $wp_query->is_home_feed(); 403 } 404 405 /** 406 * Is the query for the custom feed? 407 * 408 * @since 4.7.1 409 * 410 * @global WP_Query $wp_query Global WP_Query instance. 411 * 412 * @return bool 413 */ 414 function is_custom_feed() { 415 global $wp_query; 416 417 if ( ! isset( $wp_query ) ) { 418 _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); 419 return false; 420 } 421 422 return $wp_query->is_custom_feed(); 423 } 424 425 /** 386 426 * Is the query for the front page of the site? 387 427 * 388 428 * This is for what is displayed at your site's main URL. -
tests/phpunit/includes/testcase.php
593 593 'is_day', 594 594 'is_embed', 595 595 'is_feed', 596 'is_home_feed', 597 'is_custom_feed', 596 598 'is_front_page', 597 599 'is_home', 598 600 'is_month', -
tests/phpunit/tests/feed/rss2.php
63 63 64 64 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 65 65 create_initial_taxonomies(); 66 67 // Add a custom feed 68 add_feed( 'custom', 'do_rss2' ); 69 66 70 } 67 71 68 72 /** … … 269 273 $this->go_to( 'feed/' ); 270 274 271 275 // Verify the query object is a feed. 272 $this->assertQueryTrue( 'is_feed' );276 $this->assertQueryTrue( 'is_feed', 'is_home_feed' ); 273 277 274 278 // Queries performed on valid feed endpoints should contain posts. 275 279 $this->assertTrue( have_posts() ); … … 286 290 $this->assertEquals( 1, count( $rss ) ); 287 291 } 288 292 293 function test_valid_custom_feed_endpoint() { 294 // An example of a valid home feed endpoint. 295 $this->go_to( 'feed/custom' ); 296 297 // Verify the query object is a feed. 298 $this->assertQueryTrue( 'is_feed', 'is_custom_feed' ); 299 300 // Check to see if we have the expected XML output from the feed template. 301 $feed = $this->do_rss2(); 302 303 $xml = xml_to_array( $feed ); 304 305 // Get the <rss> child element of <xml>. 306 $rss = xml_find( $xml, 'rss' ); 307 308 // There should only be one <rss> child element. 309 $this->assertEquals( 1, count( $rss ) ); 310 } 311 289 312 /* 290 313 * Check to make sure we are rendering feed templates for the taxonomy feeds. 291 314 * e.g. https://example.com/category/foo/feed/ … … 381 404 * 382 405 * @ticket 30210 383 406 */ 384 function test_valid_sing le_post_comment_feed_endpoint() {407 function test_valid_singular_comment_feed_endpoint() { 385 408 // An example of an valid date archive feed endpoint. 386 409 $this->go_to( get_post_comments_feed_link( self::$posts[0] ) ); 387 410 -
tests/phpunit/tests/query/conditionals.php
253 253 // long version 254 254 foreach ($feeds as $feed) { 255 255 $this->go_to("/feed/{$feed}/"); 256 $this->assertQueryTrue('is_feed' );256 $this->assertQueryTrue('is_feed', 'is_home_feed'); 257 257 } 258 258 259 259 // short version 260 260 foreach ($feeds as $feed) { 261 261 $this->go_to("/{$feed}/"); 262 $this->assertQueryTrue('is_feed' );262 $this->assertQueryTrue('is_feed', 'is_home_feed'); 263 263 } 264 264 265 265 } … … 269 269 $types = array('rss2', 'rss', 'atom'); 270 270 foreach ($types as $type) { 271 271 $this->go_to(get_feed_link($type)); 272 $this->assertQueryTrue('is_feed' );272 $this->assertQueryTrue('is_feed', 'is_home_feed'); 273 273 } 274 274 } 275 275