Skip to:
Content

bbPress.org


Ignore:
Timestamp:
03/26/2012 07:36:47 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Add 'bump' functions for forum, topic, reply, and voice counts.

  • Functions not used yet
  • See #1799
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-topic-functions.php

    r3808 r3826  
    20472047}
    20482048
     2049/** Count Bumpers *************************************************************/
     2050
     2051/**
     2052 * Bump the total reply count of a topic
     2053 *
     2054 * @since bbPress (r3825)
     2055 *
     2056 * @param int $topic_id Optional. Forum id.
     2057 * @param int $difference Optional. Default 1
     2058 * @param bool $update_ancestors Optional. Default true
     2059 * @uses bbp_get_topic_id() To get the topic id
     2060 * @uses update_post_meta() To update the topic's reply count meta
     2061 * @uses apply_filters() Calls 'bbp_bump_topic_reply_count' with the reply
     2062 *                        count, topic id, and difference
     2063 * @return int Forum reply count
     2064 */
     2065function bbp_bump_topic_reply_count( $topic_id = 0, $difference = 1 ) {
     2066
     2067    // Get counts
     2068    $topic_id    = bbp_get_topic_id( $topic_id );
     2069    $reply_count = bbp_get_topic_reply_count( $topic_id, false );
     2070    $new_count   = (int) $reply_count + (int) $difference;
     2071
     2072    // Update this topic id's reply count
     2073    update_post_meta( $topic_id, '_bbp_reply_count', (int) $new_count );
     2074
     2075    return (int) apply_filters( 'bbp_bump_topic_reply_count', (int) $new_count, $topic_id, (int) $difference );
     2076}
     2077
     2078/**
     2079 * Bump the total hidden reply count of a topic
     2080 *
     2081 * @since bbPress (r3825)
     2082 *
     2083 * @param int $topic_id Optional. Forum id.
     2084 * @param int $difference Optional. Default 1
     2085 * @uses bbp_get_topic_id() To get the topic id
     2086 * @uses update_post_meta() To update the topic's reply count meta
     2087 * @uses apply_filters() Calls 'bbp_bump_topic_reply_count_hidden' with the
     2088 *                        reply count, topic id, and difference
     2089 * @return int Forum hidden reply count
     2090 */
     2091function bbp_bump_topic_reply_count_hidden( $topic_id = 0, $difference = 1 ) {
     2092
     2093    // Get counts
     2094    $topic_id    = bbp_get_topic_id( $topic_id );
     2095    $reply_count = bbp_get_topic_reply_count_hidden( $topic_id, false );
     2096    $new_count   = (int) $reply_count + (int) $difference;
     2097
     2098    // Update this topic id's hidder reply count
     2099    update_post_meta( $topic_id, '_bbp_reply_count_hidden', (int) $new_count );
     2100
     2101    return (int) apply_filters( 'bbp_bump_topic_reply_count_hidden', (int) $new_count, $topic_id, (int) $difference );
     2102}
     2103
    20492104/** Topic Updaters ************************************************************/
    20502105
     
    23192374    $voices = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT( DISTINCT post_author ) FROM {$wpdb->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' ) OR ( ID = %d AND post_type = '%s' );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ) );
    23202375
    2321     // If there's an error, make sure we at least have 1 voice
     2376    // If there's an error, make sure we have at least have 1 voice
    23222377    $voices = ( empty( $voices ) || is_wp_error( $voices ) ) ? 1 : $voices[0];
    23232378
Note: See TracChangeset for help on using the changeset viewer.