Skip to:
Content

bbPress.org

Ticket #1694: 1694.4.diff

File 1694.4.diff, 11.3 KB (added by netweb, 7 years ago)
  • includes/core/actions.php

    diff --git a/includes/core/actions.php b/includes/core/actions.php
    index 11f93fd..527c8df 100644
    a b add_action( 'bbp_deleted_reply', 'bbp_update_reply_walker' ); 
    247247add_action( 'bbp_spammed_reply',   'bbp_update_reply_walker' );
    248248add_action( 'bbp_unspammed_reply', 'bbp_update_reply_walker' );
    249249
     250// Users counts
     251add_action( 'bbp_new_topic',     'bbp_bump_user_topic_count_on_new_topic',        10, 4 );
     252add_action( 'bbp_new_reply',     'bbp_bump_user_reply_count_on_new_reply',        10, 5 );
     253add_action( 'bbp_trash_topic',   'bbp_dwindle_user_topic_count_on_deleted_topic', 10    );
     254add_action( 'bbp_trash_reply',   'bbp_dwindle_user_reply_count_on_deleted_reply', 10    );
     255add_action( 'bbp_spammed_topic', 'bbp_dwindle_user_topic_count_on_deleted_topic', 10    );
     256add_action( 'bbp_spammed_reply', 'bbp_dwindle_user_reply_count_on_deleted_reply', 10    );
     257
    250258// User status
    251259// @todo make these sub-actions
    252260add_action( 'make_ham_user',  'bbp_make_ham_user'  );
  • includes/users/options.php

    diff --git a/includes/users/options.php b/includes/users/options.php
    index 4309907..7fa5f04 100644
    a b function bbp_user_reply_count( $user_id = 0, $integer = false ) { 
    190190                        return false;
    191191
    192192                $count  = (int) get_user_option( '_bbp_reply_count', $user_id );
    193                 $filter = ( true === $integer ) ? 'bbp_get_user_topic_count_int' : 'bbp_get_user_topic_count';
     193                $filter = ( true === $integer ) ? 'bbp_get_user_reply_count_int' : 'bbp_get_user_reply_count';
    194194
    195195                return apply_filters( $filter, $count, $user_id );
    196196        }
    function bbp_user_last_posted( $user_id = 0 ) { 
    288288
    289289                return apply_filters( 'bbp_get_user_last_posted', $time, $user_id );
    290290        }
     291
     292/**
     293 * Increments the count of topics created by an user.
     294 *
     295 * @since bbPress (rXXXX)
     296 *
     297 * @param int $user_id
     298 * @param int $by_how_many
     299 * @uses bbp_get_user_topic_count() To get the users current topic count
     300 *
     301 * @
     302 */
     303function bbp_increment_user_topic_count( $user_id, $by_how_many = 1 ) {
     304        $count = intval( bbp_get_user_topic_count( $user_id ) );
     305        $count = $count + $by_how_many;
     306        $count = apply_filters( 'bbp_increment_user_topic_count', $count, $user_id, $by_how_many );
     307        update_user_option( $user_id, '_bbp_topic_count', $count );
     308}
     309
     310/**
     311 * Increments the count of replies created by an user.
     312 *
     313 * @since bbPress (rXXXX)
     314 *
     315 * @param int $user_id
     316 * @param int $by_how_many
     317 * @uses bbp_get_user_reply_count() To get the users current reply count
     318 */
     319function bbp_increment_user_reply_count( $user_id, $by_how_many = 1 ) {
     320        $count = intval( bbp_get_user_reply_count( $user_id ) );
     321        $count = $count + $by_how_many;
     322        $count = apply_filters( 'bbp_increment_user_reply_count', $count, $user_id, $by_how_many );
     323        update_user_option( $user_id, '_bbp_reply_count', $count );
     324}
     325
     326/**
     327 * Decrements the count of topics created by an user.
     328 *
     329 * @since bbPress (rXXXX)
     330 *
     331 * @param int $user_id
     332 * @param int $by_how_many
     333 * @uses bbp_get_user_topic_count() To get the users current topic count
     334 */
     335function bbp_decrement_user_topic_count( $user_id, $by_how_many = 1 ) {
     336
     337        $count = intval( bbp_get_user_topic_count( $user_id ) );
     338
     339        $count = $count - $by_how_many;
     340        $count = apply_filters( 'bbp_decrement_user_topic_count', $count, $user_id, $by_how_many );
     341
     342        // Topic count can't be less than zero.
     343        if ( $count < 0 )
     344                $count = 0;
     345
     346        update_user_option( $user_id, '_bbp_topic_count', $count );
     347}
     348
     349/**
     350 * Decrements by one the count of replies created by an user.
     351 *
     352 * @since bbPress (rXXXX)
     353 *
     354 * @param int $user_id
     355 * @param int $by_how_many
     356 * @uses bbp_get_user_reply_count() To get the users current reply count
     357 */
     358function bbp_decrement_user_reply_count( $user_id, $by_how_many = 1 ) {
     359        $count = intval( bbp_get_user_reply_count( $user_id ) );
     360        $count = $count - $by_how_many;
     361        $count = apply_filters( 'bbp_decrement_user_reply_count', $count, $user_id, $by_how_many );
     362
     363        // Reply counts can't be less than zero.
     364        if ( $count < 0 )
     365                $count = 0;
     366
     367        update_user_option( $user_id, '_bbp_reply_count', $count );
     368}
     369
     370/**
     371 * Increments by one the count of topics for an user when he creates a new topic.
     372 *
     373 * @since bbPress (rXXXX)
     374 *
     375 * @param $topic_id
     376 * @param $forum_id
     377 * @param $anonymous_data
     378 * @param $topic_author
     379 */
     380function bbp_bump_user_topic_count_on_new_topic( $topic_id, $forum_id, $anonymous_data, $topic_author ) {
     381        bbp_increment_user_topic_count( $topic_author );
     382}
     383
     384/**
     385 * Increments by one the count of topics for an user when he creates a new topic.
     386 *
     387 * @since bbPress (rXXXX)
     388 *
     389 * @param $topic_id
     390 * @param $forum_id
     391 * @param $anonymous_data
     392 * @param $topic_author
     393 */
     394function bbp_bump_user_reply_count_on_new_reply( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author ) {
     395        bbp_increment_user_reply_count( $reply_author );
     396}
     397
     398/**
     399 * Decrements by one the count of topics for an user when he creates a new topic.
     400 *
     401 * @since bbPress (rXXXX)
     402 *
     403 * @param $topic_id
     404 */
     405function bbp_dwindle_user_topic_count_on_deleted_topic( $topic_id ) {
     406        $user = bbp_get_topic_author_id( $topic_id );
     407        bbp_decrement_user_topic_count( $user );
     408}
     409
     410/**
     411 * Increments by one the count of replies for an user when he creates a new reply.
     412 *
     413 * @since bbPress (rXXXX)
     414 *
     415 * @param $reply_id
     416 *
     417 */
     418function bbp_dwindle_user_reply_count_on_deleted_reply( $reply_id ) {
     419        $user = bbp_get_reply_author_id( $reply_id );
     420        bbp_decrement_user_reply_count( $user );
     421}
     422 No newline at end of file