Changeset 6583
- Timestamp:
- 06/19/2017 04:29:43 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/common/ajax.php
r6581 r6583 76 76 77 77 // Everything is 200 OK. 78 status_header( 200);78 bbp_set_200(); 79 79 80 80 // Perform custom bbPress ajax -
trunk/src/includes/common/functions.php
r6573 r6583 93 93 */ 94 94 function bbp_get_paged() { 95 global $wp_query;95 $wp_query = bbp_get_wp_query(); 96 96 97 97 // Check the query var … … 1567 1567 1568 1568 $query = new WP_Query( array( 1569 'fields' => 'ids', 1570 'post_parent' => $parent_id, 1571 'post_status' => $post_status, 1572 'post_type' => $post_type, 1569 'fields' => 'ids', 1570 'suppress_filters' => true, 1571 'post_parent' => $parent_id, 1572 'post_status' => $post_status, 1573 'post_type' => $post_type, 1574 'posts_per_page' => -1, 1573 1575 1574 1576 // Maybe change these later 1575 'posts_per_page' => -1,1576 1577 'update_post_term_cache' => false, 1577 1578 'update_post_meta_cache' => false, 1578 1579 'ignore_sticky_posts' => true, 1579 'no_found_rows' => true 1580 'no_found_rows' => true, 1581 'nopaging' => true 1580 1582 ) ); 1581 1583 $child_ids = ! empty( $query->posts ) ? $query->posts : array(); … … 1603 1605 } 1604 1606 1605 // The ID of the cached query 1606 $cache_id = 'bbp_parent_all_' . $parent_id . '_type_' . $post_type . '_child_ids'; 1607 // Check cache key 1608 $key = md5( serialize( array( 'parent_id' => $parent_id, 'post_type' => $post_type ) ) ); 1609 $last_changed = wp_cache_get_last_changed( 'bbpress_posts' ); 1610 $cache_key = "bbp_child_ids:{$key}:{$last_changed}"; 1607 1611 1608 1612 // Check for cache and set if needed 1609 $child_ids = wp_cache_get( $cache_ id, 'bbpress_posts' );1613 $child_ids = wp_cache_get( $cache_key, 'bbpress_posts' ); 1610 1614 if ( false === $child_ids ) { 1611 1615 $post_status = array( bbp_get_public_status_id() ); … … 1645 1649 1646 1650 // Always cache the results 1647 wp_cache_set( $cache_ id, $child_ids, 'bbpress_posts' );1651 wp_cache_set( $cache_key, $child_ids, 'bbpress_posts' ); 1648 1652 } 1649 1653 … … 2016 2020 * 2017 2021 * @since 2.0.0 bbPress (r3051) 2018 * 2019 * @global WP_Query $wp_query 2020 */ 2021 function bbp_set_404() { 2022 global $wp_query; 2023 2024 if ( ! isset( $wp_query ) ) { 2025 _doing_it_wrong( __FUNCTION__, esc_html__( 'Conditional query tags do not work before the query is run. Before then, they always return false.', 'bbpress' ), '3.1' ); 2026 return false; 2027 } 2028 2029 $wp_query->set_404(); 2030 } 2031 2032 /** 2033 * Maybe avoid default 404 handling for some bbPress pages 2022 * @since 2.6.0 bbPress (r6583) Use status_header() & nocache_headers() 2023 * 2024 * @param WP_Query $query The query being checked 2025 * 2026 * @return bool Always returns true 2027 */ 2028 function bbp_set_404( $query = null ) { 2029 2030 // Global fallback 2031 if ( empty( $query ) ) { 2032 $query = bbp_get_wp_query(); 2033 } 2034 2035 // Setup environment 2036 $query->set_404(); 2037 2038 // Setup request 2039 status_header( 404 ); 2040 nocache_headers(); 2041 } 2042 2043 /** 2044 * Sets the 200 status header. 2045 * 2046 * @since 2.6.0 bbPress (r6583) 2047 */ 2048 function bbp_set_200() { 2049 status_header( 200 ); 2050 } 2051 2052 /** 2053 * Maybe handle the default 404 handling for some bbPress conditions 2054 * 2055 * Some conditions (like private/hidden forums and edits) have their own checks 2056 * on `bbp_template_redirect` and are not currently 404s. 2034 2057 * 2035 2058 * @since 2.6.0 bbPress (r6555) 2059 * 2060 * @param bool $override Whether to override the default handler 2061 * @param WP_Query $wp_query The posts query being referenced 2062 * 2063 * @return bool False to leave alone, true to override 2036 2064 */ 2037 2065 function bbp_pre_handle_404( $override = false, $wp_query = false ) { 2066 2067 // Handle a bbPress 404 condition 2068 if ( isset( $wp_query->bbp_is_404 ) ) { 2069 2070 // Either force a 404 when 200, or a 200 when 404 2071 $override = ( true === $wp_query->bbp_is_404 ) 2072 ? bbp_set_404( $wp_query ) 2073 : bbp_set_200(); 2074 } 2075 2038 2076 return $override; 2039 2077 } 2078 2079 /** 2080 * Maybe pre-assign the posts that are returned from a WP_Query. 2081 * 2082 * This effectively short-circuits the default query for posts, which is 2083 * currently only used to avoid calling the main query when it's not necessary. 2084 * 2085 * @since 2.6.0 bbPress (r6580) 2086 * 2087 * @param mixed $posts Default null. Array of posts (possibly empty) 2088 * @param WP_Query $wp_query 2089 * 2090 * @return mixed Null if no override. Array if overridden. 2091 */ 2092 function bbp_posts_pre_query( $posts = null, $wp_query = false ) { 2093 2094 // Custom 404 handler is set, so set posts to empty array to avoid 2 queries 2095 if ( isset( $wp_query->bbp_is_404 ) ) { 2096 $posts = array(); 2097 } 2098 2099 // Return, maybe overridden 2100 return $posts; 2101 } -
trunk/src/includes/core/abstraction.php
r6573 r6583 49 49 // Filter & return 50 50 return apply_filters( 'bbp_get_global_object', $retval, $name, $type, $default ); 51 } 52 53 /** 54 * Get the `$wp_query` global without needing to declare it everywhere 55 * 56 * @since 2.6.0 bbPress (r6582) 57 * 58 * @return WP_Roles 59 */ 60 function bbp_get_wp_query() { 61 return bbp_get_global_object( 'wp_query', 'WP_Query' ); 51 62 } 52 63 -
trunk/src/includes/core/cache.php
r6573 r6583 167 167 clean_object_term_cache( $post->ID, $post->post_type ); 168 168 169 // Loop through query types and clean caches 170 foreach ( $post_types as $post_type ) { 171 $key = 'bbp_parent_all_' . $post->ID . '_type_' . $post_type . '_child_ids'; 172 wp_cache_delete( $key, 'bbpress_posts' ); 173 } 169 // Bump the last_changed cache 170 wp_cache_set( 'last_changed', microtime(), 'bbpress_posts' ); 174 171 175 172 /** -
trunk/src/includes/core/filters.php
r6554 r6583 61 61 add_filter( 'the_title', 'bbp_get_reply_title_fallback', 2, 2 ); 62 62 63 // Avoid 404ing 64 add_filter( 'pre_handle_404', 'bbp_pre_handle_404', 10, 2 ); 63 // Avoid queries & 404s 64 add_filter( 'pre_handle_404', 'bbp_pre_handle_404', 10, 2 ); 65 add_action( 'posts_pre_query', 'bbp_posts_pre_query', 10, 2 ); 65 66 66 67 /** -
trunk/src/includes/core/template-functions.php
r6573 r6583 532 532 // 404 and bail if user does not have a profile 533 533 if ( empty( $the_user->ID ) || ! bbp_user_has_profile( $the_user->ID ) ) { 534 $posts_query-> set_404();534 $posts_query->bbp_is_404 = true; 535 535 return; 536 536 } … … 593 593 } 594 594 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 595 601 // Looking at a single user 596 602 $posts_query->bbp_is_single_user = true; 597 603 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; 603 606 604 607 // User is looking at their own profile … … 621 624 // Bail if view args is false (view isn't registered) 622 625 if ( false === $view_args ) { 623 $posts_query-> set_404();626 $posts_query->bbp_is_404 = true; 624 627 return; 625 628 } … … 630 633 // We are in a custom topic view 631 634 $posts_query->bbp_is_view = true; 635 636 // No 404 because views are all (currently) public 637 $posts_query->bbp_is_404 = false; 632 638 633 639 // Search Page … … 646 652 $posts_query->bbp_is_search = true; 647 653 654 // No 404 because search is always public 655 $posts_query->bbp_is_404 = false; 656 648 657 // Forum/Topic/Reply Edit Page 649 658 } elseif ( ! empty( $is_edit ) ) { … … 654 663 // Check which post_type we are editing, if any 655 664 if ( ! empty( $post_type ) ) { 656 switch ( $post_type ) {665 switch ( $post_type ) { 657 666 658 667 // We are editing a forum 659 668 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; 662 672 break; 663 673 664 674 // We are editing a topic 665 675 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; 668 679 break; 669 680 670 681 // We are editing a reply 671 682 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; 674 686 break; 675 687 } … … 679 691 $posts_query->bbp_is_topic_tag_edit = true; 680 692 $posts_query->bbp_is_edit = true; 693 $posts_query->bbp_is_404 = false; 681 694 } 682 695 -
trunk/src/includes/core/theme-compat.php
r6573 r6583 395 395 'is_single' => false, 396 396 'is_archive' => false, 397 'is_tax' => false ,397 'is_tax' => false 398 398 ), 'theme_compat_reset_post' ); 399 399 } else { … … 428 428 'is_single' => false, 429 429 'is_archive' => false, 430 'is_tax' => false ,430 'is_tax' => false 431 431 ), 'theme_compat_reset_post' ); 432 432 } … … 458 458 // Clean up the dummy post 459 459 unset( $dummy ); 460 461 /**462 * Force the header back to 200 status if not a deliberate 404463 *464 * @see https://bbpress.trac.wordpress.org/ticket/1973465 */466 if ( ! $wp_query->is_404() ) {467 status_header( 200 );468 }469 460 470 461 // If we are resetting a post, we are in theme compat -
trunk/src/includes/extend/buddypress/groups.php
r6573 r6583 816 816 */ 817 817 public function display_forums( $offset = 0 ) { 818 global $wp_query;819 818 820 819 // Allow actions immediately before group forum output … … 928 927 add_filter( 'bbp_get_topic_types', array( $this, 'unset_super_sticky' ), 10, 1 ); 929 928 929 // Get the main query object 930 $wp_query = bbp_get_wp_query(); 931 930 932 // Set the edit switches 931 933 $wp_query->bbp_is_edit = true; … … 994 996 995 997 if ( bp_action_variable( $offset + 2 ) === bbp_get_edit_rewrite_id() ) : 998 999 // Get the main query object 1000 $wp_query = bbp_get_wp_query(); 996 1001 997 1002 // Set the edit switches -
trunk/src/includes/extend/buddypress/members.php
r6573 r6583 209 209 } 210 210 211 global $wp_query; 211 // Get the main query object 212 $wp_query = bbp_get_wp_query(); 212 213 213 214 // 'favorites' action -
trunk/src/includes/forums/functions.php
r6573 r6583 963 963 // Query for private forums 964 964 $private_forums = new WP_Query( array( 965 'fields' => 'ids', 965 966 'suppress_filters' => true, 966 'nopaging' => true,967 'no_found_rows' => true,968 967 'post_type' => bbp_get_forum_post_type(), 969 968 'post_status' => bbp_get_private_status_id(), 970 'fields' => 'ids' 969 'posts_per_page' => -1, 970 971 // Performance 972 'ignore_sticky_posts' => true, 973 'no_found_rows' => true, 974 'nopaging' => true, 975 'update_post_term_cache' => false, 976 'update_post_meta_cache' => false 971 977 ) ); 972 978 973 979 // Query for hidden forums 974 980 $hidden_forums = new WP_Query( array( 981 'fields' => 'ids', 975 982 'suppress_filters' => true, 976 'nopaging' => true,977 'no_found_rows' => true,978 983 'post_type' => bbp_get_forum_post_type(), 979 984 'post_status' => bbp_get_hidden_status_id(), 980 'fields' => 'ids' 985 'posts_per_page' => -1, 986 987 // Performance 988 'ignore_sticky_posts' => true, 989 'no_found_rows' => true, 990 'nopaging' => true, 991 'update_post_term_cache' => false, 992 'update_post_meta_cache' => false 981 993 ) ); 982 994 … … 1650 1662 if ( empty( $topic_count ) ) { 1651 1663 $query = new WP_Query( array( 1652 'fields' => 'ids', 1653 'post_parent' => $forum_id, 1654 'post_status' => array( bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id() ), 1655 'post_type' => bbp_get_topic_post_type(), 1656 1657 // Maybe change these later 1658 'posts_per_page' => -1, 1664 'fields' => 'ids', 1665 'suppress_filters' => true, 1666 'post_parent' => $forum_id, 1667 'post_status' => array( bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id() ), 1668 'post_type' => bbp_get_topic_post_type(), 1669 'posts_per_page' => -1, 1670 1671 // Performance 1659 1672 'update_post_term_cache' => false, 1660 1673 'update_post_meta_cache' => false, 1661 1674 'ignore_sticky_posts' => true, 1662 'no_found_rows' => true 1675 'no_found_rows' => true, 1676 'nopaging' => true 1663 1677 ) ); 1664 1678 $topic_count = $query->post_count; … … 1706 1720 if ( ! empty( $topic_ids ) ) { 1707 1721 $query = new WP_Query( array( 1708 'fields' => 'ids', 1709 'post_parent__in' => $topic_ids, 1710 'post_status' => bbp_get_public_status_id(), 1711 'post_type' => bbp_get_reply_post_type(), 1712 1713 // Maybe change these later 1714 'posts_per_page' => -1, 1722 'fields' => 'ids', 1723 'suppress_filters' => true, 1724 'post_parent__in' => $topic_ids, 1725 'post_status' => bbp_get_public_status_id(), 1726 'post_type' => bbp_get_reply_post_type(), 1727 'posts_per_page' => -1, 1728 1729 // Performance 1715 1730 'update_post_term_cache' => false, 1716 1731 'update_post_meta_cache' => false, 1717 1732 'ignore_sticky_posts' => true, 1718 'no_found_rows' => true 1733 'no_found_rows' => true, 1734 'nopaging' => true 1719 1735 ) ); 1720 1736 $reply_count = ! empty( $query->posts ) ? count( $query->posts ) : 0; … … 2106 2122 2107 2123 $query = new WP_Query( array( 2108 'fields' => 'ids', 2109 'post_parent__in' => $topic_ids, 2110 'post_status' => bbp_get_public_status_id(), 2111 'post_type' => bbp_get_reply_post_type(), 2112 'orderby' => array( 2124 'fields' => 'ids', 2125 'suppress_filters' => true, 2126 'post_parent__in' => $topic_ids, 2127 'post_status' => bbp_get_public_status_id(), 2128 'post_type' => bbp_get_reply_post_type(), 2129 'posts_per_page' => 1, 2130 'orderby' => array( 2113 2131 'post_date' => 'DESC', 2114 2132 'ID' => 'DESC' 2115 2133 ), 2116 2134 2117 // Maybe change these later 2118 'posts_per_page' => 1, 2135 // Performance 2119 2136 'update_post_term_cache' => false, 2120 2137 'update_post_meta_cache' => false, 2121 2138 'ignore_sticky_posts' => true, 2122 'no_found_rows' => true 2139 'no_found_rows' => true, 2140 'nopaging' => true 2123 2141 ) ); 2124 2142 $reply_id = array_shift( $query->posts ); … … 2144 2162 } 2145 2163 2146 global $wp_query; 2147 2148 // Define local variable 2164 // Define local variables 2149 2165 $forum_id = 0; 2166 $wp_query = bbp_get_wp_query(); 2150 2167 2151 2168 // Check post type … … 2170 2187 // If forum is explicitly hidden and user not capable, set 404 2171 2188 if ( ! empty( $forum_id ) && bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 2172 bbp_set_404( );2189 bbp_set_404( $wp_query ); 2173 2190 } 2174 2191 } … … 2187 2204 } 2188 2205 2189 global $wp_query; 2190 2191 // Define local variable 2206 // Define local variables 2192 2207 $forum_id = 0; 2208 $wp_query = bbp_get_wp_query(); 2193 2209 2194 2210 // Check post type … … 2214 2230 // If forum is explicitly hidden and user not capable, set 404 2215 2231 if ( ! empty( $forum_id ) && bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 2216 bbp_set_404( );2232 bbp_set_404( $wp_query ); 2217 2233 } 2218 2234 } … … 2257 2273 // Note that we get all post statuses here 2258 2274 $topics = new WP_Query( array( 2275 'fields' => 'id=>parent', 2259 2276 'suppress_filters' => true, 2277 2278 // What and how 2260 2279 'post_type' => bbp_get_topic_post_type(), 2261 2280 'post_parent' => $forum_id, 2262 2281 'post_status' => array_keys( get_post_stati() ), 2263 2282 'posts_per_page' => -1, 2264 'nopaging' => true, 2265 'no_found_rows' => true, 2266 'fields' => 'id=>parent' 2283 2284 // Performance 2285 'ignore_sticky_posts' => true, 2286 'no_found_rows' => true, 2287 'nopaging' => true, 2288 'update_post_term_cache' => false, 2289 'update_post_meta_cache' => false 2267 2290 ) ); 2268 2291 … … 2305 2328 ); 2306 2329 2307 // Forum is being trashed, so its topics and repliesare trashed too2330 // Forum is being trashed, so its topics (and replies) are trashed too 2308 2331 $topics = new WP_Query( array( 2332 'fields' => 'id=>parent', 2309 2333 'suppress_filters' => true, 2310 2334 'post_type' => bbp_get_topic_post_type(), … … 2312 2336 'post_status' => $post_stati, 2313 2337 'posts_per_page' => -1, 2314 'nopaging' => true, 2315 'no_found_rows' => true, 2316 'fields' => 'id=>parent' 2338 2339 // Performance 2340 'ignore_sticky_posts' => true, 2341 'no_found_rows' => true, 2342 'nopaging' => true, 2343 'update_post_term_cache' => false, 2344 'update_post_meta_cache' => false 2317 2345 ) ); 2318 2346 -
trunk/src/includes/forums/template.php
r6582 r6583 202 202 function bbp_get_forum_id( $forum_id = 0 ) { 203 203 $bbp = bbpress(); 204 $wp_query = bbp_get_ global_object( 'wp_query', 'WP_Query');204 $wp_query = bbp_get_wp_query(); 205 205 206 206 // Easy empty checking -
trunk/src/includes/replies/template.php
r6582 r6583 328 328 function bbp_get_reply_id( $reply_id = 0 ) { 329 329 $bbp = bbpress(); 330 $wp_query = bbp_get_ global_object( 'wp_query', 'WP_Query');330 $wp_query = bbp_get_wp_query(); 331 331 332 332 // Easy empty checking -
trunk/src/includes/topics/template.php
r6582 r6583 442 442 function bbp_get_topic_id( $topic_id = 0 ) { 443 443 $bbp = bbpress(); 444 $wp_query = bbp_get_ global_object( 'wp_query', 'WP_Query');444 $wp_query = bbp_get_wp_query(); 445 445 446 446 // Easy empty checking -
trunk/tests/phpunit/testcases/core/cache.php
r6053 r6583 8 8 9 9 /** 10 * @group jjj 10 11 * @covers ::bbp_clean_post_cache 11 12 */ … … 14 15 // Get the topic post type. 15 16 $tpt = bbp_get_topic_post_type(); 17 $rpt = bbp_get_topic_post_type(); 16 18 17 19 // Set up a forum with 1 topic and 1 reply to that topic. … … 33 35 // Make sure we've cached some data. 34 36 bbp_get_all_child_ids( $f, $tpt ); 35 bbp_get_all_child_ids( $t, $ tpt );37 bbp_get_all_child_ids( $t, $rpt ); 36 38 37 $this->assertEquals( array( $t ), wp_cache_get( "bbp_parent_all_{$f}_type_{$tpt}_child_ids", 'bbpress_posts' ) ); 38 $this->assertEquals( array( $r ), wp_cache_get( "bbp_parent_all_{$t}_type_{$tpt}_child_ids", 'bbpress_posts' ) ); 39 // Setup 40 $f_key = md5( serialize( array( 'parent_id' => $f, 'post_type' => $tpt ) ) ); 41 $t_key = md5( serialize( array( 'parent_id' => $t, 'post_type' => $rpt ) ) ); 42 $last_changed = wp_cache_get_last_changed( 'bbpress_posts' ); 43 44 // Keys 45 $f_key = "bbp_child_ids:{$f_key}:{$last_changed}"; 46 $t_key = "bbp_child_ids:{$t_key}:{$last_changed}"; 47 48 $this->assertEquals( array( $t ), wp_cache_get( $f_key, 'bbpress_posts' ) ); 49 $this->assertEquals( array( $r ), wp_cache_get( $t_key, 'bbpress_posts' ) ); 39 50 40 51 // Clean the cache. 41 52 bbp_clean_post_cache( $r ); 42 53 43 $this->assertEquals( false, wp_cache_get( "bbp_parent_all_{$f}_type_{$tpt}_child_ids", 'bbpress_posts' ) ); 44 $this->assertEquals( false, wp_cache_get( "bbp_parent_all_{$t}_type_{$tpt}_child_ids", 'bbpress_posts' ) ); 54 // Setup 55 $last_changed = wp_cache_get_last_changed( 'bbpress_posts' ); 56 57 // Keys 58 $f_key = "bbp_child_ids:{$f_key}:{$last_changed}"; 59 $t_key = "bbp_child_ids:{$t_key}:{$last_changed}"; 60 61 $this->assertEquals( false, wp_cache_get( $f_key, 'bbpress_posts' ) ); 62 $this->assertEquals( false, wp_cache_get( $t_key, 'bbpress_posts' ) ); 45 63 } 46 64 }
Note: See TracChangeset
for help on using the changeset viewer.