Changeset 6583 for trunk/src/includes/common/functions.php
- Timestamp:
- 06/19/2017 04:29:43 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.