Skip to:
Content

bbPress.org

Ticket #1799: 1799.4.patch

File 1799.4.patch, 12.2 KB (added by thebrandonallen, 11 years ago)
  • src/includes/core/actions.php

    diff --git src/includes/core/actions.php src/includes/core/actions.php
    index f038bfc..adb8f0f 100644
    add_action( 'bbp_deleted_reply', 'bbp_update_reply_walker' ); 
    250250add_action( 'bbp_spammed_reply',   'bbp_update_reply_walker' );
    251251add_action( 'bbp_unspammed_reply', 'bbp_update_reply_walker' );
    252252
     253// Update forum topic/reply counts
     254add_action( 'bbp_new_reply',       'bbp_increase_forum_reply_count'        );
     255add_action( 'bbp_new_topic',       'bbp_increase_forum_topic_count'        );
     256add_action( 'bbp_trashed_reply',   'bbp_decrease_forum_reply_count'        );
     257add_action( 'bbp_trashed_topic',   'bbp_decrease_forum_topic_count'        );
     258add_action( 'bbp_trashed_topic',   'bbp_increase_forum_topic_count_hidden' );
     259add_action( 'bbp_untrashed_reply', 'bbp_increase_forum_reply_count'        );
     260add_action( 'bbp_untrashed_topic', 'bbp_increase_forum_topic_count'        );
     261add_action( 'bbp_untrashed_topic', 'bbp_decrease_forum_topic_count_hidden' );
     262add_action( 'bbp_spammed_reply',   'bbp_decrease_forum_reply_count'        );
     263add_action( 'bbp_spammed_topic',   'bbp_decrease_forum_topic_count'        );
     264add_action( 'bbp_spammed_topic',   'bbp_increase_forum_topic_count_hidden' );
     265add_action( 'bbp_unspammed_reply', 'bbp_increase_forum_reply_count'        );
     266add_action( 'bbp_unspammed_topic', 'bbp_increase_forum_topic_count'        );
     267add_action( 'bbp_unspammed_topic', 'bbp_decrease_forum_topic_count_hidden' );
     268
     269// Update topic reply counts
     270add_action( 'bbp_new_reply',       'bbp_increase_topic_reply_count'        );
     271add_action( 'bbp_trashed_reply',   'bbp_decrease_topic_reply_count'        );
     272add_action( 'bbp_trashed_reply',   'bbp_increase_topic_reply_count_hidden' );
     273add_action( 'bbp_untrashed_reply', 'bbp_increase_topic_reply_count'        );
     274add_action( 'bbp_untrashed_reply', 'bbp_decrease_topic_reply_count_hidden' );
     275add_action( 'bbp_spammed_reply',   'bbp_decrease_topic_reply_count'        );
     276add_action( 'bbp_spammed_reply',   'bbp_increase_topic_reply_count_hidden' );
     277add_action( 'bbp_unspammed_reply', 'bbp_increase_topic_reply_count'        );
     278add_action( 'bbp_unspammed_reply', 'bbp_decrease_topic_reply_count_hidden' );
     279
    253280// Users topic & reply counts
    254281add_action( 'bbp_new_topic',     'bbp_increase_user_topic_count' );
    255282add_action( 'bbp_new_reply',     'bbp_increase_user_reply_count' );
  • src/includes/forums/functions.php

    diff --git src/includes/forums/functions.php src/includes/forums/functions.php
    index cf77b19..f3112b1 100644
    function bbp_bump_forum_topic_count( $forum_id = 0, $difference = 1, $update_anc 
    10891089}
    10901090
    10911091/**
     1092 * Increase the total topic count of a forum by one
     1093 *
     1094 * @since bbPress ()
     1095 *
     1096 * @param int $forum_id Optional. Forum id.
     1097 * @uses bbp_get_forum_id() To get the forum id
     1098 * @uses bbp_bump_forum_topic_count() To bump forum topic count
     1099 */
     1100function bbp_increase_forum_topic_count( $forum_id = 0 ) {
     1101        if ( empty( $forum_id ) ) {
     1102                return;
     1103        }
     1104
     1105        if ( bbp_is_topic( $forum_id ) ) {
     1106                $topic_id = $forum_id;
     1107                $forum_id = bbp_get_topic_forum_id( $topic_id );
     1108
     1109                // If this is a new, unpublished, topic, increase hidden count and bail
     1110                if ( 'bbp_new_topic' === current_action() && ( ! bbp_is_topic_published( $topic_id ) && ! bbp_is_topic_closed( $topic_id ) ) ) {
     1111                        bbp_increase_forum_topic_count_hidden( $forum_id );
     1112                        return;
     1113                }
     1114        }
     1115
     1116        bbp_bump_forum_topic_count( $forum_id );
     1117}
     1118
     1119/**
     1120 * Decrease the total topic count of a forum by one
     1121 *
     1122 * @since bbPress ()
     1123 *
     1124 * @param int $forum_id Optional. Forum id.
     1125 * @uses bbp_get_forum_id() To get the forum id
     1126 * @uses bbp_bump_forum_topic_count() To bump forum topic count
     1127 */
     1128function bbp_decrease_forum_topic_count( $forum_id = 0 ) {
     1129        if ( empty( $forum_id ) ) {
     1130                return;
     1131        }
     1132
     1133        if ( bbp_is_topic( $forum_id ) ) {
     1134                $forum_id = bbp_get_topic_forum_id( $forum_id );
     1135        }
     1136
     1137        bbp_bump_forum_topic_count( $forum_id, -1 );
     1138}
     1139
     1140/**
    10921141 * Bump the total hidden topic count of a forum
    10931142 *
    10941143 * @since bbPress (r3825)
    function bbp_bump_forum_topic_count_hidden( $forum_id = 0, $difference = 1 ) { 
    11151164}
    11161165
    11171166/**
     1167 * Increase the total hidden topic count of a forum by one
     1168 *
     1169 * @since bbPress ()
     1170 *
     1171 * @param int $forum_id Optional. Forum id.
     1172 * @uses bbp_get_forum_id() To get the forum id
     1173 * @uses bbp_bump_forum_topic_count_hidden() To bump forum hidden topic count
     1174 */
     1175function bbp_increase_forum_topic_count_hidden( $forum_id = 0 ) {
     1176        if ( empty( $forum_id ) ) {
     1177                return;
     1178        }
     1179
     1180        if ( bbp_is_topic( $forum_id ) ) {
     1181                $forum_id = bbp_get_topic_forum_id( $forum_id );
     1182        }
     1183
     1184        bbp_bump_forum_topic_count_hidden( $forum_id );
     1185}
     1186
     1187/**
     1188 * Decrease the total hidden topic count of a forum by one
     1189 *
     1190 * @since bbPress ()
     1191 *
     1192 * @param int $forum_id Optional. Forum id.
     1193 * @uses bbp_get_forum_id() To get the forum id
     1194 * @uses bbp_bump_forum_topic_count_hidden() To bump forum hidden topic count
     1195 */
     1196function bbp_decrease_forum_topic_count_hidden( $forum_id = 0 ) {
     1197        if ( empty( $forum_id ) ) {
     1198                return;
     1199        }
     1200
     1201        if ( bbp_is_topic( $forum_id ) ) {
     1202                $forum_id = bbp_get_topic_forum_id( $forum_id );
     1203        }
     1204
     1205        bbp_bump_forum_topic_count_hidden( $forum_id, -1 );
     1206}
     1207
     1208/**
    11181209 * Bump the total topic count of a forum
    11191210 *
    11201211 * @since bbPress (r3825)
    function bbp_bump_forum_reply_count( $forum_id = 0, $difference = 1, $update_anc 
    11641255        return (int) apply_filters( 'bbp_bump_forum_reply_count', (int) $total_reply_count + (int) $difference, $forum_id, (int) $difference, (bool) $update_ancestors );
    11651256}
    11661257
     1258/**
     1259 * Increase the total reply count of a forum by one
     1260 *
     1261 * @since bbPress ()
     1262 *
     1263 * @param int $forum_id Optional. Forum id.
     1264 * @uses bbp_get_forum_id() To get the forum id
     1265 * @uses bbp_bump_forum_reply_count() To bump forum topic count
     1266 */
     1267function bbp_increase_forum_reply_count( $forum_id = 0 ) {
     1268        if ( empty( $forum_id ) ) {
     1269                return;
     1270        }
     1271
     1272        if ( bbp_is_reply( $forum_id ) ) {
     1273                $reply_id = $forum_id;
     1274                $forum_id = bbp_get_reply_forum_id( $reply_id );
     1275
     1276                // Don't update if this is a new, unpublished, reply
     1277                if ( 'bbp_new_reply' === current_action() && ! bbp_is_reply_published( $reply_id ) ) {
     1278                        return;
     1279                }
     1280        }
     1281
     1282        bbp_bump_forum_reply_count( $forum_id, 1 );
     1283}
     1284
     1285/**
     1286 * Decrease the total reply count of a forum by one
     1287 *
     1288 * @since bbPress ()
     1289 *
     1290 * @param int $forum_id Optional. Forum id.
     1291 * @uses bbp_get_forum_id() To get the forum id
     1292 * @uses bbp_bump_forum_reply_count() To bump forum topic count
     1293 */
     1294function bbp_decrease_forum_reply_count( $forum_id = 0 ) {
     1295        if ( empty( $forum_id ) ) {
     1296                return;
     1297        }
     1298
     1299        if ( bbp_is_reply( $forum_id ) ) {
     1300                $forum_id = bbp_get_reply_forum_id( $forum_id );
     1301        }
     1302
     1303        bbp_bump_forum_reply_count( $forum_id, -1 );
     1304}
     1305
    11671306/** Forum Updaters ************************************************************/
    11681307
    11691308/**
    function bbp_update_forum( $args = '' ) { 
    16171756        }
    16181757
    16191758        // Counts
    1620         bbp_update_forum_subforum_count    ( $r['forum_id'] );
    1621         bbp_update_forum_reply_count       ( $r['forum_id'] );
    1622         bbp_update_forum_topic_count       ( $r['forum_id'] );
    1623         bbp_update_forum_topic_count_hidden( $r['forum_id'] );
     1759        bbp_update_forum_subforum_count( $r['forum_id'] );
     1760
     1761        // Only update topic count if we're deleting a topic, or in the dashboard
     1762        if ( in_array( current_action(), array( 'bbp_deleted_topic', 'save_post' ) ) ) {
     1763                bbp_update_forum_reply_count(        $r['forum_id'] );
     1764                bbp_update_forum_topic_count(        $r['forum_id'] );
     1765                bbp_update_forum_topic_count_hidden( $r['forum_id'] );
     1766        }
    16241767
    16251768        // Update the parent forum if one was passed
    16261769        if ( !empty( $r['post_parent'] ) && is_numeric( $r['post_parent'] ) ) {
  • src/includes/replies/functions.php

    diff --git src/includes/replies/functions.php src/includes/replies/functions.php
    index ad32198..2144fb1 100644
    function bbp_update_reply_walker( $reply_id, $last_active_time = '', $forum_id = 
    984984                                }
    985985
    986986                                // Counts
    987                                 bbp_update_topic_voice_count       ( $ancestor );
    988                                 bbp_update_topic_reply_count       ( $ancestor );
    989                                 bbp_update_topic_reply_count_hidden( $ancestor );
     987                                bbp_update_topic_voice_count( $ancestor );
     988
     989                                // Only update reply count if we're deleting a reply, or in the dashboard
     990                                if ( in_array( current_action(), array( 'bbp_deleted_reply', 'save_post' ) ) ) {
     991                                        bbp_update_topic_reply_count(        $ancestor );
     992                                        bbp_update_topic_reply_count_hidden( $ancestor );
     993                                }
    990994
    991995                        // Forum meta relating to most recent topic
    992996                        } elseif ( bbp_is_forum( $ancestor ) ) {
    function bbp_update_reply_walker( $reply_id, $last_active_time = '', $forum_id = 
    10101014                                }
    10111015
    10121016                                // Counts
    1013                                 bbp_update_forum_reply_count( $ancestor );
     1017                                // Only update reply count if we're deleting a reply, or in the dashboard
     1018                                if ( in_array( current_action(), array( 'bbp_deleted_reply', 'save_post' ) ) ) {
     1019                                        bbp_update_forum_reply_count( $ancestor );
     1020                                }
    10141021                        }
    10151022                }
    10161023        }
  • src/includes/topics/functions.php

    diff --git src/includes/topics/functions.php src/includes/topics/functions.php
    index fd278f6..530bc50 100644
    function bbp_bump_topic_reply_count( $topic_id = 0, $difference = 1 ) { 
    23472347}
    23482348
    23492349/**
     2350 * Increase the total reply count of a topic by one
     2351 *
     2352 * @since bbPress ()
     2353 *
     2354 * @param int $topic_id Optional. Forum id.
     2355 * @uses bbp_is_reply() To check if the passed topic id is a reply
     2356 * @uses bbp_get_reply_topic_id() To get the topic id
     2357 * @uses bbp_bump_topic_reply_count() To bump topic reply count
     2358 */
     2359function bbp_increase_topic_reply_count( $topic_id = 0 ) {
     2360        if ( empty( $topic_id ) ) {
     2361                return;
     2362        }
     2363
     2364        if ( bbp_is_reply( $topic_id ) ) {
     2365                $reply_id = $topic_id;
     2366                $topic_id = bbp_get_reply_topic_id( $reply_id );
     2367
     2368                // If this is a new, unpublished, reply, update hidden count and bail
     2369                if ( 'bbp_new_reply' === current_action() && ! bbp_is_reply_published( $reply_id ) ) {
     2370                        bbp_increase_topic_reply_count_hidden( $topic_id );
     2371                        return;
     2372                }
     2373        }
     2374
     2375        bbp_bump_topic_reply_count( $topic_id );
     2376}
     2377
     2378/**
     2379 * Decrease the total reply count of a topic by one
     2380 *
     2381 * @since bbPress ()
     2382 *
     2383 * @param int $topic_id Optional. Topic id.
     2384 * @uses bbp_is_reply() To check if the passed topic id is a reply
     2385 * @uses bbp_get_reply_topic_id() To get the topic id
     2386 * @uses bbp_bump_topic_reply_count() To bump topic reply count
     2387 */
     2388function bbp_decrease_topic_reply_count( $topic_id = 0 ) {
     2389        if ( empty( $topic_id ) ) {
     2390                return;
     2391        }
     2392
     2393        if ( bbp_is_reply( $topic_id ) ) {
     2394                $topic_id = bbp_get_reply_topic_id( $topic_id );
     2395        }
     2396
     2397        bbp_bump_topic_reply_count( $topic_id, -1 );
     2398}
     2399
     2400/**
    23502401 * Bump the total hidden reply count of a topic
    23512402 *
    23522403 * @since bbPress (r3825)
    function bbp_bump_topic_reply_count_hidden( $topic_id = 0, $difference = 1 ) { 
    23722423        return (int) apply_filters( 'bbp_bump_topic_reply_count_hidden', (int) $new_count, $topic_id, (int) $difference );
    23732424}
    23742425
     2426/**
     2427 * Increase the total hidden reply count of a topic by one
     2428 *
     2429 * @since bbPress ()
     2430 *
     2431 * @param int $topic_id Optional. Topic id.
     2432 * @uses bbp_is_reply() To check if the passed topic id is a reply
     2433 * @uses bbp_get_reply_topic_id() To get the topic id
     2434 * @uses bbp_bump_topic_reply_count_hidden() To bump topic hidden reply count
     2435 */
     2436function bbp_increase_topic_reply_count_hidden( $topic_id = 0 ) {
     2437        if ( empty( $topic_id ) ) {
     2438                return;
     2439        }
     2440
     2441        if ( bbp_is_reply( $topic_id ) ) {
     2442                $topic_id = bbp_get_reply_topic_id( $topic_id );
     2443        }
     2444
     2445        bbp_bump_topic_reply_count_hidden( $topic_id );
     2446}
     2447
     2448/**
     2449 * Decrease the total hidden reply count of a topic by one
     2450 *
     2451 * @since bbPress ()
     2452 *
     2453 * @param int $topic_id Optional. Topic id.
     2454 * @uses bbp_is_reply() To check if the passed topic id is a reply
     2455 * @uses bbp_get_reply_topic_id() To get the topic id
     2456 * @uses bbp_bump_topic_reply_count_hidden() To bump topic hidden reply count
     2457 */
     2458function bbp_decrease_topic_reply_count_hidden( $topic_id = 0 ) {
     2459        if ( empty( $topic_id ) ) {
     2460                return;
     2461        }
     2462
     2463        if ( bbp_is_reply( $topic_id ) ) {
     2464                $topic_id = bbp_get_reply_topic_id( $topic_id );
     2465        }
     2466
     2467        bbp_bump_topic_reply_count_hidden( $topic_id, -1 );
     2468}
     2469
    23752470/** Topic Updaters ************************************************************/
    23762471
    23772472/**