Ticket #1799: 1799.10.patch
File 1799.10.patch, 33.5 KB (added by , 9 years ago) |
---|
-
src/includes/core/actions.php
255 255 add_action( 'bbp_approved_reply', 'bbp_update_reply_walker' ); 256 256 add_action( 'bbp_unapproved_reply', 'bbp_update_reply_walker' ); 257 257 258 // Users topic & reply counts 258 // Update forum topic/reply counts. 259 add_action( 'bbp_new_reply', 'bbp_increase_forum_reply_count' ); 260 add_action( 'bbp_new_topic', 'bbp_increase_forum_topic_count' ); 261 add_action( 'bbp_trashed_reply', 'bbp_decrease_forum_reply_count' ); 262 add_action( 'bbp_trashed_topic', 'bbp_decrease_forum_topic_count' ); 263 add_action( 'bbp_trashed_topic', 'bbp_increase_forum_topic_count_hidden' ); 264 add_action( 'bbp_untrashed_reply', 'bbp_increase_forum_reply_count' ); 265 add_action( 'bbp_untrashed_topic', 'bbp_increase_forum_topic_count' ); 266 add_action( 'bbp_untrashed_topic', 'bbp_decrease_forum_topic_count_hidden' ); 267 add_action( 'bbp_spammed_reply', 'bbp_decrease_forum_reply_count' ); 268 add_action( 'bbp_spammed_topic', 'bbp_decrease_forum_topic_count' ); 269 add_action( 'bbp_spammed_topic', 'bbp_increase_forum_topic_count_hidden' ); 270 add_action( 'bbp_unspammed_reply', 'bbp_increase_forum_reply_count' ); 271 add_action( 'bbp_unspammed_topic', 'bbp_increase_forum_topic_count' ); 272 add_action( 'bbp_unspammed_topic', 'bbp_decrease_forum_topic_count_hidden' ); 273 add_action( 'bbp_approved_reply', 'bbp_increase_forum_reply_count' ); 274 add_action( 'bbp_approved_topic', 'bbp_increase_forum_topic_count' ); 275 add_action( 'bbp_approved_topic', 'bbp_decrease_forum_topic_count_hidden' ); 276 add_action( 'bbp_unapproved_reply', 'bbp_decrease_forum_reply_count' ); 277 add_action( 'bbp_unapproved_topic', 'bbp_decrease_forum_topic_count' ); 278 add_action( 'bbp_unapproved_topic', 'bbp_increase_forum_topic_count_hidden' ); 279 280 // Update forum reply counts for approved/unapproved topics. 281 add_action( 'bbp_approved_topic', 'bbp_approved_unapproved_topic_update_forum_reply_count' ); 282 add_action( 'bbp_unapproved_topic', 'bbp_approved_unapproved_topic_update_forum_reply_count' ); 283 284 // Update topic reply counts. 285 add_action( 'bbp_new_reply', 'bbp_increase_topic_reply_count' ); 286 add_action( 'bbp_trashed_reply', 'bbp_decrease_topic_reply_count' ); 287 add_action( 'bbp_trashed_reply', 'bbp_increase_topic_reply_count_hidden' ); 288 add_action( 'bbp_untrashed_reply', 'bbp_increase_topic_reply_count' ); 289 add_action( 'bbp_untrashed_reply', 'bbp_decrease_topic_reply_count_hidden' ); 290 add_action( 'bbp_spammed_reply', 'bbp_decrease_topic_reply_count' ); 291 add_action( 'bbp_spammed_reply', 'bbp_increase_topic_reply_count_hidden' ); 292 add_action( 'bbp_unspammed_reply', 'bbp_increase_topic_reply_count' ); 293 add_action( 'bbp_unspammed_reply', 'bbp_decrease_topic_reply_count_hidden' ); 294 add_action( 'bbp_approved_reply', 'bbp_increase_topic_reply_count' ); 295 add_action( 'bbp_approved_reply', 'bbp_decrease_topic_reply_count_hidden' ); 296 add_action( 'bbp_unapproved_reply', 'bbp_decrease_topic_reply_count' ); 297 add_action( 'bbp_unapproved_reply', 'bbp_increase_topic_reply_count_hidden' ); 298 299 // Users topic & reply counts. 259 300 add_action( 'bbp_new_topic', 'bbp_increase_user_topic_count' ); 260 301 add_action( 'bbp_new_reply', 'bbp_increase_user_reply_count' ); 261 302 add_action( 'bbp_untrash_topic', 'bbp_increase_user_topic_count' ); … … 267 308 add_action( 'bbp_spam_topic', 'bbp_decrease_user_topic_count' ); 268 309 add_action( 'bbp_spam_reply', 'bbp_decrease_user_reply_count' ); 269 310 311 // Insert forum/topic/reply counts. 312 add_action( 'bbp_insert_topic', 'bbp_insert_topic_update_counts', 10, 2 ); 313 add_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10, 3 ); 314 270 315 // Topic status transition helpers for replies 271 316 add_action( 'bbp_trash_topic', 'bbp_trash_topic_replies' ); 272 317 add_action( 'bbp_untrash_topic', 'bbp_untrash_topic_replies' ); -
src/includes/forums/functions.php
73 73 'forum_id' => $forum_id, 74 74 ) ); 75 75 76 /** 77 * Fires after forum has been inserted via `bbp_insert_forum`. 78 * 79 * @since 2.6.0 bbPress (rXXXX) 80 * 81 * @param int $forum_id The forum id. 82 */ 83 do_action( 'bbp_insert_forum', (int) $forum_id ); 84 76 85 // Return new forum ID 77 86 return $forum_id; 78 87 } … … 1141 1150 if ( ! empty( $ancestors ) ) { 1142 1151 foreach ( (array) $ancestors as $parent_forum_id ) { 1143 1152 1144 // Get forum counts 1145 $parent_topic_count = bbp_get_forum_topic_count( $parent_forum_id, false, true ); 1153 // Only update topic count when an ancestor is not a category. 1154 if ( ! bbp_is_forum_category( $parent_forum_id ) ) { 1155 1156 $parent_topic_count = bbp_get_forum_topic_count( $parent_forum_id, false, true ); 1157 update_post_meta( $parent_forum_id, '_bbp_topic_count', (int) ( $parent_topic_count + $difference ) ); 1158 } 1159 1160 // Update the total topic count. 1146 1161 $parent_total_topic_count = bbp_get_forum_topic_count( $parent_forum_id, true, true ); 1147 1148 // Update counts1149 update_post_meta( $parent_forum_id, '_bbp_topic_count', (int) ( $parent_topic_count + $difference ) );1150 1162 update_post_meta( $parent_forum_id, '_bbp_total_topic_count', (int) ( $parent_total_topic_count + $difference ) ); 1151 1163 } 1152 1164 } … … 1158 1170 } 1159 1171 1160 1172 /** 1173 * Increase the total topic count of a forum by one. 1174 * 1175 * @since 2.6.0 bbPress (rXXXX) 1176 * 1177 * @param int $forum_id The forum id. 1178 * 1179 * @uses bbp_get_forum_id() To get the forum id. 1180 * @uses bbp_bump_forum_topic_count() To bump forum topic count. 1181 * 1182 * @return void 1183 */ 1184 function bbp_increase_forum_topic_count( $forum_id = 0 ) { 1185 1186 // Bail early if no id is passed. 1187 if ( empty( $forum_id ) ) { 1188 return; 1189 } 1190 1191 // If it's a topic, get the forum id. 1192 if ( bbp_is_topic( $forum_id ) ) { 1193 $topic_id = $forum_id; 1194 $forum_id = bbp_get_topic_forum_id( $topic_id ); 1195 1196 // If this is a new, unpublished, topic, increase hidden count and bail. 1197 if ( 'bbp_new_topic' === current_filter() && ( ! bbp_is_topic_published( $topic_id ) && ! bbp_is_topic_closed( $topic_id ) ) ) { 1198 bbp_increase_forum_topic_count_hidden( $forum_id ); 1199 return; 1200 } 1201 } 1202 1203 bbp_bump_forum_topic_count( $forum_id ); 1204 } 1205 1206 /** 1207 * Decrease the total topic count of a forum by one. 1208 * 1209 * @since 2.6.0 bbPress (rXXXX) 1210 * 1211 * @param int $forum_id The forum id. 1212 * 1213 * @uses bbp_get_forum_id() To get the forum id. 1214 * @uses bbp_bump_forum_topic_count() To bump forum topic count. 1215 * 1216 * @return void 1217 */ 1218 function bbp_decrease_forum_topic_count( $forum_id = 0 ) { 1219 1220 // Bail early if no id is passed. 1221 if ( empty( $forum_id ) ) { 1222 return; 1223 } 1224 1225 // If it's a topic, get the forum id. 1226 if ( bbp_is_topic( $forum_id ) ) { 1227 $forum_id = bbp_get_topic_forum_id( $forum_id ); 1228 } 1229 1230 bbp_bump_forum_topic_count( $forum_id, -1 ); 1231 } 1232 1233 /** 1161 1234 * Bump the total hidden topic count of a forum 1162 1235 * 1163 1236 * @since 2.1.0 bbPress (r3825) … … 1191 1264 } 1192 1265 1193 1266 /** 1267 * Increase the total hidden topic count of a forum by one. 1268 * 1269 * @since 2.6.0 bbPress (rXXXX) 1270 * 1271 * @param int $forum_id The forum id. 1272 * 1273 * @uses bbp_get_forum_id() To get the forum id. 1274 * @uses bbp_bump_forum_topic_count_hidden() To bump forum hidden topic count. 1275 * 1276 * @return void 1277 */ 1278 function bbp_increase_forum_topic_count_hidden( $forum_id = 0 ) { 1279 1280 // Bail early if no id is passed. 1281 if ( empty( $forum_id ) ) { 1282 return; 1283 } 1284 1285 // If it's a topic, get the forum id. 1286 if ( bbp_is_topic( $forum_id ) ) { 1287 $forum_id = bbp_get_topic_forum_id( $forum_id ); 1288 } 1289 1290 bbp_bump_forum_topic_count_hidden( $forum_id ); 1291 } 1292 1293 /** 1294 * Decrease the total hidden topic count of a forum by one. 1295 * 1296 * @since 2.6.0 bbPress (rXXXX) 1297 * 1298 * @param int $forum_id The forum id. 1299 * 1300 * @uses bbp_get_forum_id() To get the forum id. 1301 * @uses bbp_bump_forum_topic_count_hidden() To bump forum hidden topic count. 1302 * 1303 * @return void 1304 */ 1305 function bbp_decrease_forum_topic_count_hidden( $forum_id = 0 ) { 1306 1307 // Bail early if no id is passed. 1308 if ( empty( $forum_id ) ) { 1309 return; 1310 } 1311 1312 // If it's a topic, get the forum id. 1313 if ( bbp_is_topic( $forum_id ) ) { 1314 $forum_id = bbp_get_topic_forum_id( $forum_id ); 1315 } 1316 1317 bbp_bump_forum_topic_count_hidden( $forum_id, -1 ); 1318 } 1319 1320 /** 1194 1321 * Bump the total topic count of a forum 1195 1322 * 1196 1323 * @since 2.1.0 bbPress (r3825) … … 1232 1359 if ( ! empty( $ancestors ) ) { 1233 1360 foreach ( (array) $ancestors as $parent_forum_id ) { 1234 1361 1235 // Get forum counts 1236 $parent_topic_count = bbp_get_forum_reply_count( $parent_forum_id, false, true ); 1362 // Only update reply count when an ancestor is not a category. 1363 if ( ! bbp_is_forum_category( $parent_forum_id ) ) { 1364 1365 $parent_reply_count = bbp_get_forum_reply_count( $parent_forum_id, false, true ); 1366 update_post_meta( $parent_forum_id, '_bbp_reply_count', (int) ( $parent_reply_count + $difference ) ); 1367 } 1368 1369 // Update the total reply count. 1237 1370 $parent_total_reply_count = bbp_get_forum_reply_count( $parent_forum_id, true, true ); 1238 1239 // Update counts1240 update_post_meta( $parent_forum_id, '_bbp_reply_count', (int) ( $parent_topic_count + $difference ) );1241 1371 update_post_meta( $parent_forum_id, '_bbp_total_reply_count', (int) ( $parent_total_reply_count + $difference ) ); 1242 1372 } 1243 1373 } … … 1248 1378 return (int) apply_filters( 'bbp_bump_forum_reply_count', $forum_reply_count, $forum_id, $difference, $update_ancestors ); 1249 1379 } 1250 1380 1381 /** 1382 * Increase the total reply count of a forum by one. 1383 * 1384 * @since 2.6.0 bbPress (rXXXX) 1385 * 1386 * @param int $forum_id The forum id. 1387 * 1388 * @uses bbp_get_forum_id() To get the forum id. 1389 * @uses bbp_bump_forum_reply_count() To bump forum topic count. 1390 * 1391 * @return void 1392 */ 1393 function bbp_increase_forum_reply_count( $forum_id = 0 ) { 1394 1395 // Bail early if no id is passed. 1396 if ( empty( $forum_id ) ) { 1397 return; 1398 } 1399 1400 // If it's a reply, get the forum id. 1401 if ( bbp_is_reply( $forum_id ) ) { 1402 $reply_id = $forum_id; 1403 $forum_id = bbp_get_reply_forum_id( $reply_id ); 1404 1405 // Don't update if this is a new, unpublished, reply. 1406 if ( 'bbp_new_reply' === current_filter() && ! bbp_is_reply_published( $reply_id ) ) { 1407 return; 1408 } 1409 } 1410 1411 bbp_bump_forum_reply_count( $forum_id ); 1412 } 1413 1414 /** 1415 * Decrease the total reply count of a forum by one. 1416 * 1417 * @since 2.6.0 bbPress (rXXXX) 1418 * 1419 * @param int $forum_id The forum id. 1420 * 1421 * @uses bbp_get_forum_id() To get the forum id. 1422 * @uses bbp_bump_forum_reply_count() To bump forum topic count. 1423 * 1424 * @return void 1425 */ 1426 function bbp_decrease_forum_reply_count( $forum_id = 0 ) { 1427 1428 // Bail early if no id is passed. 1429 if ( empty( $forum_id ) ) { 1430 return; 1431 } 1432 1433 // If it's a reply, get the forum id. 1434 if ( bbp_is_reply( $forum_id ) ) { 1435 $forum_id = bbp_get_reply_forum_id( $forum_id ); 1436 } 1437 1438 bbp_bump_forum_reply_count( $forum_id, -1 ); 1439 } 1440 1441 /** 1442 * Update forum reply counts when a topic is approved or unapproved. 1443 * 1444 * @since 2.6.0 bbPress (rXXXX) 1445 * 1446 * @param int $topic_id The topic id. 1447 * 1448 * @uses bbp_get_reply_post_type() To get the reply post type. 1449 * @uses bbp_get_public_child_ids() To get the topic's public child ids. 1450 * @uses bbp_get_topic_forum_id() To get the topic's forum id. 1451 * @uses bbp_bump_forum_reply_count() To bump the forum reply count. 1452 * 1453 * @return void 1454 */ 1455 function bbp_approved_unapproved_topic_update_forum_reply_count( $topic_id = 0 ) { 1456 1457 // Bail early if we don't have a topic id. 1458 if ( empty( $topic_id ) ) { 1459 return; 1460 } 1461 1462 // Get the topic's replies. 1463 $replies = bbp_get_public_child_ids( $topic_id, bbp_get_reply_post_type() ); 1464 $count = count( $replies ); 1465 1466 // If we're unapproving, set count to negative. 1467 if ( 'bbp_unapproved_topic' === current_filter() ) { 1468 $count = -$count; 1469 } 1470 1471 // Update counts. 1472 bbp_bump_forum_reply_count( bbp_get_topic_forum_id( $topic_id ), $count ); 1473 } 1474 1251 1475 /** Forum Updaters ************************************************************/ 1252 1476 1253 1477 /** … … 1732 1956 } 1733 1957 1734 1958 // Counts 1735 bbp_update_forum_subforum_count ( $r['forum_id'] ); 1736 bbp_update_forum_reply_count ( $r['forum_id'] ); 1737 bbp_update_forum_topic_count ( $r['forum_id'] ); 1738 bbp_update_forum_topic_count_hidden( $r['forum_id'] ); 1959 bbp_update_forum_subforum_count( $r['forum_id'] ); 1739 1960 1961 // Only update topic count if we're deleting a topic, or in the dashboard. 1962 if ( in_array( current_filter(), array( 'bbp_deleted_topic', 'save_post' ), true ) ) { 1963 bbp_update_forum_reply_count( $r['forum_id'] ); 1964 bbp_update_forum_topic_count( $r['forum_id'] ); 1965 bbp_update_forum_topic_count_hidden( $r['forum_id'] ); 1966 } 1967 1740 1968 // Update the parent forum if one was passed 1741 1969 if ( ! empty( $r['post_parent'] ) && is_numeric( $r['post_parent'] ) ) { 1742 1970 bbp_update_forum( array( -
src/includes/replies/functions.php
65 65 // Update the reply and hierarchy 66 66 bbp_update_reply( $reply_id, $reply_meta['topic_id'], $reply_meta['forum_id'], array(), $reply_data['post_author'], false, $reply_meta['reply_to'] ); 67 67 68 /** 69 * Fires after reply has been inserted via `bbp_insert_reply`. 70 * 71 * @since 2.6.0 bbPress (rXXXX) 72 * 73 * @param int $reply_id The reply id. 74 * @param int $topic_id The topic id. 75 * @param int $forum_id The forum id. 76 */ 77 do_action( 'bbp_insert_reply', (int) $reply_id, (int) $reply_meta['topic_id'], (int) $reply_meta['forum_id'] ); 78 68 79 // Return new reply ID 69 80 return $reply_id; 70 81 } 71 82 83 /** 84 * Update counts after a reply is inserted via `bbp_insert_reply`. 85 * 86 * @since 2.6.0 bbPress (rXXXX) 87 * 88 * @param int $reply_id The reply id. 89 * @param int $topic_id The topic id. 90 * @param int $forum_id The forum id. 91 * 92 * @uses bbp_get_reply_status() To get the reply status. 93 * @uses bbp_get_public_status_id() To get the public status id. 94 * @uses bbp_increase_topic_reply_count() To bump the reply's topic reply count by 1. 95 * @uses bbp_increase_forum_reply_count() To bump the reply's forum reply count by 1. 96 * @uses bbp_increase_topic_reply_count_hidden() To bump the reply's topic reply 97 * hidden count by 1. 98 * 99 * @return void 100 */ 101 function bbp_insert_reply_update_counts( $reply_id = 0, $topic_id = 0, $forum_id = 0 ) { 102 103 // If the reply is public, update the forum/topic reply counts. 104 if ( bbp_get_reply_status( $reply_id ) === bbp_get_public_status_id() ) { 105 bbp_increase_topic_reply_count( $topic_id ); 106 bbp_increase_forum_reply_count( $forum_id ); 107 108 // If the reply isn't public only update the topic reply hidden count. 109 } else { 110 bbp_increase_topic_reply_count_hidden( $topic_id ); 111 } 112 } 113 72 114 /** Post Form Handlers ********************************************************/ 73 115 74 116 /** … … 977 1019 bbp_update_topic_last_active_time( $ancestor, $topic_last_active_time ); 978 1020 979 1021 // Counts 980 bbp_update_topic_voice_count ( $ancestor ); 981 bbp_update_topic_reply_count ( $ancestor ); 982 bbp_update_topic_reply_count_hidden( $ancestor ); 1022 bbp_update_topic_voice_count( $ancestor ); 983 1023 1024 // Only update reply count if we're deleting a reply, or in the dashboard. 1025 if ( in_array( current_filter(), array( 'bbp_deleted_reply', 'save_post' ), true ) ) { 1026 bbp_update_topic_reply_count( $ancestor ); 1027 bbp_update_topic_reply_count_hidden( $ancestor ); 1028 } 1029 984 1030 // Forum meta relating to most recent topic 985 1031 } elseif ( bbp_is_forum( $ancestor ) ) { 986 1032 … … 1003 1049 } 1004 1050 1005 1051 // Counts 1006 bbp_update_forum_reply_count( $ancestor ); 1052 // Only update reply count if we're deleting a reply, or in the dashboard. 1053 if ( in_array( current_filter(), array( 'bbp_deleted_reply', 'save_post' ), true ) ) { 1054 bbp_update_forum_reply_count( $ancestor ); 1055 } 1007 1056 } 1008 1057 } 1009 1058 } -
src/includes/topics/functions.php
70 70 // Update the topic and hierarchy 71 71 bbp_update_topic( $topic_id, $topic_meta['forum_id'], array(), $topic_data['post_author'], false ); 72 72 73 /** 74 * Fires after topic has been inserted via `bbp_insert_topic`. 75 * 76 * @since 2.6.0 bbPress (rXXXX) 77 * 78 * @param int $topic_id The topic id. 79 * @param int $forum_id The forum id. 80 */ 81 do_action( 'bbp_insert_topic', (int) $topic_id, (int) $topic_meta['forum_id'] ); 82 73 83 // Return new topic ID 74 84 return $topic_id; 75 85 } … … 1022 1032 * @uses update_post_meta() To update the old forum sticky meta 1023 1033 * @uses bbp_stick_topic() To stick the topic in the new forum 1024 1034 * @uses bbp_get_reply_post_type() To get the reply post type 1025 * @uses bbp_get_all_child_ids() To get the public child ids 1035 * @uses bbp_get_all_child_ids() To get the all child ids. 1036 * @uses bbp_get_public_child_ids() To get the all child ids. 1037 * @uses get_post_field() To get the topic's post status. 1038 * @uses bbp_get_public_status_id() To get the public status id. 1039 * @uses bbp_decrease_forum_topic_count() To bump the forum topic count by -1. 1040 * @uses bbp_bump_forum_reply_count() To bump the forum reply count. 1041 * @uses bbp_increase_forum_topic_count() To bump the forum topic count by 1. 1042 * @uses bbp_decrease_forum_topic_count_hidden() To bump the forum topic hidden count by -1. 1043 * @uses bbp_increase_forum_topic_count_hidden() To bump the forum topic hidden count by 1. 1026 1044 * @uses bbp_update_reply_forum_id() To update the reply forum id 1027 1045 * @uses bbp_update_topic_forum_id() To update the topic forum id 1028 1046 * @uses get_post_ancestors() To get the topic's ancestors … … 1100 1118 // Get topic ancestors 1101 1119 $old_forum_ancestors = array_values( array_unique( array_merge( array( $old_forum_id ), (array) get_post_ancestors( $old_forum_id ) ) ) ); 1102 1120 1121 // Get reply count. 1122 $public_reply_count = count( bbp_get_public_child_ids( $topic_id, bbp_get_reply_post_type() ) ); 1123 1124 // Topic status. 1125 $topic_status = get_post_field( 'post_status', $topic_id ); 1126 1127 // Update old/new forum counts. 1128 if ( $topic_status === bbp_get_public_status_id() ) { 1129 1130 // Update old forum counts. 1131 bbp_decrease_forum_topic_count( $old_forum_id ); 1132 bbp_bump_forum_reply_count( $old_forum_id, -$public_reply_count ); 1133 1134 // Update new forum counts. 1135 bbp_increase_forum_topic_count( $new_forum_id ); 1136 bbp_bump_forum_reply_count( $new_forum_id, $public_reply_count ); 1137 } else { 1138 1139 // Update old forum counts. 1140 bbp_decrease_forum_topic_count_hidden( $old_forum_id ); 1141 1142 // Update new forum counts. 1143 bbp_increase_forum_topic_count_hidden( $new_forum_id ); 1144 } 1145 1103 1146 // Loop through ancestors and update them 1104 1147 if ( ! empty( $old_forum_ancestors ) ) { 1105 1148 foreach ( $old_forum_ancestors as $ancestor ) { … … 2364 2407 } 2365 2408 2366 2409 /** 2410 * Increase the total reply count of a topic by one. 2411 * 2412 * @since 2.6.0 bbPress (rXXXX) 2413 * 2414 * @param int $topic_id The topic id. 2415 * 2416 * @uses bbp_is_reply() To check if the passed topic id is a reply. 2417 * @uses bbp_get_reply_topic_id() To get the topic id. 2418 * @uses bbp_bump_topic_reply_count() To bump topic reply count. 2419 * 2420 * @return void 2421 */ 2422 function bbp_increase_topic_reply_count( $topic_id = 0 ) { 2423 2424 // Bail early if no id is passed. 2425 if ( empty( $topic_id ) ) { 2426 return; 2427 } 2428 2429 // If it's a reply, get the topic id. 2430 if ( bbp_is_reply( $topic_id ) ) { 2431 $reply_id = $topic_id; 2432 $topic_id = bbp_get_reply_topic_id( $reply_id ); 2433 2434 // If this is a new, unpublished, reply, update hidden count and bail. 2435 if ( 'bbp_new_reply' === current_filter() && ! bbp_is_reply_published( $reply_id ) ) { 2436 bbp_increase_topic_reply_count_hidden( $topic_id ); 2437 return; 2438 } 2439 } 2440 2441 bbp_bump_topic_reply_count( $topic_id ); 2442 } 2443 2444 /** 2445 * Decrease the total reply count of a topic by one. 2446 * 2447 * @since 2.6.0 bbPress (rXXXX) 2448 * 2449 * @param int $topic_id The topic id. 2450 * 2451 * @uses bbp_is_reply() To check if the passed topic id is a reply. 2452 * @uses bbp_get_reply_topic_id() To get the topic id. 2453 * @uses bbp_bump_topic_reply_count() To bump topic reply count. 2454 * 2455 * @return void 2456 */ 2457 function bbp_decrease_topic_reply_count( $topic_id = 0 ) { 2458 2459 // Bail early if no id is passed. 2460 if ( empty( $topic_id ) ) { 2461 return; 2462 } 2463 2464 // If it's a reply, get the topic id. 2465 if ( bbp_is_reply( $topic_id ) ) { 2466 $topic_id = bbp_get_reply_topic_id( $topic_id ); 2467 } 2468 2469 bbp_bump_topic_reply_count( $topic_id, -1 ); 2470 } 2471 2472 /** 2367 2473 * Bump the total hidden reply count of a topic 2368 2474 * 2369 2475 * @since 2.1.0 bbPress (r3825) … … 2396 2502 return (int) apply_filters( 'bbp_bump_topic_reply_count_hidden', $new_count, $topic_id, $difference ); 2397 2503 } 2398 2504 2505 /** 2506 * Increase the total hidden reply count of a topic by one. 2507 * 2508 * @since 2.6.0 bbPress (rXXXX) 2509 * 2510 * @param int $topic_id The topic id. 2511 * 2512 * @uses bbp_is_reply() To check if the passed topic id is a reply. 2513 * @uses bbp_get_reply_topic_id() To get the topic id. 2514 * @uses bbp_bump_topic_reply_count_hidden() To bump topic hidden reply count. 2515 * 2516 * @return void 2517 */ 2518 function bbp_increase_topic_reply_count_hidden( $topic_id = 0 ) { 2519 2520 // Bail early if no id is passed. 2521 if ( empty( $topic_id ) ) { 2522 return; 2523 } 2524 2525 // If it's a reply, get the topic id. 2526 if ( bbp_is_reply( $topic_id ) ) { 2527 $topic_id = bbp_get_reply_topic_id( $topic_id ); 2528 } 2529 2530 bbp_bump_topic_reply_count_hidden( $topic_id ); 2531 } 2532 2533 /** 2534 * Decrease the total hidden reply count of a topic by one. 2535 * 2536 * @since 2.6.0 bbPress (rXXXX) 2537 * 2538 * @param int $topic_id The topic id. 2539 * 2540 * @uses bbp_is_reply() To check if the passed topic id is a reply. 2541 * @uses bbp_get_reply_topic_id() To get the topic id. 2542 * @uses bbp_bump_topic_reply_count_hidden() To bump topic hidden reply count. 2543 * 2544 * @return void 2545 */ 2546 function bbp_decrease_topic_reply_count_hidden( $topic_id = 0 ) { 2547 2548 // Bail early if no id is passed. 2549 if ( empty( $topic_id ) ) { 2550 return; 2551 } 2552 2553 // If it's a reply, get the topic id. 2554 if ( bbp_is_reply( $topic_id ) ) { 2555 $topic_id = bbp_get_reply_topic_id( $topic_id ); 2556 } 2557 2558 bbp_bump_topic_reply_count_hidden( $topic_id, -1 ); 2559 } 2560 2561 /** 2562 * Update counts after a topic is inserted via `bbp_insert_topic`. 2563 * 2564 * @since 2.6.0 bbPress (rXXXX) 2565 * 2566 * @param int $reply_id The reply id. 2567 * @param int $topic_id The topic id. 2568 * 2569 * @uses bbp_get_topic_status() To get the post status. 2570 * @uses bbp_get_public_status_id() To get the public status id. 2571 * @uses bbp_increase_forum_topic_count() To bump the topic's forum topic count by 1. 2572 * @uses bbp_increase_forum_topic_count_hidden() To bump the topic's forum topic 2573 * hidden count by 1. 2574 * 2575 * @return void 2576 */ 2577 function bbp_insert_topic_update_counts( $topic_id = 0, $forum_id = 0 ) { 2578 2579 // If the topic is public, update the forum topic counts. 2580 if ( bbp_get_topic_status( $topic_id ) === bbp_get_public_status_id() ) { 2581 bbp_increase_forum_topic_count( $forum_id ); 2582 2583 // If the topic isn't public only update the forum topic hidden count. 2584 } else { 2585 bbp_increase_forum_topic_count_hidden( $forum_id ); 2586 } 2587 } 2588 2399 2589 /** Topic Updaters ************************************************************/ 2400 2590 2401 2591 /** -
tests/phpunit/testcases/forums/functions/counts.php
13 13 * Generic function to test the forum counts with a new topic 14 14 */ 15 15 public function test_bbp_forum_new_topic_counts() { 16 remove_action( 'bbp_insert_topic', 'bbp_insert_topic_update_counts', 10 ); 17 16 18 $f = $this->factory->forum->create(); 17 19 $t1 = $this->factory->topic->create( array( 18 20 'post_parent' => $f, … … 23 25 ) ); 24 26 $u = $this->factory->user->create(); 25 27 26 // Cheating here, but we need $_SERVER['SERVER_NAME'] to be set.27 $this->setUp_wp_mail( false);28 // Don't attempt to send an email. This is for speed and PHP errors. 29 remove_action( 'bbp_new_topic', 'bbp_notify_forum_subscribers', 11, 4 ); 28 30 29 31 // Simulate the 'bbp_new_topic' action. 30 32 do_action( 'bbp_new_topic', $t1, $f, false, bbp_get_current_user_id(), $t1 ); 31 33 32 // Reverse our changes.33 $this->tearDown_wp_mail( false );34 35 34 $count = bbp_get_forum_topic_count( $f, true, true ); 36 35 $this->assertSame( 1, $count ); 37 36 … … 46 45 ), 47 46 ) ); 48 47 49 // Cheating here, but we need $_SERVER['SERVER_NAME'] to be set.50 $this->setUp_wp_mail( false );51 52 48 // Simulate the 'bbp_new_topic' action. 53 49 do_action( 'bbp_new_topic', $t2, $f, false, $u , $t2 ); 54 50 55 // Reverse our changes.56 $this->tearDown_wp_mail( false );57 58 51 $count = bbp_get_forum_topic_count( $f, true, true ); 59 52 $this->assertSame( 2, $count ); 60 53 61 54 $count = bbp_get_forum_topic_count_hidden( $f, true, true ); 62 55 $this->assertSame( 0, $count ); 56 57 // Re-add removed actions. 58 add_action( 'bbp_insert_topic', 'bbp_insert_topic_update_counts', 10, 2 ); 59 add_action( 'bbp_new_topic', 'bbp_notify_forum_subscribers', 11, 4 ); 63 60 } 64 61 65 62 /** … … 253 250 $this->assertSame( '1', $count ); 254 251 } 255 252 253 /** 254 * @covers ::bbp_increase_forum_topic_count 255 */ 256 public function test_bbp_increase_forum_topic_count() { 257 $f = $this->factory->forum->create(); 258 259 $count = bbp_get_forum_topic_count( $f ); 260 $this->assertSame( '0', $count ); 261 262 bbp_increase_forum_topic_count( $f ); 263 264 $count = bbp_get_forum_topic_count( $f ); 265 $this->assertSame( '1', $count ); 266 } 267 256 268 /** 269 * @covers ::bbp_decrease_forum_topic_count 270 */ 271 public function test_bbp_decrease_forum_topic_count() { 272 $f = $this->factory->forum->create(); 273 274 $count = bbp_get_forum_topic_count( $f ); 275 $this->assertSame( '0', $count ); 276 277 $t = $this->factory->topic->create_many( 9, array( 278 'post_parent' => $f, 279 ) ); 280 281 bbp_update_forum_topic_count( $f ); 282 283 $count = bbp_get_forum_topic_count( $f ); 284 $this->assertSame( '9', $count ); 285 286 bbp_update_forum_topic_count( $f ); 287 288 bbp_decrease_forum_topic_count( $f ); 289 290 $count = bbp_get_forum_topic_count( $f ); 291 $this->assertSame( '8', $count ); 292 } 293 294 /** 257 295 * @covers ::bbp_bump_forum_topic_count_hidden 258 296 */ 259 297 public function test_bbp_bump_forum_topic_count_hidden() { … … 268 306 $this->assertSame( '1', $count ); 269 307 } 270 308 309 /** 310 * @covers ::bbp_increase_forum_topic_count_hidden 311 */ 312 public function test_bbp_increase_forum_topic_count_hidden() { 313 $f = $this->factory->forum->create(); 314 315 $count = bbp_get_forum_topic_count_hidden( $f ); 316 $this->assertSame( '0', $count ); 317 318 bbp_increase_forum_topic_count_hidden( $f ); 319 320 $count = bbp_get_forum_topic_count_hidden( $f ); 321 $this->assertSame( '1', $count ); 322 } 323 271 324 /** 325 * @covers ::bbp_decrease_forum_topic_count_hidden 326 */ 327 public function test_bbp_decrease_forum_topic_count_hidden() { 328 $f = $this->factory->forum->create(); 329 330 $count = bbp_get_forum_topic_count_hidden( $f ); 331 $this->assertSame( '0', $count ); 332 333 $t = $this->factory->topic->create_many( 9, array( 334 'post_parent' => $f, 335 'post_status' => bbp_get_spam_status_id(), 336 'topic_meta' => array( 337 'forum_id' => $f, 338 'spam_meta_status' => 'publish', 339 ) 340 ) ); 341 342 bbp_update_forum_topic_count_hidden( $f ); 343 344 $count = bbp_get_forum_topic_count_hidden( $f ); 345 $this->assertSame( '9', $count ); 346 347 bbp_decrease_forum_topic_count_hidden( $f ); 348 349 $count = bbp_get_forum_topic_count_hidden( $f ); 350 $this->assertSame( '8', $count ); 351 } 352 353 /** 272 354 * @covers ::bbp_bump_forum_reply_count 273 355 */ 274 356 public function test_bbp_bump_forum_reply_count() { … … 283 365 $this->assertSame( '1', $count ); 284 366 } 285 367 368 /** 369 * @covers ::bbp_increase_forum_reply_count 370 */ 371 public function test_bbp_increase_forum_reply_count() { 372 $f = $this->factory->forum->create(); 373 374 $count = bbp_get_forum_reply_count( $f ); 375 $this->assertSame( '0', $count ); 376 377 bbp_increase_forum_reply_count( $f ); 378 379 $count = bbp_get_forum_reply_count( $f ); 380 $this->assertSame( '1', $count ); 381 } 382 286 383 /** 384 * @covers ::bbp_decrease_forum_reply_count 385 */ 386 public function test_bbp_decrease_forum_reply_count() { 387 $f = $this->factory->forum->create(); 388 389 $count = bbp_get_forum_reply_count( $f ); 390 $this->assertSame( '0', $count ); 391 392 $t = $this->factory->topic->create( array( 393 'post_parent' => $f, 394 ) ); 395 396 $r = $this->factory->reply->create_many( 9, array( 397 'post_parent' => $t, 398 ) ); 399 400 bbp_update_forum_reply_count( $f ); 401 402 $count = bbp_get_forum_reply_count( $f ); 403 $this->assertSame( '9', $count ); 404 405 bbp_decrease_forum_reply_count( $f ); 406 407 $count = bbp_get_forum_reply_count( $f ); 408 $this->assertSame( '8', $count ); 409 } 410 411 /** 287 412 * @covers ::bbp_update_forum_subforum_count 288 413 */ 289 414 public function test_bbp_update_forum_subforum_count() { -
tests/phpunit/testcases/topics/functions/counts.php
13 13 * Generic function to test the topics counts with a new reply 14 14 */ 15 15 public function test_bbp_topic_new_reply_counts() { 16 remove_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10 ); 17 16 18 $f = $this->factory->forum->create(); 17 19 $t = $this->factory->topic->create( array( 18 20 'post_parent' => $f, … … 31 33 ) ); 32 34 $u = $this->factory->user->create(); 33 35 34 // Cheating here, but we need $_SERVER['SERVER_NAME'] to be set.35 $this->setUp_wp_mail( false);36 // Don't attempt to send an email. This is for speed and PHP errors. 37 remove_action( 'bbp_new_reply', 'bbp_notify_subscribers', 11, 5 ); 36 38 37 39 // Simulate the 'bbp_new_reply' action. 38 40 do_action( 'bbp_new_reply', $r1, $t, $f, false, bbp_get_current_user_id() ); 39 41 40 // Reverse our changes.41 $this->tearDown_wp_mail( false );42 43 42 $count = bbp_get_topic_reply_count( $t, true ); 44 43 $this->assertSame( 1, $count ); 45 44 … … 58 57 ), 59 58 ) ); 60 59 61 // Cheating here, but we need $_SERVER['SERVER_NAME'] to be set.62 $this->setUp_wp_mail( false );63 64 60 // Simulate the 'bbp_new_topic' action. 65 61 do_action( 'bbp_new_reply', $r2, $t, $f, false, $u ); 66 62 67 // Reverse our changes.68 $this->tearDown_wp_mail( false );69 70 63 $count = bbp_get_topic_reply_count( $t, true ); 71 64 $this->assertSame( 2, $count ); 72 65 … … 75 68 76 69 $count = bbp_get_topic_voice_count( $t, true ); 77 70 $this->assertSame( 2, $count ); 71 72 // Re-add removed actions. 73 add_action( 'bbp_insert_reply', 'bbp_insert_reply_update_counts', 10, 2 ); 74 add_action( 'bbp_new_reply', 'bbp_notify_subscribers', 11, 5 ); 75 78 76 } 79 77 80 78 /** … … 340 338 $this->assertSame( '4', $count ); 341 339 } 342 340 341 /** 342 * @covers ::bbp_increase_topic_reply_count 343 */ 344 public function test_bbp_increase_topic_reply_count() { 345 $t = $this->factory->topic->create(); 346 347 $count = bbp_get_topic_reply_count( $t ); 348 $this->assertSame( '0', $count ); 349 350 bbp_increase_topic_reply_count( $t ); 351 352 $count = bbp_get_topic_reply_count( $t ); 353 $this->assertSame( '1', $count ); 354 } 355 343 356 /** 357 * @covers ::bbp_decrease_topic_reply_count 358 */ 359 public function test_bbp_decrease_topic_reply_count() { 360 $t = $this->factory->topic->create(); 361 362 $count = bbp_get_topic_reply_count( $t ); 363 $this->assertSame( '0', $count ); 364 365 // Set the count manually to 9 366 bbp_update_topic_reply_count( $t, 9 ); 367 368 $count = bbp_get_topic_reply_count( $t ); 369 $this->assertSame( '9', $count ); 370 371 bbp_decrease_topic_reply_count( $t ); 372 373 $count = bbp_get_topic_reply_count( $t ); 374 $this->assertSame( '8', $count ); 375 } 376 377 /** 344 378 * @covers ::bbp_bump_topic_reply_count_hidden 345 379 */ 346 380 public function test_bbp_bump_topic_reply_count_hidden() { … … 358 392 $this->assertSame( '4', $count ); 359 393 } 360 394 395 /** 396 * @covers ::bbp_increase_topic_reply_count_hidden 397 */ 398 public function test_bbp_increase_topic_reply_count_hidden() { 399 $t = $this->factory->topic->create(); 400 401 $count = bbp_get_topic_reply_count_hidden( $t ); 402 $this->assertSame( '0', $count ); 403 404 bbp_increase_topic_reply_count_hidden( $t ); 405 406 $count = bbp_get_topic_reply_count_hidden( $t ); 407 $this->assertSame( '1', $count ); 408 } 409 361 410 /** 411 * @covers ::bbp_decrease_topic_reply_count_hidden 412 */ 413 public function test_bbp_decrease_topic_reply_count_hidden() { 414 $t = $this->factory->topic->create(); 415 416 $count = bbp_get_topic_reply_count_hidden( $t ); 417 $this->assertSame( '0', $count ); 418 419 // Set the count manually to 9 420 bbp_update_topic_reply_count_hidden( $t, 9 ); 421 422 $count = bbp_get_topic_reply_count_hidden( $t ); 423 $this->assertSame( '9', $count ); 424 425 bbp_decrease_topic_reply_count_hidden( $t ); 426 427 $count = bbp_get_topic_reply_count_hidden( $t ); 428 $this->assertSame( '8', $count ); 429 } 430 431 /** 362 432 * @covers ::bbp_update_topic_reply_count 363 433 */ 364 434 public function test_bbp_update_topic_reply_count() { -
tests/phpunit/testcases/topics/functions/topic.php
181 181 $this->assertSame( $new_forum_id, bbp_get_reply_forum_id( $reply_id ) ); 182 182 $this->assertSame( $topic_id, bbp_get_reply_topic_id( $reply_id ) ); 183 183 184 // Old Topic/Reply Counts 185 $this->assertSame( 0, bbp_get_forum_topic_count( $old_forum_id, true, true ) ); 186 $this->assertSame( 0, bbp_get_forum_reply_count( $old_forum_id, true, true ) ); 187 188 184 189 // Retore the user 185 190 $this->set_current_user( $this->old_current_user ); 186 191 }