Skip to:
Content

bbPress.org

Ticket #1694: 1694.diff

File 1694.diff, 4.8 KB (added by MZAWeb, 12 years ago)
  • includes/core/actions.php

     
    241241add_action( 'bbp_spammed_reply',   'bbp_update_reply_walker' );
    242242add_action( 'bbp_unspammed_reply', 'bbp_update_reply_walker' );
    243243
     244// Users counts
     245add_action( 'bbp_new_topic',    'bbp_bump_user_topic_count_on_new_topic',        10, 4 );
     246add_action( 'bbp_new_reply',    'bbp_bump_user_reply_count_on_new_reply',        10, 5 );
     247add_action( 'bbp_delete_topic', 'bbp_dwindle_user_topic_count_on_deleted_topic', 10    );
     248add_action( 'bbp_delete_reply', 'bbp_dwindle_user_reply_count_on_deleted_reply', 10    );
     249
     250
    244251// User status
    245252// @todo make these sub-actions
    246253add_action( 'make_ham_user',  'bbp_make_ham_user'  );
  • includes/users/options.php

     
    288288
    289289                return apply_filters( 'bbp_get_user_last_posted', $time, $user_id );
    290290        }
     291
     292
     293/**
     294 * Increments the count of topics created by an user
     295 *
     296 * @param int $user_id
     297 * @param int $by_how_many
     298 *
     299 */
     300function bbp_increment_user_topic_count( $user_id, $by_how_many = 1 ) {
     301        $count = intval( bbp_get_user_topic_count( $user_id ) );
     302        $count = $count + $by_how_many;
     303        $count = apply_filters( 'bbp_increment_user_topic_count', $count, $user_id, $by_how_many );
     304        update_user_meta( $user_id, '_bbp_topic_count', $count );
     305}
     306
     307/**
     308 * Increments the count of replies created by an user
     309 *
     310 * @param int $user_id
     311 * @param int $by_how_many
     312 */
     313function bbp_increment_user_reply_count( $user_id, $by_how_many = 1 ) {
     314        $count = intval( bbp_get_user_reply_count( $user_id ) );
     315        $count = $count + $by_how_many;
     316        $count = apply_filters( 'bbp_increment_user_reply_count', $count, $user_id, $by_how_many );
     317        update_user_meta( $user_id, '_bbp_reply_count', $count );
     318}
     319
     320/**
     321 * Decrements the count of topics created by an user
     322 *
     323 * @param int $user_id
     324 * @param int $by_how_many
     325 */
     326function bbp_decrement_user_topic_count( $user_id, $by_how_many = 1 ) {
     327
     328        $count = intval( bbp_get_user_topic_count( $user_id ) );
     329
     330        $count = $count - $by_how_many;
     331        $count = apply_filters( 'bbp_decrement_user_topic_count', $count, $user_id, $by_how_many );
     332
     333        // Topic count can't be less than zero.
     334        if ( $count < 0 )
     335                $count = 0;
     336
     337        update_user_meta( $user_id, '_bbp_topic_count', $count );
     338}
     339
     340/**
     341 * Decrements by one the count of replies created by an user
     342 *
     343 * @param int $user_id
     344 * @param int $by_how_many
     345 */
     346function bbp_decrement_user_reply_count( $user_id, $by_how_many = 1 ) {
     347        $count = intval( bbp_get_user_reply_count( $user_id ) );
     348        $count = $count - $by_how_many;
     349        $count = apply_filters( 'bbp_decrement_user_reply_count', $count, $user_id, $by_how_many );
     350
     351        // Reply counts can't be less than zero.
     352        if ( $count < 0 )
     353                $count = 0;
     354
     355        update_user_meta( $user_id, '_bbp_reply_count', $count );
     356}
     357
     358/**
     359 * Increments by one the count of topics for an user when he creates a new topic
     360 *
     361 * @param $topic_id
     362 * @param $forum_id
     363 * @param $anonymous_data
     364 * @param $topic_author
     365 */
     366function bbp_bump_user_topic_count_on_new_topic( $topic_id, $forum_id, $anonymous_data, $topic_author ) {
     367        bbp_increment_user_topic_count( $topic_author );
     368}
     369
     370/**
     371 * Increments by one the count of topics for an user when he creates a new topic
     372 *
     373 * @param $topic_id
     374 * @param $forum_id
     375 * @param $anonymous_data
     376 * @param $topic_author
     377 */
     378function bbp_bump_user_reply_count_on_new_reply( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author ) {
     379        bbp_increment_user_reply_count( $reply_author );
     380}
     381
     382/**
     383 * Decrements by one the count of topics for an user when he creates a new topic
     384 *
     385 * @param $topic_id
     386 */
     387function bbp_dwindle_user_topic_count_on_deleted_topic( $topic_id ) {
     388        $user = bbp_get_topic_author_id( $topic_id );
     389        bbp_decrement_user_topic_count( $user );
     390}
     391
     392/**
     393 * Increments by one the count of replies for an user when he creates a new reply
     394 *
     395 * @param $reply_id
     396
     397 */
     398function bbp_dwindle_user_reply_count_on_deleted_reply( $reply_id ) {
     399        $user = bbp_get_reply_author_id( $reply_id );
     400        bbp_decrement_user_reply_count( $user );
     401}
     402 No newline at end of file
  • includes/topics/functions.php

     
    29402940                'post_status'      => 'any',
    29412941                'post_parent'      => $topic_id,
    29422942                'posts_per_page'   => -1,
    2943                 'nopaging'         => true,
    2944                 'fields'           => 'id=>parent'
     2943                'nopaging'         => true
    29452944        ) ) ) {
    29462945                foreach ( $replies->posts as $reply ) {
    29472946                        wp_delete_post( $reply->ID, true );
     2947
    29482948                }
    29492949
    29502950                // Reset the $post global