Skip to:
Content

BuddyPress.org

Ticket #8744: 8744.patch

File 8744.patch, 1.9 KB (added by imath, 3 years ago)
  • src/bp-core/bp-core-filters.php

    diff --git src/bp-core/bp-core-filters.php src/bp-core/bp-core-filters.php
    index 447dbace0..1d9c1aae0 100644
    add_filter( 'bp_get_template_stack', 'bp_add_template_stack_locations' ); 
    7878// Turn comments off for BuddyPress pages.
    7979add_filter( 'comments_open', 'bp_comments_open', 10, 2 );
    8080
     81// Force comments count to be 0 or comments list to be an empty array.
     82add_filter( 'comments_pre_query', 'bp_comments_pre_query', 10, 2 );
     83
    8184// Prevent DB query for WP's main loop.
    8285add_filter( 'posts_pre_query', 'bp_core_filter_wp_query', 10, 2 );
    8386
  • src/bp-core/bp-core-theme-compatibility.php

    diff --git src/bp-core/bp-core-theme-compatibility.php src/bp-core/bp-core-theme-compatibility.php
    index 06fa44853..17bcf8dc7 100644
    function bp_comments_open( $open, $post_id = 0 ) { 
    935935        return apply_filters( 'bp_force_comment_status', $retval, $open, $post_id );
    936936}
    937937
     938/**
     939 * Avoid potential extra comment query on BuddyPress pages.
     940 *
     941 * @since 10.5.0
     942 *
     943 * @param array|int|null   $comment_data     The comments list, the comment count or null.
     944 * @param WP_Comment_Query $wp_comment_query The WP_Comment_Query instance.
     945 * @return array|int|null Null to leave WordPress deal with the comment query, an empty array or 0 to shortcircuit it.
     946 */
     947function bp_comments_pre_query( $comment_data, $wp_comment_query ) {
     948        $is_post_null = isset( $wp_comment_query->query_vars['post_id'] ) && 0 === (int) $wp_comment_query->query_vars['post_id'];
     949
     950        if ( ! is_buddypress() || ! $is_post_null ) {
     951                return $comment_data;
     952        }
     953
     954        if ( isset( $wp_comment_query->query_vars['count'] ) && $wp_comment_query->query_vars['count'] ) {
     955                $comment_data = 0;
     956        } else {
     957                $comment_data = array();
     958        }
     959
     960        return $comment_data;
     961}
     962
    938963/**
    939964 * Do not allow {@link comments_template()} to render during theme compatibility.
    940965 *