Skip to:
Content

bbPress.org

Changeset 7293


Ignore:
Timestamp:
04/16/2025 06:05:04 PM (2 months ago)
Author:
johnjamesjacoby
Message:

Replies: Fix a bug that causes replies to not appear in some topics.

In WordPress 6.8, WP_Query now enforces a consistent alphabetical order for array values. This change breaks the _bbp_has_replies_where() function, which previously relied on a strict comparison against post_type.

See: https://core.trac.wordpress.org/ticket/59516

This commit replaces the strict comparison with an array_diff() check to account for the new behavior. It also optimizes the surrounding logic to minimize repeated calls to $query->get().

Props vortfu, arl1nd.

Committed to trunk for 2.7.

Fixes #3631.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/replies/functions.php

    r7268 r7293  
    20872087    }
    20882088
    2089     // Bail if no post_parent to replace
    2090     if ( ! is_numeric( $query->get( 'post_parent' ) ) ) {
    2091         return $where;
    2092     }
    2093 
    2094     // Bail if not a topic and reply query
    2095     if ( array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) !== $query->get( 'post_type' ) ) {
    2096         return $where;
    2097     }
    2098 
    20992089    // Bail if including specific post ID's
    21002090    if ( $query->get( 'post__in' ) ) {
     
    21022092    }
    21032093
     2094    // Get post_parent from query (used to get the topic ID below)
     2095    $post_parent = $query->get( 'post_parent' );
     2096
     2097    // Bail if post_parent is default '' (uses is_numeric() because WordPress does internally)
     2098    if ( ! is_numeric( $post_parent ) ) {
     2099        return $where;
     2100    }
     2101
     2102    // Get post_type from query, define array to diff against
     2103    $queried_types = (array) $query->get( 'post_type' );
     2104    $post_types    = array( bbp_get_topic_post_type(), bbp_get_reply_post_type() );
     2105
     2106    // Bail if query is not already for both topic and reply post types
     2107    if ( array_diff( $post_types, $queried_types ) ) {
     2108        return $where;
     2109    }
     2110
    21042111    /** Proceed ***************************************************************/
    21052112
     
    21082115
    21092116    // Get the topic ID from the post_parent, set in bbp_has_replies()
    2110     $topic_id   = bbp_get_topic_id( $query->get( 'post_parent' ) );
     2117    $topic_id   = bbp_get_topic_id( $post_parent );
    21112118
    21122119    // The texts to search for
Note: See TracChangeset for help on using the changeset viewer.