Changeset 6036 for trunk/src/includes/forums/functions.php
- Timestamp:
- 05/30/2016 10:28:36 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 );
Note: See TracChangeset
for help on using the changeset viewer.