Skip to:
Content

bbPress.org

Changeset 6685


Ignore:
Timestamp:
09/09/2017 03:00:07 PM (8 years ago)
Author:
johnjamesjacoby
Message:

Query: use NOT IN strategy in bbp_get_all_child_ids()

This ensures that only specific post-statuses are explicitly excluded from "all child IDs" type queries, where previously post-statuses needed to be specifically defined.

See #3128. Fixes #3140. 2.5 branch, for 2.5.14.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.5/includes/common/functions.php

    r6647 r6685  
    497497        if ( current_user_can( 'read_private_topics' ) || current_user_can( 'edit_others_topics' ) || current_user_can( 'view_trash' ) ) {
    498498
    499             // Declare empty arrays 
    500             $topics = $topic_titles = array(); 
     499            // Declare empty arrays
     500            $topics = $topic_titles = array();
    501501
    502502            // Private
     
    532532        if ( current_user_can( 'read_private_replies' ) || current_user_can( 'edit_others_replies' ) || current_user_can( 'view_trash' ) ) {
    533533
    534             // Declare empty arrays 
    535             $replies = $reply_titles = array(); 
     534            // Declare empty arrays
     535            $replies = $reply_titles = array();
    536536
    537537            // Private
     
    16401640    $child_ids = wp_cache_get( $cache_id, 'bbpress_posts' );
    16411641    if ( false === $child_ids ) {
    1642         $post_status = array( bbp_get_public_status_id() );
    1643 
    1644         // Extra post statuses based on post type
    1645         switch ( $post_type ) {
    1646 
    1647             // Forum
    1648             case bbp_get_forum_post_type() :
    1649                 $post_status[] = bbp_get_private_status_id();
    1650                 $post_status[] = bbp_get_hidden_status_id();
    1651                 break;
    1652 
    1653             // Topic
    1654             case bbp_get_topic_post_type() :
    1655                 $post_status[] = bbp_get_closed_status_id();
    1656                 $post_status[] = bbp_get_trash_status_id();
    1657                 $post_status[] = bbp_get_spam_status_id();
    1658                 break;
    1659 
    1660             // Reply
    1661             case bbp_get_reply_post_type() :
    1662                 $post_status[] = bbp_get_trash_status_id();
    1663                 $post_status[] = bbp_get_spam_status_id();
    1664                 break;
    1665         }
    1666 
    1667         // Join post statuses together
    1668         $post_status = "'" . implode( "', '", $post_status ) . "'";
    1669 
    1670         $child_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) );
     1642
     1643        // Join post statuses to specifically exclude together
     1644        $not_in      = array( 'draft', 'future' );
     1645        $post_status = "'" . implode( "', '", $not_in ) . "'";
     1646
     1647        $child_ids   = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status NOT IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) );
    16711648        wp_cache_set( $cache_id, $child_ids, 'bbpress_posts' );
    16721649    }
Note: See TracChangeset for help on using the changeset viewer.