Skip to:
Content

bbPress.org

Changeset 6254


Ignore:
Timestamp:
01/17/2017 09:05:29 AM (8 years ago)
Author:
johnjamesjacoby
Message:

Topic Tags: Introduce bbp_update_topic_tag_count() and include public/closed statuses in counts.

Fixes #3043.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bbpress.php

    r6252 r6254  
    690690                'rewrite'               => bbp_get_topic_tag_tax_rewrite(),
    691691                'capabilities'          => bbp_get_topic_tag_caps(),
    692                 'update_count_callback' => '_update_post_term_count',
     692                'update_count_callback' => 'bbp_update_topic_tag_count',
    693693                'query_var'             => true,
    694694                'show_tagcloud'         => true,
  • trunk/src/includes/topics/functions.php

    r6224 r6254  
    39943994}
    39953995
     3996/**
     3997 * Will update topic-tag count based on object type.
     3998 *
     3999 * Function for the default callback for topic-tag taxonomies.
     4000 *
     4001 * @see https://bbpress.trac.wordpress.org/ticket/3043
     4002 * @access private
     4003 *
     4004 * @since 2.6.0 bbPress (r6253)
     4005 *
     4006 * @param array  $terms    List of Term taxonomy IDs.
     4007 * @param object $taxonomy Current taxonomy object of terms.
     4008 */
     4009function bbp_update_topic_tag_count( $terms, $taxonomy ) {
     4010
     4011    // Bail if no object types are available
     4012    if ( empty( $terms ) || empty( $taxonomy->object_type ) ) {
     4013        return;
     4014    }
     4015
     4016    // Get object types
     4017    $object_types = (array) $taxonomy->object_type;
     4018
     4019    foreach ( $object_types as &$object_type ) {
     4020        list( $object_type ) = explode( ':', $object_type );
     4021    }
     4022
     4023    $object_types = array_unique( $object_types );
     4024
     4025    if ( ! empty( $object_types ) ) {
     4026        $object_types = esc_sql( array_filter( $object_types, 'post_type_exists' ) );
     4027    }
     4028
     4029    // Statuses to count
     4030    $object_statuses = array(
     4031        bbp_get_public_status_id(),
     4032        bbp_get_closed_status_id()
     4033    );
     4034
     4035    // Get database
     4036    $bbp_db = bbp_db();
     4037
     4038    // Loop through terms, maybe update counts
     4039    foreach ( (array) $terms as $term ) {
     4040        $count = 0;
     4041
     4042        // Get count, and bump it
     4043        if ( ! empty( $object_types ) ) {
     4044            $query    = "SELECT COUNT(*) FROM {$bbp_db->term_relationships}, {$bbp_db->posts} WHERE {$bbp_db->posts}.ID = {$bbp_db->term_relationships}.object_id AND post_status IN ('" . implode("', '", $object_statuses ) . "') AND post_type IN ('" . implode("', '", $object_types ) . "') AND term_taxonomy_id = %d";
     4045            $prepare  = $bbp_db->prepare( $query, $term );
     4046            $count   += (int) $bbp_db->get_var( $prepare );
     4047        }
     4048
     4049        /** This action is documented in wp-includes/taxonomy.php */
     4050        do_action( 'edit_term_taxonomy', $term, $taxonomy->name );
     4051        $bbp_db->update( $bbp_db->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
     4052
     4053        /** This action is documented in wp-includes/taxonomy.php */
     4054        do_action( 'edited_term_taxonomy', $term, $taxonomy->name );
     4055    }
     4056}
     4057
    39964058/** Autoembed *****************************************************************/
    39974059
Note: See TracChangeset for help on using the changeset viewer.