Skip to:
Content

bbPress.org


Ignore:
Timestamp:
06/19/2017 04:29:43 AM (9 years ago)
Author:
johnjamesjacoby
Message:

Better 404 handling:

  • Introduce bbp_is_404 query var, and set this in places where the default 404 condition needs to be overridden
  • Introduce bbp_set_200() for cases where a default of 404 needs to be set to a 200
  • Introduce bbp_get_wp_query() helper for getting the $wp_query global
  • Update bbp_set_404() to accept a $query parameter to make passing the query around easier
  • Update child-ids queries to use the last_changed cache to reduce the amount of cache churn when cleaning

Fixes #3047. See #1973.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/core/template-functions.php

    r6573 r6583  
    532532                // 404 and bail if user does not have a profile
    533533                if ( empty( $the_user->ID ) || ! bbp_user_has_profile( $the_user->ID ) ) {
    534                         $posts_query->set_404();
     534                        $posts_query->bbp_is_404 = true;
    535535                        return;
    536536                }
    … …  
    593593                }
    594594
     595                // Make sure 404 is not set
     596                $posts_query->is_404  = false;
     597
     598                // Correct is_home variable
     599                $posts_query->is_home = false;
     600
    595601                // Looking at a single user
    596602                $posts_query->bbp_is_single_user = true;
    597603
    598                 // Make sure 404 is not set
    599                 $posts_query->is_404  = false;
    600 
    601                 // Correct is_home variable
    602                 $posts_query->is_home = false;
     604                // User found so don't 404 yet
     605                $posts_query->bbp_is_404 = false;
    603606
    604607                // User is looking at their own profile
    … …  
    621624                // Bail if view args is false (view isn't registered)
    622625                if ( false === $view_args ) {
    623                         $posts_query->set_404();
     626                        $posts_query->bbp_is_404 = true;
    624627                        return;
    625628                }
    … …  
    630633                // We are in a custom topic view
    631634                $posts_query->bbp_is_view = true;
     635
     636                // No 404 because views are all (currently) public
     637                $posts_query->bbp_is_404 = false;
    632638
    633639        // Search Page
    … …  
    646652                $posts_query->bbp_is_search = true;
    647653
     654                // No 404 because search is always public
     655                $posts_query->bbp_is_404 = false;
     656
    648657        // Forum/Topic/Reply Edit Page
    649658        } elseif ( ! empty( $is_edit ) ) {
    … …  
    654663                // Check which post_type we are editing, if any
    655664                if ( ! empty( $post_type ) ) {
    656                         switch( $post_type ) {
     665                        switch ( $post_type ) {
    657666
    658667                                // We are editing a forum
    659668                                case bbp_get_forum_post_type() :
    660                                         $posts_query->bbp_is_forum_edit = true;
    661                                         $posts_query->bbp_is_edit       = true;
     669                                        $posts_query->bbp_is_forum_edit  = true;
     670                                        $posts_query->bbp_is_edit        = true;
     671                                        $posts_query->bbp_is_404         = false;
    662672                                        break;
    663673
    664674                                // We are editing a topic
    665675                                case bbp_get_topic_post_type() :
    666                                         $posts_query->bbp_is_topic_edit = true;
    667                                         $posts_query->bbp_is_edit       = true;
     676                                        $posts_query->bbp_is_topic_edit  = true;
     677                                        $posts_query->bbp_is_edit        = true;
     678                                        $posts_query->bbp_is_404         = false;
    668679                                        break;
    669680
    670681                                // We are editing a reply
    671682                                case bbp_get_reply_post_type() :
    672                                         $posts_query->bbp_is_reply_edit = true;
    673                                         $posts_query->bbp_is_edit       = true;
     683                                        $posts_query->bbp_is_reply_edit  = true;
     684                                        $posts_query->bbp_is_edit        = true;
     685                                        $posts_query->bbp_is_404         = false;
    674686                                        break;
    675687                        }
    … …  
    679691                        $posts_query->bbp_is_topic_tag_edit = true;
    680692                        $posts_query->bbp_is_edit           = true;
     693                        $posts_query->bbp_is_404            = false;
    681694                }
    682695
Note: See TracChangeset for help on using the changeset viewer.