Changeset 6036
- Timestamp:
- 05/30/2016 10:28:36 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/core/actions.php
r6034 r6036 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' ); … … 267 308 add_action( 'bbp_spam_topic', 'bbp_decrease_user_topic_count' ); 268 309 add_action( 'bbp_spam_reply', 'bbp_decrease_user_reply_count' ); 310 311 // Insert 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 ); 269 314 270 315 // Topic status transition helpers for replies -
trunk/src/includes/forums/functions.php
r6032 r6036 73 73 'forum_id' => $forum_id, 74 74 ) ); 75 76 /** 77 * Fires after forum has been inserted via `bbp_insert_forum`. 78 * 79 * @since 2.6.0 bbPress (r6036) 80 * 81 * @param int $forum_id The forum id. 82 */ 83 do_action( 'bbp_insert_forum', (int) $forum_id ); 75 84 76 85 // Return new forum ID … … 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 } … … 1156 1168 1157 1169 return (int) apply_filters( 'bbp_bump_forum_topic_count', $forum_topic_count, $forum_id, $difference, $update_ancestors ); 1170 } 1171 1172 /** 1173 * Increase the total topic count of a forum by one. 1174 * 1175 * @since 2.6.0 bbPress (r6036) 1176 * 1177 * @param int $forum_id The forum id. 1178 * 1179 * @uses bbp_is_topic() To get the topic id 1180 * @uses bbp_get_topic_forum_id() To get the topics forum id 1181 * @uses bbp_is_topic_published() To get the topics published status 1182 * @uses bbp_is_topic_closed() To get the topics closed status 1183 * @uses bbp_increase_forum_topic_count_hidden() To increase the forums hidden 1184 * topic count by 1 1185 * @uses bbp_bump_forum_topic_count() To bump the forum topic count 1186 * 1187 * @return void 1188 */ 1189 function bbp_increase_forum_topic_count( $forum_id = 0 ) { 1190 1191 // Bail early if no id is passed. 1192 if ( empty( $forum_id ) ) { 1193 return; 1194 } 1195 1196 // If it's a topic, get the forum id. 1197 if ( bbp_is_topic( $forum_id ) ) { 1198 $topic_id = $forum_id; 1199 $forum_id = bbp_get_topic_forum_id( $topic_id ); 1200 1201 // If this is a new, unpublished, topic, increase hidden count and bail. 1202 if ( 'bbp_new_topic' === current_filter() && ( ! bbp_is_topic_published( $topic_id ) && ! bbp_is_topic_closed( $topic_id ) ) ) { 1203 bbp_increase_forum_topic_count_hidden( $forum_id ); 1204 return; 1205 } 1206 } 1207 1208 bbp_bump_forum_topic_count( $forum_id ); 1209 } 1210 1211 /** 1212 * Decrease the total topic count of a forum by one. 1213 * 1214 * @since 2.6.0 bbPress (r6036) 1215 * 1216 * @param int $forum_id The forum id. 1217 * 1218 * @uses bbp_is_topic() To get the topic id 1219 * @uses bbp_get_topic_forum_id() To get the topics forum id 1220 * @uses bbp_bump_forum_topic_count() To bump the forum topic count 1221 * 1222 * @return void 1223 */ 1224 function bbp_decrease_forum_topic_count( $forum_id = 0 ) { 1225 1226 // Bail early if no id is passed. 1227 if ( empty( $forum_id ) ) { 1228 return; 1229 } 1230 1231 // If it's a topic, get the forum id. 1232 if ( bbp_is_topic( $forum_id ) ) { 1233 $forum_id = bbp_get_topic_forum_id( $forum_id ); 1234 } 1235 1236 bbp_bump_forum_topic_count( $forum_id, -1 ); 1158 1237 } 1159 1238 … … 1192 1271 1193 1272 /** 1273 * Increase the total hidden topic count of a forum by one. 1274 * 1275 * @since 2.6.0 bbPress (r6036) 1276 * 1277 * @param int $forum_id The forum id. 1278 * 1279 * @uses bbp_is_topic() To get the topic id 1280 * @uses bbp_get_topic_forum_id() To get the topics forum id 1281 * @uses bbp_bump_forum_topic_count_hidden() To bump the forum hidden topic count 1282 * 1283 * @return void 1284 */ 1285 function bbp_increase_forum_topic_count_hidden( $forum_id = 0 ) { 1286 1287 // Bail early if no id is passed. 1288 if ( empty( $forum_id ) ) { 1289 return; 1290 } 1291 1292 // If it's a topic, get the forum id. 1293 if ( bbp_is_topic( $forum_id ) ) { 1294 $forum_id = bbp_get_topic_forum_id( $forum_id ); 1295 } 1296 1297 bbp_bump_forum_topic_count_hidden( $forum_id ); 1298 } 1299 1300 /** 1301 * Decrease the total hidden topic count of a forum by one. 1302 * 1303 * @since 2.6.0 bbPress (r6036) 1304 * 1305 * @param int $forum_id The forum id. 1306 * 1307 * @uses bbp_is_topic() To get the topic id 1308 * @uses bbp_get_topic_forum_id() To get the topics forum id 1309 * @uses bbp_bump_forum_topic_count_hidden() To bump the forums hidden topic 1310 * count by -1 1311 * 1312 * @return void 1313 */ 1314 function bbp_decrease_forum_topic_count_hidden( $forum_id = 0 ) { 1315 1316 // Bail early if no id is passed. 1317 if ( empty( $forum_id ) ) { 1318 return; 1319 } 1320 1321 // If it's a topic, get the forum id. 1322 if ( bbp_is_topic( $forum_id ) ) { 1323 $forum_id = bbp_get_topic_forum_id( $forum_id ); 1324 } 1325 1326 bbp_bump_forum_topic_count_hidden( $forum_id, -1 ); 1327 } 1328 1329 /** 1194 1330 * Bump the total topic count of a forum 1195 1331 * … … 1233 1369 foreach ( (array) $ancestors as $parent_forum_id ) { 1234 1370 1235 // Get forum counts 1236 $parent_topic_count = bbp_get_forum_reply_count( $parent_forum_id, false, true ); 1371 // Only update reply count when an ancestor is not a category. 1372 if ( ! bbp_is_forum_category( $parent_forum_id ) ) { 1373 1374 $parent_reply_count = bbp_get_forum_reply_count( $parent_forum_id, false, true ); 1375 update_post_meta( $parent_forum_id, '_bbp_reply_count', (int) ( $parent_reply_count + $difference ) ); 1376 } 1377 1378 // Update the total reply count. 1237 1379 $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 1380 update_post_meta( $parent_forum_id, '_bbp_total_reply_count', (int) ( $parent_total_reply_count + $difference ) ); 1242 1381 } … … 1247 1386 1248 1387 return (int) apply_filters( 'bbp_bump_forum_reply_count', $forum_reply_count, $forum_id, $difference, $update_ancestors ); 1388 } 1389 1390 /** 1391 * Increase the total reply count of a forum by one. 1392 * 1393 * @since 2.6.0 bbPress (r6036) 1394 * 1395 * @param int $forum_id The forum id. 1396 * 1397 * @uses bbp_is_reply() To get the reply id 1398 * @uses bbp_get_reply_forum_id() To get the replies forum id 1399 * @uses bbp_is_reply_published() To get the replies published status 1400 * @uses bbp_bump_forum_reply_count() To bump the forum reply count 1401 * 1402 * @return void 1403 */ 1404 function bbp_increase_forum_reply_count( $forum_id = 0 ) { 1405 1406 // Bail early if no id is passed. 1407 if ( empty( $forum_id ) ) { 1408 return; 1409 } 1410 1411 // If it's a reply, get the forum id. 1412 if ( bbp_is_reply( $forum_id ) ) { 1413 $reply_id = $forum_id; 1414 $forum_id = bbp_get_reply_forum_id( $reply_id ); 1415 1416 // Don't update if this is a new, unpublished, reply. 1417 if ( 'bbp_new_reply' === current_filter() && ! bbp_is_reply_published( $reply_id ) ) { 1418 return; 1419 } 1420 } 1421 1422 bbp_bump_forum_reply_count( $forum_id ); 1423 } 1424 1425 /** 1426 * Decrease the total reply count of a forum by one. 1427 * 1428 * @since 2.6.0 bbPress (r6036) 1429 * 1430 * @param int $forum_id The forum id. 1431 * 1432 * @uses bbp_is_reply() To get the reply id 1433 * @uses bbp_get_reply_forum_id() To get the replies forum id 1434 * @uses bbp_bump_forum_reply_count() To bump the forum reply count 1435 * 1436 * @return void 1437 */ 1438 function bbp_decrease_forum_reply_count( $forum_id = 0 ) { 1439 1440 // Bail early if no id is passed. 1441 if ( empty( $forum_id ) ) { 1442 return; 1443 } 1444 1445 // If it's a reply, get the forum id. 1446 if ( bbp_is_reply( $forum_id ) ) { 1447 $forum_id = bbp_get_reply_forum_id( $forum_id ); 1448 } 1449 1450 bbp_bump_forum_reply_count( $forum_id, -1 ); 1451 } 1452 1453 /** 1454 * Update forum reply counts when a topic is approved or unapproved. 1455 * 1456 * @since 2.6.0 bbPress (r6036) 1457 * 1458 * @param int $topic_id The topic id. 1459 * 1460 * @uses bbp_get_public_child_ids() To get the topic's public child ids 1461 * @uses bbp_get_reply_post_type() To get the reply post type 1462 * @uses bbp_bump_forum_reply_count() To bump the forum reply count 1463 * @uses bbp_get_topic_forum_id() To get the topics forum id 1464 * 1465 * @return void 1466 */ 1467 function bbp_approved_unapproved_topic_update_forum_reply_count( $topic_id = 0 ) { 1468 1469 // Bail early if we don't have a topic id. 1470 if ( empty( $topic_id ) ) { 1471 return; 1472 } 1473 1474 // Get the topic's replies. 1475 $replies = bbp_get_public_child_ids( $topic_id, bbp_get_reply_post_type() ); 1476 $count = count( $replies ); 1477 1478 // If we're unapproving, set count to negative. 1479 if ( 'bbp_unapproved_topic' === current_filter() ) { 1480 $count = -$count; 1481 } 1482 1483 // Update counts. 1484 bbp_bump_forum_reply_count( bbp_get_topic_forum_id( $topic_id ), $count ); 1249 1485 } 1250 1486 … … 1733 1969 1734 1970 // 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'] ); 1971 bbp_update_forum_subforum_count( $r['forum_id'] ); 1972 1973 // Only update topic count if we're deleting a topic, or in the dashboard. 1974 if ( in_array( current_filter(), array( 'bbp_deleted_topic', 'save_post' ), true ) ) { 1975 bbp_update_forum_reply_count( $r['forum_id'] ); 1976 bbp_update_forum_topic_count( $r['forum_id'] ); 1977 bbp_update_forum_topic_count_hidden( $r['forum_id'] ); 1978 } 1739 1979 1740 1980 // Update the parent forum if one was passed … … 1849 2089 */ 1850 2090 function bbp_get_hidden_forum_ids() { 1851 2091 $forum_ids = get_option( '_bbp_hidden_forums', array() ); 1852 2092 1853 2093 return apply_filters( 'bbp_get_hidden_forum_ids', (array) $forum_ids ); … … 1866 2106 */ 1867 2107 function bbp_get_private_forum_ids() { 1868 2108 $forum_ids = get_option( '_bbp_private_forums', array() ); 1869 2109 1870 2110 return apply_filters( 'bbp_get_private_forum_ids', (array) $forum_ids ); … … 2075 2315 */ 2076 2316 function bbp_forum_query_topic_ids( $forum_id ) { 2077 2317 $topic_ids = bbp_get_public_child_ids( $forum_id, bbp_get_topic_post_type() ); 2078 2318 2079 2319 return (array) apply_filters( 'bbp_forum_query_topic_ids', $topic_ids, $forum_id ); -
trunk/src/includes/replies/functions.php
r6032 r6036 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 (r6036) 72 * 73 * @param int $reply_id The reply id. 74 * @param int $reply_meta['topic_id'] The reply topic meta. 75 * @param int $reply_meta['forum_id'] The reply forum meta. 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; 81 } 82 83 /** 84 * Update counts after a reply is inserted via `bbp_insert_reply`. 85 * 86 * @since 2.6.0 bbPress (r6036) 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 topics reply count by 1 95 * @uses bbp_increase_forum_reply_count() To bump the forums reply count by 1 96 * @uses bbp_increase_topic_reply_count_hidden() To bump the topics hidden reply 97 * 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 } 70 112 } 71 113 … … 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 ); 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 } 983 1029 984 1030 // Forum meta relating to most recent topic … … 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 } -
trunk/src/includes/topics/functions.php
r6032 r6036 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 73 /** 74 * Fires after topic has been inserted via `bbp_insert_topic`. 75 * 76 * @since 2.6.0 bbPress (r6036) 77 * 78 * @param int $topic_id The topic id. 79 * @param int $topic_meta['forum_id'] The topic forum meta. 80 */ 81 do_action( 'bbp_insert_topic', (int) $topic_id, (int) $topic_meta['forum_id'] ); 72 82 73 83 // Return new topic ID … … 1022 1032 * up the old and new branches and updating the counts. 1023 1033 * 1024 * @param int $topic_id Topic id 1025 * @param int $old_forum_id Old forum id 1026 * @param int $new_forum_id New forum id 1034 * @since 2.0.0 bbPress (r2907) 1035 * 1036 * @param int $topic_id The topic id. 1037 * @param int $old_forum_id Old forum id. 1038 * @param int $new_forum_id New forum id. 1027 1039 * @uses bbp_get_topic_id() To get the topic id 1028 1040 * @uses bbp_get_forum_id() To get the forum id 1041 * @uses bbp_clean_post_cache() To clean the old and new forum post caches 1042 * @uses bbp_update_topic_forum_id() To update the topic forum id 1029 1043 * @uses wp_update_post() To update the topic post parent` 1030 1044 * @uses bbp_get_stickies() To get the old forums sticky topics … … 1033 1047 * @uses bbp_stick_topic() To stick the topic in the new forum 1034 1048 * @uses bbp_get_reply_post_type() To get the reply post type 1035 * @uses bbp_get_all_child_ids() To get the publicchild ids1049 * @uses bbp_get_all_child_ids() To get all the child ids 1036 1050 * @uses bbp_update_reply_forum_id() To update the reply forum id 1037 * @uses bbp_update_topic_forum_id() To update the topic forum id1038 1051 * @uses get_post_ancestors() To get the topic's ancestors 1052 * @uses bbp_get_public_child_ids() To get all the public child ids 1053 * @uses get_post_field() To get the topic's post status 1054 * @uses bbp_get_public_status_id() To get the public status id 1055 * @uses bbp_decrease_forum_topic_count() To bump the forum topic count by -1 1056 * @uses bbp_bump_forum_reply_count() To bump the forum reply count 1057 * @uses bbp_increase_forum_topic_count() To bump the forum topic count by 1 1058 * @uses bbp_decrease_forum_topic_count_hidden() To bump the forum topic hidden count by -1 1059 * @uses bbp_increase_forum_topic_count_hidden() To bump the forum topic hidden count by 1 1039 1060 * @uses bbp_is_forum() To check if the ancestor is a forum 1040 1061 * @uses bbp_update_forum() To update the forum … … 1110 1131 // Get topic ancestors 1111 1132 $old_forum_ancestors = array_values( array_unique( array_merge( array( $old_forum_id ), (array) get_post_ancestors( $old_forum_id ) ) ) ); 1133 1134 // Get reply count. 1135 $public_reply_count = count( bbp_get_public_child_ids( $topic_id, bbp_get_reply_post_type() ) ); 1136 1137 // Topic status. 1138 $topic_status = get_post_field( 'post_status', $topic_id ); 1139 1140 // Update old/new forum counts. 1141 if ( $topic_status === bbp_get_public_status_id() ) { 1142 1143 // Update old forum counts. 1144 bbp_decrease_forum_topic_count( $old_forum_id ); 1145 bbp_bump_forum_reply_count( $old_forum_id, -$public_reply_count ); 1146 1147 // Update new forum counts. 1148 bbp_increase_forum_topic_count( $new_forum_id ); 1149 bbp_bump_forum_reply_count( $new_forum_id, $public_reply_count ); 1150 } else { 1151 1152 // Update old forum counts. 1153 bbp_decrease_forum_topic_count_hidden( $old_forum_id ); 1154 1155 // Update new forum counts. 1156 bbp_increase_forum_topic_count_hidden( $new_forum_id ); 1157 } 1112 1158 1113 1159 // Loop through ancestors and update them … … 2379 2425 2380 2426 /** 2427 * Increase the total reply count of a topic by one. 2428 * 2429 * @since 2.6.0 bbPress (r6036) 2430 * 2431 * @param int $topic_id The topic id. 2432 * 2433 * @uses bbp_is_reply() To check if the passed topic id is a reply 2434 * @uses bbp_get_reply_topic_id() To get the replies topic id 2435 * @uses bbp_is_reply_published() To check if the reply is published 2436 * @uses bbp_increase_topic_reply_count_hidden() To increase the topics reply 2437 * hidden count by 1 2438 * @uses bbp_bump_topic_reply_count() To bump the topic reply count 2439 * 2440 * @return void 2441 */ 2442 function bbp_increase_topic_reply_count( $topic_id = 0 ) { 2443 2444 // Bail early if no id is passed. 2445 if ( empty( $topic_id ) ) { 2446 return; 2447 } 2448 2449 // If it's a reply, get the topic id. 2450 if ( bbp_is_reply( $topic_id ) ) { 2451 $reply_id = $topic_id; 2452 $topic_id = bbp_get_reply_topic_id( $reply_id ); 2453 2454 // If this is a new, unpublished, reply, update hidden count and bail. 2455 if ( 'bbp_new_reply' === current_filter() && ! bbp_is_reply_published( $reply_id ) ) { 2456 bbp_increase_topic_reply_count_hidden( $topic_id ); 2457 return; 2458 } 2459 } 2460 2461 bbp_bump_topic_reply_count( $topic_id ); 2462 } 2463 2464 /** 2465 * Decrease the total reply count of a topic by one. 2466 * 2467 * @since 2.6.0 bbPress (r6036) 2468 * 2469 * @param int $topic_id The topic id. 2470 * 2471 * @uses bbp_is_reply() To check if the passed topic id is a reply 2472 * @uses bbp_get_reply_topic_id() To get the replies topic id 2473 * @uses bbp_bump_topic_reply_count() To bump the topic reply count 2474 * 2475 * @return void 2476 */ 2477 function bbp_decrease_topic_reply_count( $topic_id = 0 ) { 2478 2479 // Bail early if no id is passed. 2480 if ( empty( $topic_id ) ) { 2481 return; 2482 } 2483 2484 // If it's a reply, get the topic id. 2485 if ( bbp_is_reply( $topic_id ) ) { 2486 $topic_id = bbp_get_reply_topic_id( $topic_id ); 2487 } 2488 2489 bbp_bump_topic_reply_count( $topic_id, -1 ); 2490 } 2491 2492 /** 2381 2493 * Bump the total hidden reply count of a topic 2382 2494 * … … 2409 2521 2410 2522 return (int) apply_filters( 'bbp_bump_topic_reply_count_hidden', $new_count, $topic_id, $difference ); 2523 } 2524 2525 /** 2526 * Increase the total hidden reply count of a topic by one. 2527 * 2528 * @since 2.6.0 bbPress (r6036) 2529 * 2530 * @param int $topic_id The topic id. 2531 * 2532 * @uses bbp_is_reply() To check if the passed topic id is a reply 2533 * @uses bbp_get_reply_topic_id() To get the topic id 2534 * @uses bbp_bump_topic_reply_count_hidden() To bump topic hidden reply count 2535 * 2536 * @return void 2537 */ 2538 function bbp_increase_topic_reply_count_hidden( $topic_id = 0 ) { 2539 2540 // Bail early if no id is passed. 2541 if ( empty( $topic_id ) ) { 2542 return; 2543 } 2544 2545 // If it's a reply, get the topic id. 2546 if ( bbp_is_reply( $topic_id ) ) { 2547 $topic_id = bbp_get_reply_topic_id( $topic_id ); 2548 } 2549 2550 bbp_bump_topic_reply_count_hidden( $topic_id ); 2551 } 2552 2553 /** 2554 * Decrease the total hidden reply count of a topic by one. 2555 * 2556 * @since 2.6.0 bbPress (r6036) 2557 * 2558 * @param int $topic_id The topic id. 2559 * 2560 * @uses bbp_is_reply() To check if the passed topic id is a reply 2561 * @uses bbp_get_reply_topic_id() To get the topic id 2562 * @uses bbp_bump_topic_reply_count_hidden() To bump topic hidden reply count 2563 * 2564 * @return void 2565 */ 2566 function bbp_decrease_topic_reply_count_hidden( $topic_id = 0 ) { 2567 2568 // Bail early if no id is passed. 2569 if ( empty( $topic_id ) ) { 2570 return; 2571 } 2572 2573 // If it's a reply, get the topic id. 2574 if ( bbp_is_reply( $topic_id ) ) { 2575 $topic_id = bbp_get_reply_topic_id( $topic_id ); 2576 } 2577 2578 bbp_bump_topic_reply_count_hidden( $topic_id, -1 ); 2579 } 2580 2581 /** 2582 * Update counts after a topic is inserted via `bbp_insert_topic`. 2583 * 2584 * @since 2.6.0 bbPress (r6036) 2585 * 2586 * @param int $reply_id The reply id. 2587 * @param int $topic_id The topic id. 2588 * 2589 * @uses bbp_get_topic_status() To get the post status 2590 * @uses bbp_get_public_status_id() To get the public status id 2591 * @uses bbp_increase_forum_topic_count() To bump the topic's forum topic count by 1 2592 * @uses bbp_increase_forum_topic_count_hidden() To bump the topic's forum topic 2593 * hidden count by 1 2594 * 2595 * @return void 2596 */ 2597 function bbp_insert_topic_update_counts( $topic_id = 0, $forum_id = 0 ) { 2598 2599 // If the topic is public, update the forum topic counts. 2600 if ( bbp_get_topic_status( $topic_id ) === bbp_get_public_status_id() ) { 2601 bbp_increase_forum_topic_count( $forum_id ); 2602 2603 // If the topic isn't public only update the forum topic hidden count. 2604 } else { 2605 bbp_increase_forum_topic_count_hidden( $forum_id ); 2606 } 2411 2607 } 2412 2608 -
trunk/tests/phpunit/testcases/forums/functions/counts.php
r6011 r6036 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( … … 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 ); … … 46 45 ), 47 46 ) ); 48 49 // Cheating here, but we need $_SERVER['SERVER_NAME'] to be set.50 $this->setUp_wp_mail( false );51 47 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 $count = bbp_get_forum_topic_count( $f, true, true ); 59 $this->assertSame( 2, $count ); 60 61 $count = bbp_get_forum_topic_count_hidden( $f, true, true ); 62 $this->assertSame( 0, $count ); 51 $count = bbp_get_forum_topic_count( $f, true, true ); 52 $this->assertSame( 2, $count ); 53 54 $count = bbp_get_forum_topic_count_hidden( $f, true, true ); 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 … … 255 252 256 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 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( 2, 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( '2', $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( '1', $count ); 292 } 293 294 /** 257 295 * @covers ::bbp_bump_forum_topic_count_hidden 258 296 */ … … 270 308 271 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 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( 2, 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( '2', $count ); 346 347 bbp_decrease_forum_topic_count_hidden( $f ); 348 349 $count = bbp_get_forum_topic_count_hidden( $f ); 350 $this->assertSame( '1', $count ); 351 } 352 353 /** 272 354 * @covers ::bbp_bump_forum_reply_count 273 355 */ … … 279 361 280 362 bbp_bump_forum_reply_count( $f ); 363 364 $count = bbp_get_forum_reply_count( $f ); 365 $this->assertSame( '1', $count ); 366 } 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 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( 2, 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( '2', $count ); 404 405 bbp_decrease_forum_reply_count( $f ); 281 406 282 407 $count = bbp_get_forum_reply_count( $f ); -
trunk/tests/phpunit/testcases/topics/functions/counts.php
r5922 r6036 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( … … 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_topic_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 ); … … 58 57 ), 59 58 ) ); 60 61 // Cheating here, but we need $_SERVER['SERVER_NAME'] to be set.62 $this->setUp_wp_mail( false );63 59 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 $count = bbp_get_topic_reply_count( $t, true ); 71 $this->assertSame( 2, $count ); 72 73 $count = bbp_get_topic_reply_count_hidden( $t, true ); 74 $this->assertSame( 0, $count ); 75 76 $count = bbp_get_topic_voice_count( $t, true ); 77 $this->assertSame( 2, $count ); 63 $count = bbp_get_topic_reply_count( $t, true ); 64 $this->assertSame( 2, $count ); 65 66 $count = bbp_get_topic_reply_count_hidden( $t, true ); 67 $this->assertSame( 0, $count ); 68 69 $count = bbp_get_topic_voice_count( $t, true ); 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_topic_subscribers', 11, 5 ); 75 78 76 } 79 77 … … 342 340 343 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 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 2 366 bbp_update_topic_reply_count( $t, 2 ); 367 368 $count = bbp_get_topic_reply_count( $t ); 369 $this->assertSame( '2', $count ); 370 371 bbp_decrease_topic_reply_count( $t ); 372 373 $count = bbp_get_topic_reply_count( $t ); 374 $this->assertSame( '1', $count ); 375 } 376 377 /** 344 378 * @covers ::bbp_bump_topic_reply_count_hidden 345 379 */ … … 357 391 $count = bbp_get_topic_reply_count_hidden( $t ); 358 392 $this->assertSame( '4', $count ); 393 } 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 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 2 420 bbp_update_topic_reply_count_hidden( $t, 2 ); 421 422 $count = bbp_get_topic_reply_count_hidden( $t ); 423 $this->assertSame( '2', $count ); 424 425 bbp_decrease_topic_reply_count_hidden( $t ); 426 427 $count = bbp_get_topic_reply_count_hidden( $t ); 428 $this->assertSame( '1', $count ); 359 429 } 360 430 -
trunk/tests/phpunit/testcases/topics/functions/topic.php
r5947 r6036 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 );
Note: See TracChangeset
for help on using the changeset viewer.