Make WordPress Core

Ticket #15770: 15770.2.diff

File 15770.2.diff, 1.5 KB (added by nacin, 13 years ago)
  • wp-includes/class-wp.php

     
    474474        function handle_404() {
    475475                global $wp_query;
    476476
    477                 if ( !is_admin() && ( 0 == count( $wp_query->posts ) ) && !is_404() && !is_robots() && !is_search() && !is_home() ) {
     477                // If we've already issued a 404, bail.
     478                if ( is_404() )
     479                        return;
     480
     481                // Never 404 for the admin, robots, or if we found posts.
     482                if ( is_admin() || is_robots() || $wp_query->posts ) {
     483                        status_header( 200 );
     484                        return;
     485                }
     486
     487                // We will 404 for paged queries, as no posts were found.
     488                if ( ! is_paged() ) {
     489
    478490                        // Don't 404 for these queries if they matched an object.
    479                         if ( ( is_tag() || is_category() || is_tax() || is_author() || is_post_type_archive() ) && $wp_query->get_queried_object() && !is_paged() ) {
    480                                 if ( !is_404() )
    481                                         status_header( 200 );
     491                        if ( ( is_tag() || is_category() || is_tax() || is_author() || is_post_type_archive() ) && $wp_query->get_queried_object() ) {
     492                                status_header( 200 );
    482493                                return;
    483494                        }
    484                         $wp_query->set_404();
    485                         status_header( 404 );
    486                         nocache_headers();
    487                 } elseif ( !is_404() ) {
    488                         status_header( 200 );
     495
     496                        // Don't 404 for these queries either.
     497                        if ( is_home() || is_search() ) {
     498                                status_header( 200 );
     499                                return;
     500                        }
    489501                }
     502
     503                // Guess it's time to 404.
     504                $wp_query->set_404();
     505                status_header( 404 );
     506                nocache_headers();
    490507        }
    491508
    492509        /**