Ticket #20899: 20899.4.diff
File 20899.4.diff, 6.9 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.8.0 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.8.0 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; … … 927 947 $this->is_archive = true; 928 948 } 929 949 930 if ( '' != $qv['feed'] ) 950 if ( '' != $qv['feed'] ) { 931 951 $this->is_feed = true; 952 if ( ! in_array( $qv['feed'], array( 'feed', 'rss', 'rss2', 'atom', 'rdf' ) ) ) { 953 $this->is_custom_feed = true; 954 } 955 } 932 956 933 957 if ( '' != $qv['embed'] ) { 934 958 $this->is_embed = true; … … 957 981 if ( $this->is_feed && ( !empty($qv['withcomments']) || ( empty($qv['withoutcomments']) && $this->is_singular ) ) ) 958 982 $this->is_comment_feed = true; 959 983 960 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 ) )961 $this->is_home = true;962 984 985 986 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 ) ) { 987 if ( $this->is_feed ) { 988 if ( ! $this->is_comment_feed ) { 989 $this->is_home_feed = true; 990 } 991 } else { 992 $this->is_home = true; 993 } 994 995 } 996 963 997 // Correct is_* for page_on_front and page_for_posts 964 998 if ( $this->is_home && 'page' == get_option('show_on_front') && get_option('page_on_front') ) { 965 999 $_query = wp_parse_args($this->query); … … 3676 3710 } 3677 3711 3678 3712 /** 3713 * Is the query for a hompage feed? 3714 * 3715 * @since 4.8.0 3716 * 3717 * @return bool 3718 */ 3719 public function is_home_feed() { 3720 return (bool) $this->is_home_feed; 3721 } 3722 3723 /** 3724 * Is the query for a custom feed? 3725 * 3726 * @since 4.8.0 3727 * 3728 * @return bool 3729 */ 3730 public function is_custom_feed() { 3731 return (bool) $this->is_custom_feed; 3732 } 3733 3734 /** 3679 3735 * Is the query for the front page of the site? 3680 3736 * 3681 3737 * This is for what is displayed at your site's main URL. -
src/wp-includes/query.php
383 383 } 384 384 385 385 /** 386 * Is the query for the blog homepage feed? 387 * 388 * @since 4.8.0 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.8.0 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
626 626 'is_day', 627 627 'is_embed', 628 628 'is_feed', 629 'is_home_feed', 630 'is_custom_feed', 629 631 'is_front_page', 630 632 'is_home', 631 633 '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 /** … … 296 300 $this->go_to( 'feed/' ); 297 301 298 302 // Verify the query object is a feed. 299 $this->assertQueryTrue( 'is_feed' );303 $this->assertQueryTrue( 'is_feed', 'is_home_feed' ); 300 304 301 305 // Queries performed on valid feed endpoints should contain posts. 302 306 $this->assertTrue( have_posts() ); … … 313 317 $this->assertEquals( 1, count( $rss ) ); 314 318 } 315 319 320 function test_valid_custom_feed_endpoint() { 321 // An example of a valid home feed endpoint. 322 $this->go_to( 'feed/custom' ); 323 324 // Verify the query object is a feed. 325 $this->assertQueryTrue( 'is_feed', 'is_custom_feed' ); 326 327 // Check to see if we have the expected XML output from the feed template. 328 $feed = $this->do_rss2(); 329 330 $xml = xml_to_array( $feed ); 331 332 // Get the <rss> child element of <xml>. 333 $rss = xml_find( $xml, 'rss' ); 334 335 // There should only be one <rss> child element. 336 $this->assertEquals( 1, count( $rss ) ); 337 } 338 316 339 /* 317 340 * Check to make sure we are rendering feed templates for the taxonomy feeds. 318 341 * e.g. https://example.com/category/foo/feed/ … … 408 431 * 409 432 * @ticket 30210 410 433 */ 411 function test_valid_sing le_post_comment_feed_endpoint() {434 function test_valid_singular_comment_feed_endpoint() { 412 435 // An example of an valid date archive feed endpoint. 413 436 $this->go_to( get_post_comments_feed_link( self::$posts[0] ) ); 414 437 -
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