Changeset 6923
- Timestamp:
- 11/09/2019 05:35:42 AM (5 years ago)
- Location:
- trunk/src/includes
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/tools.php
r6897 r6923 241 241 ) ); 242 242 243 // Count non-published replies to each forum 244 bbp_register_repair_tool( array( 245 'id' => 'bbp-forum-hidden-replies', 246 'type' => 'repair', 247 'title' => esc_html__( 'Recount pending, spammed, and trashed replies in each forum', 'bbpress' ), 248 'description' => esc_html__( 'Run this if non-public replies display incorrectly in forums.', 'bbpress' ), 249 'callback' => 'bbp_admin_repair_forum_hidden_reply_count', 250 'priority' => 60, 251 'overhead' => 'high', 252 'components' => array( bbp_get_forum_post_type(), bbp_get_reply_post_type() ) 253 ) ); 254 243 255 // Count topic replies 244 256 bbp_register_repair_tool( array( … … 248 260 'description' => esc_html__( 'Run this if the number of topics in any topics are incorrect.', 'bbpress' ), 249 261 'callback' => 'bbp_admin_repair_topic_reply_count', 250 'priority' => 6 0,262 'priority' => 65, 251 263 'overhead' => 'high', 252 264 'components' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) … … 258 270 'type' => 'repair', 259 271 'title' => esc_html__( 'Recount pending, spammed, and trashed replies in each topic', 'bbpress' ), 260 'description' => esc_html__( 'Run this if non-public replies display incorrectly .', 'bbpress' ),272 'description' => esc_html__( 'Run this if non-public replies display incorrectly in topics.', 'bbpress' ), 261 273 'callback' => 'bbp_admin_repair_topic_hidden_reply_count', 262 'priority' => 65,274 'priority' => 70, 263 275 'overhead' => 'high', 264 276 'components' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) … … 272 284 'description' => esc_html__( 'Run this to get fresh topic counts for all users.', 'bbpress' ), 273 285 'callback' => 'bbp_admin_repair_user_topic_count', 274 'priority' => 7 0,286 'priority' => 75, 275 287 'overhead' => 'medium', 276 288 'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() ) … … 284 296 'description' => esc_html__( 'Run this to get fresh reply counts for all users.', 'bbpress' ), 285 297 'callback' => 'bbp_admin_repair_user_reply_count', 286 'priority' => 75,298 'priority' => 80, 287 299 'overhead' => 'medium', 288 300 'components' => array( bbp_get_reply_post_type(), bbp_get_user_rewrite_id() ) … … 296 308 'description' => esc_html__( 'Run this to remove trashed or deleted topics from all user favorites.', 'bbpress' ), 297 309 'callback' => 'bbp_admin_repair_user_favorites', 298 'priority' => 8 0,310 'priority' => 85, 299 311 'overhead' => 'medium', 300 312 'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() ) … … 308 320 'description' => esc_html__( 'Run this to remove trashed or deleted topics from all user subscriptions.', 'bbpress' ), 309 321 'callback' => 'bbp_admin_repair_user_topic_subscriptions', 310 'priority' => 85,322 'priority' => 90, 311 323 'overhead' => 'medium', 312 324 'components' => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() ) … … 320 332 'description' => esc_html__( 'Run this to remove trashed or deleted forums from all user subscriptions.', 'bbpress' ), 321 333 'callback' => 'bbp_admin_repair_user_forum_subscriptions', 322 'priority' => 9 0,334 'priority' => 95, 323 335 'overhead' => 'medium', 324 336 'components' => array( bbp_get_forum_post_type(), bbp_get_user_rewrite_id() ) … … 332 344 'description' => esc_html__( 'Run this if users have issues accessing the forums.', 'bbpress' ), 333 345 'callback' => 'bbp_admin_repair_user_roles', 334 'priority' => 95,346 'priority' => 100, 335 347 'overhead' => 'low', 336 348 'components' => array( bbp_get_user_rewrite_id() ) … … 344 356 'description' => esc_html__( 'Copies engagements from user meta to topic meta.', 'bbpress' ), 345 357 'callback' => 'bbp_admin_upgrade_user_engagements', 346 'priority' => 10 0,358 'priority' => 105, 347 359 'version' => '2.6.0', 348 360 'overhead' => 'high', … … 357 369 'description' => esc_html__( 'Copies favorites from user meta to topic meta.', 'bbpress' ), 358 370 'callback' => 'bbp_admin_upgrade_user_favorites', 359 'priority' => 1 05,371 'priority' => 110, 360 372 'version' => '2.6.0', 361 373 'overhead' => 'high', … … 370 382 'description' => esc_html__( 'Copies topic subscriptions from user meta to topic meta.', 'bbpress' ), 371 383 'callback' => 'bbp_admin_upgrade_user_topic_subscriptions', 372 'priority' => 11 0,384 'priority' => 115, 373 385 'version' => '2.6.0', 374 386 'overhead' => 'high', … … 383 395 'description' => esc_html__( 'Copies forum subscriptions from user meta to forum meta.', 'bbpress' ), 384 396 'callback' => 'bbp_admin_upgrade_user_forum_subscriptions', 385 'priority' => 1 15,397 'priority' => 120, 386 398 'version' => '2.6.0', 387 399 'overhead' => 'high', … … 396 408 'description' => esc_html__( 'Run this to delete old data (after confirming successful favorites upgrade)', 'bbpress' ), 397 409 'callback' => 'bbp_admin_upgrade_remove_favorites_from_usermeta', 398 'priority' => 12 0,410 'priority' => 125, 399 411 'version' => '2.6.1', 400 412 'overhead' => 'medium', … … 409 421 'description' => esc_html__( 'Run this to delete old data (after confirming successful topic subscriptions upgrade)', 'bbpress' ), 410 422 'callback' => 'bbp_admin_upgrade_remove_topic_subscriptions_from_usermeta', 411 'priority' => 1 25,423 'priority' => 130, 412 424 'version' => '2.6.1', 413 425 'overhead' => 'medium', … … 422 434 'description' => esc_html__( 'Run this to delete old data (after confirming successful forum subscriptions upgrade)', 'bbpress' ), 423 435 'callback' => 'bbp_admin_upgrade_remove_forum_subscriptions_from_usermeta', 424 'priority' => 13 0,436 'priority' => 135, 425 437 'version' => '2.6.1', 426 438 'overhead' => 'medium', … … 435 447 'description' => esc_html__( 'Run this if you just upgraded BuddyPress Forums from Legacy.', 'bbpress' ), 436 448 'callback' => 'bbp_admin_upgrade_group_forum_relationship', 437 'priority' => 1 35,449 'priority' => 140, 438 450 'overhead' => 'low', 439 451 'components' => array( bbp_get_forum_post_type() ) -
trunk/src/includes/admin/tools/repair.php
r6908 r6923 263 263 264 264 /** 265 * Recount topic hidden replies (spammed/trashed)265 * Recount non-public replies per topic (pending/spammed/trashed) 266 266 * 267 267 * @since 2.0.0 bbPress (r2747) … … 405 405 foreach ( $forums as $forum ) { 406 406 bbp_update_forum_reply_count( $forum->ID ); 407 } 408 } else { 409 return array( 2, sprintf( $statement, $result ) ); 410 } 411 412 return array( 0, sprintf( $statement, esc_html__( 'Complete!', 'bbpress' ) ) ); 413 } 414 415 /** 416 * Recount non-public forum replies 417 * 418 * @since 2.6.0 bbPress (r6922) 419 * 420 * @return array An array of the status code and the message 421 */ 422 function bbp_admin_repair_forum_reply_count_hidden() { 423 424 // Define variables 425 $bbp_db = bbp_db(); 426 $statement = esc_html__( 'Counting the number of pending, spammed, and trashed replies in each forum… %s', 'bbpress' ); 427 $result = esc_html__( 'Failed!', 'bbpress' ); 428 429 // Post type 430 $fpt = bbp_get_forum_post_type(); 431 432 // Delete the meta keys _bbp_reply_count and _bbp_total_reply_count for each forum 433 $sql_delete = "DELETE `postmeta` FROM `{$bbp_db->postmeta}` AS `postmeta` 434 LEFT JOIN `{$bbp_db->posts}` AS `posts` ON `posts`.`ID` = `postmeta`.`post_id` 435 WHERE `posts`.`post_type` = '{$fpt}' 436 AND `postmeta`.`meta_key` = '_bbp_reply_count_hidden' 437 OR `postmeta`.`meta_key` = '_bbp_total_reply_count_hidden'"; 438 439 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 440 return array( 1, sprintf( $statement, $result ) ); 441 } 442 443 // Recalculate the metas key _bbp_reply_count and _bbp_total_reply_count for each forum 444 $forums = get_posts( array( 'post_type' => bbp_get_forum_post_type(), 'numberposts' => -1 ) ); 445 if ( ! empty( $forums ) ) { 446 foreach ( $forums as $forum ) { 447 bbp_update_forum_reply_count_hidden( $forum->ID ); 407 448 } 408 449 } else { -
trunk/src/includes/common/functions.php
r6922 r6923 1664 1664 } 1665 1665 1666 // Get the public posts status 1667 $post_status = array( bbp_get_public_status_id() ); 1668 1669 // Add closed status if topic post type 1670 if ( bbp_get_topic_post_type() === $post_type ) { 1671 $post_status[] = bbp_get_closed_status_id(); 1666 // Which statuses 1667 switch ( $post_type ) { 1668 1669 // Forum 1670 case bbp_get_forum_post_type() : 1671 $post_status = bbp_get_public_forum_statuses(); 1672 break; 1673 1674 // Topic 1675 case bbp_get_topic_post_type() : 1676 $post_status = bbp_get_public_topic_statuses(); 1677 break; 1678 1679 // Reply 1680 case bbp_get_reply_post_type() : 1681 default : 1682 $post_status = bbp_get_public_reply_statuses(); 1683 break; 1672 1684 } 1673 1685 … … 1823 1835 // Forum 1824 1836 case bbp_get_forum_post_type() : 1825 $post_status = array( bbp_get_public_status_id());1837 $post_status = bbp_get_public_forum_statuses(); 1826 1838 break; 1827 1839 -
trunk/src/includes/core/actions.php
r6915 r6923 231 231 232 232 // Subscriptions 233 add_action( 'bbp_spam_topic', 'bbp_remove_topic_from_all_subscriptions' ); 234 add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_subscriptions' ); 235 add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions' ); 236 add_action( 'bbp_trash_forum', 'bbp_remove_forum_from_all_subscriptions' ); 237 add_action( 'bbp_delete_forum', 'bbp_remove_forum_from_all_subscriptions' ); 238 add_action( 'bbp_new_reply', 'bbp_notify_topic_subscribers', 11, 5 ); 239 add_action( 'bbp_new_topic', 'bbp_notify_forum_subscribers', 11, 4 ); 233 add_action( 'bbp_spam_topic', 'bbp_remove_topic_from_all_subscriptions' ); 234 add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_subscriptions' ); 235 add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions' ); 236 add_action( 'bbp_trash_forum', 'bbp_remove_forum_from_all_subscriptions' ); 237 add_action( 'bbp_delete_forum', 'bbp_remove_forum_from_all_subscriptions' ); 238 239 // Subscription notifications 240 add_action( 'bbp_new_reply', 'bbp_notify_topic_subscribers', 11, 5 ); 241 add_action( 'bbp_new_topic', 'bbp_notify_forum_subscribers', 11, 4 ); 240 242 241 243 // Sticky … … 264 266 add_action( 'bbp_unapproved_reply', 'bbp_update_reply_walker' ); 265 267 266 // Update forum topic/reply counts. 267 add_action( 'bbp_new_reply', 'bbp_increase_forum_reply_count' ); 268 add_action( 'bbp_new_topic', 'bbp_increase_forum_topic_count' ); 269 add_action( 'bbp_trashed_reply', 'bbp_decrease_forum_reply_count' ); 270 add_action( 'bbp_trashed_topic', 'bbp_decrease_forum_topic_count' ); 271 add_action( 'bbp_untrashed_reply', 'bbp_increase_forum_reply_count' ); 272 add_action( 'bbp_untrashed_topic', 'bbp_increase_forum_topic_count' ); 273 add_action( 'bbp_spammed_reply', 'bbp_decrease_forum_reply_count' ); 274 add_action( 'bbp_spammed_topic', 'bbp_decrease_forum_topic_count' ); 275 add_action( 'bbp_unspammed_reply', 'bbp_increase_forum_reply_count' ); 276 add_action( 'bbp_unspammed_topic', 'bbp_increase_forum_topic_count' ); 277 add_action( 'bbp_approved_reply', 'bbp_increase_forum_reply_count' ); 278 add_action( 'bbp_approved_topic', 'bbp_increase_forum_topic_count' ); 279 add_action( 'bbp_unapproved_reply', 'bbp_decrease_forum_reply_count' ); 280 add_action( 'bbp_unapproved_topic', 'bbp_decrease_forum_topic_count' ); 268 // Update forum reply counts 269 add_action( 'bbp_new_reply', 'bbp_increase_forum_reply_count' ); 270 add_action( 'bbp_untrashed_reply', 'bbp_increase_forum_reply_count' ); 271 add_action( 'bbp_unspammed_reply', 'bbp_increase_forum_reply_count' ); 272 add_action( 'bbp_approved_reply', 'bbp_increase_forum_reply_count' ); 273 add_action( 'bbp_trash_reply', 'bbp_decrease_forum_reply_count' ); 274 add_action( 'bbp_spam_reply', 'bbp_decrease_forum_reply_count' ); 275 add_action( 'bbp_unapprove_reply', 'bbp_decrease_forum_reply_count' ); 276 277 // Update forum hidden reply counts 278 add_action( 'bbp_trashed_reply', 'bbp_increase_forum_reply_count_hidden' ); 279 add_action( 'bbp_spammed_reply', 'bbp_increase_forum_reply_count_hidden' ); 280 add_action( 'bbp_unapproved_reply', 'bbp_increase_forum_reply_count_hidden' ); 281 add_action( 'bbp_untrash_reply', 'bbp_decrease_forum_reply_count_hidden' ); 282 add_action( 'bbp_unspam_reply', 'bbp_decrease_forum_reply_count_hidden' ); 283 add_action( 'bbp_approve_reply', 'bbp_decrease_forum_reply_count_hidden' ); 284 add_action( 'bbp_delete_reply', 'bbp_decrease_forum_reply_count_hidden' ); 285 286 // Update forum topic counts 287 add_action( 'bbp_new_topic', 'bbp_increase_forum_topic_count' ); 288 add_action( 'bbp_untrashed_topic', 'bbp_increase_forum_topic_count' ); 289 add_action( 'bbp_unspammed_topic', 'bbp_increase_forum_topic_count' ); 290 add_action( 'bbp_approved_topic', 'bbp_increase_forum_topic_count' ); 291 add_action( 'bbp_trash_topic', 'bbp_decrease_forum_topic_count' ); 292 add_action( 'bbp_spam_topic', 'bbp_decrease_forum_topic_count' ); 293 add_action( 'bbp_unapprove_topic', 'bbp_decrease_forum_topic_count' ); 294 295 // Update forum hidden topic counts 281 296 add_action( 'bbp_trashed_topic', 'bbp_increase_forum_topic_count_hidden' ); 282 add_action( 'bbp_untrashed_topic', 'bbp_decrease_forum_topic_count_hidden' );283 297 add_action( 'bbp_spammed_topic', 'bbp_increase_forum_topic_count_hidden' ); 284 add_action( 'bbp_unspammed_topic', 'bbp_decrease_forum_topic_count_hidden' );285 add_action( 'bbp_approved_topic', 'bbp_decrease_forum_topic_count_hidden' );286 298 add_action( 'bbp_unapproved_topic', 'bbp_increase_forum_topic_count_hidden' ); 287 288 // Update forum reply counts for approved/unapproved topics. 299 add_action( 'bbp_untrash_topic', 'bbp_decrease_forum_topic_count_hidden' ); 300 add_action( 'bbp_unspam_topic', 'bbp_decrease_forum_topic_count_hidden' ); 301 add_action( 'bbp_approve_topic', 'bbp_decrease_forum_topic_count_hidden' ); 302 add_action( 'bbp_delete_topic', 'bbp_decrease_forum_topic_count_hidden' ); 303 304 // Update topic reply counts 305 add_action( 'bbp_new_reply', 'bbp_increase_topic_reply_count' ); 306 add_action( 'bbp_untrashed_reply', 'bbp_increase_topic_reply_count' ); 307 add_action( 'bbp_unspammed_reply', 'bbp_increase_topic_reply_count' ); 308 add_action( 'bbp_approved_reply', 'bbp_increase_topic_reply_count' ); 309 add_action( 'bbp_trash_reply', 'bbp_decrease_topic_reply_count' ); 310 add_action( 'bbp_spam_reply', 'bbp_decrease_topic_reply_count' ); 311 add_action( 'bbp_unapprove_reply', 'bbp_decrease_topic_reply_count' ); 312 313 // Update topic hidden reply counts 314 add_action( 'bbp_trashed_reply', 'bbp_increase_topic_reply_count_hidden' ); 315 add_action( 'bbp_unapproved_reply', 'bbp_increase_topic_reply_count_hidden' ); 316 add_action( 'bbp_spammed_reply', 'bbp_increase_topic_reply_count_hidden' ); 317 add_action( 'bbp_untrash_reply', 'bbp_decrease_topic_reply_count_hidden' ); 318 add_action( 'bbp_unspam_reply', 'bbp_decrease_topic_reply_count_hidden' ); 319 add_action( 'bbp_approve_reply', 'bbp_decrease_topic_reply_count_hidden' ); 320 add_action( 'bbp_delete_reply', 'bbp_decrease_topic_reply_count_hidden' ); 321 322 // Update forum reply counts for approved/unapproved topics 289 323 add_action( 'bbp_approved_topic', 'bbp_approved_unapproved_topic_update_forum_reply_count' ); 290 324 add_action( 'bbp_unapproved_topic', 'bbp_approved_unapproved_topic_update_forum_reply_count' ); 291 325 292 // Update topic reply counts. 293 add_action( 'bbp_new_reply', 'bbp_increase_topic_reply_count' ); 294 add_action( 'bbp_trashed_reply', 'bbp_decrease_topic_reply_count' ); 295 add_action( 'bbp_untrashed_reply', 'bbp_increase_topic_reply_count' ); 296 add_action( 'bbp_spammed_reply', 'bbp_decrease_topic_reply_count' ); 297 add_action( 'bbp_unspammed_reply', 'bbp_increase_topic_reply_count' ); 298 add_action( 'bbp_approved_reply', 'bbp_increase_topic_reply_count' ); 299 add_action( 'bbp_unapproved_reply', 'bbp_decrease_topic_reply_count' ); 300 add_action( 'bbp_trashed_reply', 'bbp_increase_topic_reply_count_hidden' ); 301 add_action( 'bbp_untrashed_reply', 'bbp_decrease_topic_reply_count_hidden' ); 302 add_action( 'bbp_spammed_reply', 'bbp_increase_topic_reply_count_hidden' ); 303 add_action( 'bbp_unspammed_reply', 'bbp_decrease_topic_reply_count_hidden' ); 304 add_action( 'bbp_approved_reply', 'bbp_decrease_topic_reply_count_hidden' ); 305 add_action( 'bbp_unapproved_reply', 'bbp_increase_topic_reply_count_hidden' ); 306 add_action( 'bbp_deleted_reply', 'bbp_decrease_topic_reply_count_hidden' ); 307 308 // Users topic & reply counts. 326 // Users topic & reply counts 309 327 add_action( 'bbp_new_topic', 'bbp_increase_user_topic_count' ); 310 328 add_action( 'bbp_new_reply', 'bbp_increase_user_reply_count' ); … … 325 343 add_action( 'bbp_unspam_topic', 'bbp_unspam_topic_replies' ); 326 344 327 // Topic engagements on user creation .345 // Topic engagements on user creation 328 346 add_action( 'bbp_new_topic', 'bbp_update_topic_engagements', 20 ); 329 347 add_action( 'bbp_new_reply', 'bbp_update_topic_engagements', 20 ); … … 344 362 add_action( 'bbp_insert_reply', 'bbp_update_topic_voice_count', 30 ); 345 363 346 // Recalculate engagements .364 // Recalculate engagements 347 365 add_action( 'bbp_trashed_reply', 'bbp_recalculate_topic_engagements' ); 348 366 add_action( 'bbp_untrashed_reply', 'bbp_recalculate_topic_engagements' ); … … 360 378 add_action( 'bbp_deleted_topic', 'bbp_recalculate_topic_engagements' ); 361 379 362 // Update engagement counts .380 // Update engagement counts 363 381 add_action( 'bbp_trashed_reply', 'bbp_update_topic_voice_count', 30 ); 364 382 add_action( 'bbp_untrashed_reply', 'bbp_update_topic_voice_count', 30 ); -
trunk/src/includes/core/sub-actions.php
r6919 r6923 265 265 do_action( 'bbp_login_form_login' ); 266 266 } 267 268 267 269 268 /** -
trunk/src/includes/forums/functions.php
r6922 r6923 1135 1135 $forum_id = bbp_get_topic_forum_id( $topic_id ); 1136 1136 1137 // Bail if not public.1137 // Update inverse based on item status 1138 1138 if ( ! bbp_is_topic_public( $topic_id ) ) { 1139 1139 bbp_increase_forum_topic_count_hidden( $forum_id ); … … 1142 1142 } 1143 1143 1144 // Bump up 1144 1145 bbp_bump_forum_topic_count( $forum_id ); 1145 1146 } … … 1163 1164 // If it's a topic, get the forum id. 1164 1165 if ( bbp_is_topic( $forum_id ) ) { 1165 $forum_id = bbp_get_topic_forum_id( $forum_id ); 1166 } 1167 1166 $topic_id = $forum_id; 1167 $forum_id = bbp_get_topic_forum_id( $topic_id ); 1168 1169 // Update inverse based on item status 1170 if ( ! bbp_is_topic_public( $topic_id ) ) { 1171 bbp_decrease_forum_topic_count_hidden( $forum_id ); 1172 return; 1173 } 1174 } 1175 1176 // Bump down 1168 1177 bbp_bump_forum_topic_count( $forum_id, -1 ); 1169 1178 } 1170 1179 1171 1180 /** 1172 * Bump the total hiddentopic count of a forum1181 * Bump the total topic count of a forum 1173 1182 * 1174 1183 * @since 2.1.0 bbPress (r3825) … … 1176 1185 * @param int $forum_id Optional. Forum id. 1177 1186 * @param int $difference Optional. Default 1 1178 * 1179 * @return int Forum hidden topic count 1180 */ 1181 function bbp_bump_forum_topic_count_hidden( $forum_id = 0, $difference = 1 ) { 1187 * @param bool $update_ancestors Optional. Default true 1188 * 1189 * @return int Forum topic count 1190 */ 1191 function bbp_bump_forum_topic_count_hidden( $forum_id = 0, $difference = 1, $update_ancestors = true ) { 1182 1192 1183 1193 // Bail if no bump … … 1187 1197 1188 1198 // Get some counts 1189 $forum_id = bbp_get_forum_id( $forum_id );1190 $ topic_count = bbp_get_forum_topic_count_hidden( $forum_id, true );1191 $ difference = (int) $difference;1192 $ new_count = (int) ( $topic_count + $difference );1199 $forum_id = bbp_get_forum_id( $forum_id ); 1200 $reply_count = bbp_get_forum_topic_count_hidden( $forum_id, false, true ); 1201 $total_topic_count = bbp_get_forum_topic_count_hidden( $forum_id, true, true ); 1202 $difference = (int) $difference; 1193 1203 1194 1204 // Update this forum id 1195 update_post_meta( $forum_id, '_bbp_topic_count_hidden', $new_count ); 1205 update_post_meta( $forum_id, '_bbp_topic_count_hidden', (int) ( $reply_count + $difference ) ); 1206 update_post_meta( $forum_id, '_bbp_total_topic_count_hidden', (int) ( $total_topic_count + $difference ) ); 1207 1208 // Check for ancestors 1209 if ( true === $update_ancestors ) { 1210 1211 // Get post ancestors 1212 $forum = get_post( $forum_id ); 1213 $ancestors = get_post_ancestors( $forum ); 1214 1215 // If has ancestors, loop through them... 1216 if ( ! empty( $ancestors ) ) { 1217 foreach ( (array) $ancestors as $parent_forum_id ) { 1218 1219 // Only update topic count when an ancestor is not a category. 1220 if ( ! bbp_is_forum_category( $parent_forum_id ) ) { 1221 1222 $parent_topic_count = bbp_get_forum_topic_count_hidden( $parent_forum_id, false, true ); 1223 update_post_meta( $parent_forum_id, '_bbp_topic_count_hidden', (int) ( $parent_topic_count + $difference ) ); 1224 } 1225 1226 // Update the total topic count. 1227 $parent_total_topic_count = bbp_get_forum_topic_count_hidden( $parent_forum_id, true, true ); 1228 update_post_meta( $parent_forum_id, '_bbp_total_topic_count_hidden', (int) ( $parent_total_topic_count + $difference ) ); 1229 } 1230 } 1231 } 1232 1233 $forum_topic_count = (int) ( $total_topic_count + $difference ); 1196 1234 1197 1235 // Filter & return 1198 return (int) apply_filters( 'bbp_bump_forum_topic_count_hidden', $ new_count, $forum_id, $difference);1236 return (int) apply_filters( 'bbp_bump_forum_topic_count_hidden', $forum_topic_count, $forum_id, $difference, $update_ancestors ); 1199 1237 } 1200 1238 … … 1217 1255 // If it's a topic, get the forum id. 1218 1256 if ( bbp_is_topic( $forum_id ) ) { 1219 $forum_id = bbp_get_topic_forum_id( $forum_id ); 1220 } 1221 1257 $topic_id = $forum_id; 1258 $forum_id = bbp_get_topic_forum_id( $topic_id ); 1259 1260 // Update inverse based on item status 1261 if ( bbp_is_topic_public( $topic_id ) ) { 1262 bbp_increase_forum_topic_count( $forum_id ); 1263 return; 1264 } 1265 } 1266 1267 // Bump up 1222 1268 bbp_bump_forum_topic_count_hidden( $forum_id ); 1223 1269 } … … 1241 1287 // If it's a topic, get the forum id. 1242 1288 if ( bbp_is_topic( $forum_id ) ) { 1243 $forum_id = bbp_get_topic_forum_id( $forum_id ); 1244 } 1245 1289 $topic_id = $forum_id; 1290 $forum_id = bbp_get_topic_forum_id( $topic_id ); 1291 1292 // Update inverse based on item status 1293 if ( bbp_is_topic_public( $topic_id ) ) { 1294 bbp_decrease_forum_topic_count( $forum_id ); 1295 return; 1296 } 1297 } 1298 1299 // Bump down 1246 1300 bbp_bump_forum_topic_count_hidden( $forum_id, -1 ); 1247 1301 } … … 1267 1321 // Get some counts 1268 1322 $forum_id = bbp_get_forum_id( $forum_id ); 1269 $ topic_count = bbp_get_forum_reply_count( $forum_id, false, true );1323 $reply_count = bbp_get_forum_reply_count( $forum_id, false, true ); 1270 1324 $total_reply_count = bbp_get_forum_reply_count( $forum_id, true, true ); 1271 1325 $difference = (int) $difference; 1272 1326 1273 1327 // Update this forum id 1274 update_post_meta( $forum_id, '_bbp_reply_count', (int) ( $ topic_count + $difference ) );1328 update_post_meta( $forum_id, '_bbp_reply_count', (int) ( $reply_count + $difference ) ); 1275 1329 update_post_meta( $forum_id, '_bbp_total_reply_count', (int) ( $total_reply_count + $difference ) ); 1276 1330 … … 1307 1361 1308 1362 /** 1363 * Bump the total topic count of a forum 1364 * 1365 * @since 2.6.0 bbPress (r6922) 1366 * 1367 * @param int $forum_id Optional. Forum id. 1368 * @param int $difference Optional. Default 1 1369 * @param bool $update_ancestors Optional. Default true 1370 * 1371 * @return int Forum topic count 1372 */ 1373 function bbp_bump_forum_reply_count_hidden( $forum_id = 0, $difference = 1, $update_ancestors = true ) { 1374 1375 // Bail if no bump 1376 if ( empty( $difference ) ) { 1377 return false; 1378 } 1379 1380 // Get some counts 1381 $forum_id = bbp_get_forum_id( $forum_id ); 1382 $reply_count = bbp_get_forum_reply_count_hidden( $forum_id, false, true ); 1383 $total_reply_count = bbp_get_forum_reply_count_hidden( $forum_id, true, true ); 1384 $difference = (int) $difference; 1385 1386 // Update this forum id 1387 update_post_meta( $forum_id, '_bbp_reply_count_hidden', (int) ( $reply_count + $difference ) ); 1388 update_post_meta( $forum_id, '_bbp_total_reply_count_hidden', (int) ( $total_reply_count + $difference ) ); 1389 1390 // Check for ancestors 1391 if ( true === $update_ancestors ) { 1392 1393 // Get post ancestors 1394 $forum = get_post( $forum_id ); 1395 $ancestors = get_post_ancestors( $forum ); 1396 1397 // If has ancestors, loop through them... 1398 if ( ! empty( $ancestors ) ) { 1399 foreach ( (array) $ancestors as $parent_forum_id ) { 1400 1401 // Only update reply count when an ancestor is not a category. 1402 if ( ! bbp_is_forum_category( $parent_forum_id ) ) { 1403 1404 $parent_reply_count = bbp_get_forum_reply_count_hidden( $parent_forum_id, false, true ); 1405 update_post_meta( $parent_forum_id, '_bbp_reply_count_hidden', (int) ( $parent_reply_count + $difference ) ); 1406 } 1407 1408 // Update the total reply count. 1409 $parent_total_reply_count = bbp_get_forum_reply_count_hidden( $parent_forum_id, true, true ); 1410 update_post_meta( $parent_forum_id, '_bbp_total_reply_count_hidden', (int) ( $parent_total_reply_count + $difference ) ); 1411 } 1412 } 1413 } 1414 1415 $forum_reply_count = (int) ( $total_reply_count + $difference ); 1416 1417 // Filter & return 1418 return (int) apply_filters( 'bbp_bump_forum_reply_count_hidden', $forum_reply_count, $forum_id, $difference, $update_ancestors ); 1419 } 1420 1421 /** 1309 1422 * Increase the total reply count of a forum by one. 1310 1423 * … … 1324 1437 // If it's a reply, get the forum id. 1325 1438 if ( bbp_is_reply( $forum_id ) ) { 1326 $forum_id = bbp_get_reply_forum_id( $forum_id ); 1327 } 1328 1439 $reply_id = $forum_id; 1440 $forum_id = bbp_get_reply_forum_id( $reply_id ); 1441 1442 // Update inverse based on item status 1443 if ( ! bbp_is_reply_public( $reply_id ) ) { 1444 bbp_increase_forum_reply_count_hidden( $forum_id ); 1445 return; 1446 } 1447 } 1448 1449 // Bump up 1329 1450 bbp_bump_forum_reply_count( $forum_id ); 1330 1451 } … … 1348 1469 // If it's a reply, get the forum id. 1349 1470 if ( bbp_is_reply( $forum_id ) ) { 1350 $forum_id = bbp_get_reply_forum_id( $forum_id ); 1351 } 1352 1471 $reply_id = $forum_id; 1472 $forum_id = bbp_get_reply_forum_id( $reply_id ); 1473 1474 // Update inverse based on item status 1475 if ( ! bbp_is_reply_public( $reply_id ) ) { 1476 bbp_decrease_forum_reply_count_hidden( $forum_id ); 1477 return; 1478 } 1479 } 1480 1481 // Bump down 1353 1482 bbp_bump_forum_reply_count( $forum_id, -1 ); 1483 } 1484 1485 /** 1486 * Increase the total hidden reply count of a forum by one. 1487 * 1488 * @since 2.6.0 bbPress (r6036) 1489 * 1490 * @param int $forum_id The forum id. 1491 * 1492 * @return void 1493 */ 1494 function bbp_increase_forum_reply_count_hidden( $forum_id = 0 ) { 1495 1496 // Bail early if no id is passed. 1497 if ( empty( $forum_id ) ) { 1498 return; 1499 } 1500 1501 // If it's a reply, get the forum id. 1502 if ( bbp_is_reply( $forum_id ) ) { 1503 $reply_id = $forum_id; 1504 $forum_id = bbp_get_reply_forum_id( $reply_id ); 1505 1506 // Update inverse based on item status 1507 if ( bbp_is_reply_public( $reply_id ) ) { 1508 bbp_increase_forum_reply_count( $forum_id ); 1509 return; 1510 } 1511 } 1512 1513 // Bump up 1514 bbp_bump_forum_reply_count_hidden( $forum_id ); 1515 } 1516 1517 /** 1518 * Decrease the total hidden reply count of a forum by one. 1519 * 1520 * @since 2.6.0 bbPress (r6036) 1521 * 1522 * @param int $forum_id The forum id. 1523 * 1524 * @return void 1525 */ 1526 function bbp_decrease_forum_reply_count_hidden( $forum_id = 0 ) { 1527 1528 // Bail early if no id is passed. 1529 if ( empty( $forum_id ) ) { 1530 return; 1531 } 1532 1533 // If it's a reply, get the forum id. 1534 if ( bbp_is_reply( $forum_id ) ) { 1535 $reply_id = $forum_id; 1536 $forum_id = bbp_get_reply_forum_id( $reply_id ); 1537 1538 // Update inverse based on item status 1539 if ( bbp_is_reply_public( $reply_id ) ) { 1540 bbp_decrease_forum_reply_count( $forum_id ); 1541 return; 1542 } 1543 } 1544 1545 // Bump down 1546 bbp_bump_forum_reply_count_hidden( $forum_id, -1 ); 1354 1547 } 1355 1548 … … 1378 1571 } 1379 1572 1380 // Update counts.1573 // Bump up or down 1381 1574 bbp_bump_forum_reply_count( bbp_get_topic_forum_id( $topic_id ), $count ); 1382 1575 } … … 1437 1630 1438 1631 // Update the last public topic ID 1439 if ( bbp_is_topic_published( $topic_id ) ) { 1440 update_post_meta( $forum_id, '_bbp_last_topic_id', $topic_id ); 1441 } 1632 update_post_meta( $forum_id, '_bbp_last_topic_id', $topic_id ); 1442 1633 1443 1634 // Filter & return … … 1479 1670 1480 1671 // ...and compare it to the most recent topic id... 1481 $reply_id = ( $reply_id > max( $topic_ids ) ) ? $reply_id : max( $topic_ids ); 1672 $reply_id = ( $reply_id > max( $topic_ids ) ) 1673 ? $reply_id 1674 : max( $topic_ids ); 1482 1675 } 1483 1676 } … … 1493 1686 1494 1687 // Update the last public reply ID 1495 if ( bbp_is_reply_published( $reply_id ) ) { 1496 update_post_meta( $forum_id, '_bbp_last_reply_id', $reply_id ); 1497 } 1688 update_post_meta( $forum_id, '_bbp_last_reply_id', $reply_id ); 1498 1689 1499 1690 // Filter & return … … 1520 1711 if ( empty( $active_id ) ) { 1521 1712 1522 // Loop through children and add together forum reply counts1713 // Loop through children and get the last active ID 1523 1714 $children = bbp_forum_query_subforum_ids( $forum_id ); 1524 1715 if ( ! empty( $children ) ) { … … 1528 1719 } 1529 1720 1530 // Don't count replies if the forum is a category1721 // Get topic IDs and only accept larger IDs 1531 1722 $topic_ids = bbp_forum_query_topic_ids( $forum_id ); 1532 1723 if ( ! empty( $topic_ids ) ) { 1724 1725 // Make sure ID is larger 1533 1726 $active_id = bbp_forum_query_last_reply_id( $forum_id, $topic_ids ); 1534 $active_id = $active_id > max( $topic_ids ) ? $active_id : max( $topic_ids ); 1727 $active_id = $active_id > max( $topic_ids ) 1728 ? $active_id 1729 : max( $topic_ids ); 1535 1730 1536 1731 // Forum has no topics … … 1544 1739 $children_last_active = (int) $children_last_active; 1545 1740 1546 // If child forums have higher id, use that instead1741 // If child forums have higher ID, use that instead 1547 1742 if ( ! empty( $children ) && ( $children_last_active > $active_id ) ) { 1548 1743 $active_id = $children_last_active; 1549 1744 } 1550 1745 1551 // Update only if published 1552 if ( bbp_get_public_status_id() === get_post_status( $active_id ) ) { 1553 update_post_meta( $forum_id, '_bbp_last_active_id', $active_id ); 1554 } 1746 update_post_meta( $forum_id, '_bbp_last_active_id', $active_id ); 1555 1747 1556 1748 // Filter & return … … 1591 1783 * 1592 1784 * @param int $forum_id Optional. Forum id 1785 * @param int $subforums Optional. Number of subforums 1593 1786 * @return bool True on success, false on failure 1594 1787 */ 1595 function bbp_update_forum_subforum_count( $forum_id = 0, $subforums = 0) {1788 function bbp_update_forum_subforum_count( $forum_id = 0, $subforums = false ) { 1596 1789 $forum_id = bbp_get_forum_id( $forum_id ); 1597 1790 1598 1791 // Maybe query for counts 1599 if ( empty( $subforums ) ) { 1600 $subforums = bbp_get_public_child_count( $forum_id, bbp_get_forum_post_type() ); 1601 } 1602 1603 $subforums = (int) $subforums; 1792 $subforums = ! is_int( $subforums ) 1793 ? bbp_get_public_child_count( $forum_id, bbp_get_forum_post_type() ) 1794 : (int) $subforums; 1604 1795 1605 1796 update_post_meta( $forum_id, '_bbp_forum_subforum_count', $subforums ); … … 1658 1849 * @return int Topic hidden topic count 1659 1850 */ 1660 function bbp_update_forum_topic_count_hidden( $forum_id = 0, $topic_count = 0) {1851 function bbp_update_forum_topic_count_hidden( $forum_id = 0, $topic_count = false ) { 1661 1852 1662 1853 // If topic_id was passed as $forum_id, then get its forum … … 1674 1865 1675 1866 // Get topics of forum 1676 if ( empty( $topic_count ) ) {1867 if ( ! is_int( $topic_count ) ) { 1677 1868 $query = new WP_Query( array( 1678 1869 'fields' => 'ids', … … 1730 1921 1731 1922 // Don't count replies if the forum is a category 1732 $reply_count = 0; 1733 $topic_ids = bbp_forum_query_topic_ids( $forum_id ); 1734 if ( ! empty( $topic_ids ) ) { 1735 $reply_count = bbp_get_public_child_count( $forum_id, bbp_get_reply_post_type() ); 1736 } 1923 $reply_count = ! bbp_is_forum_category( $forum_id ) 1924 ? bbp_get_public_child_count( $forum_id, bbp_get_reply_post_type() ) 1925 : 0; 1737 1926 1738 1927 // Calculate total replies in this forum 1739 1928 $total_replies = (int) ( $reply_count + $children_reply_count ); 1740 1929 1741 // Update the count 1930 // Update the counts 1742 1931 update_post_meta( $forum_id, '_bbp_reply_count', $reply_count ); 1743 1932 update_post_meta( $forum_id, '_bbp_total_reply_count', $total_replies ); … … 1745 1934 // Filter & return 1746 1935 return (int) apply_filters( 'bbp_update_forum_reply_count', $total_replies, $forum_id ); 1936 } 1937 1938 /** 1939 * Adjust the total hidden reply count of a forum 1940 * 1941 * @since 2.6.0 bbPress (r6922) 1942 * 1943 * @param int $forum_id Optional. Forum id or topic id. It is checked whether it 1944 * is a topic or a forum. If it's a topic, its parent, 1945 * i.e. the forum is automatically retrieved. 1946 * 1947 * @return int Forum reply count 1948 */ 1949 function bbp_update_forum_reply_count_hidden( $forum_id = 0 ) { 1950 1951 $forum_id = bbp_get_forum_id( $forum_id ); 1952 $children_reply_count = 0; 1953 1954 // Loop through children and add together forum reply counts 1955 $children = bbp_forum_query_subforum_ids( $forum_id ); 1956 if ( ! empty( $children ) ) { 1957 foreach ( (array) $children as $child ) { 1958 $children_reply_count += bbp_update_forum_reply_count_hidden( $child ); 1959 } 1960 } 1961 1962 // Don't count replies if the forum is a category 1963 $reply_count = ! bbp_is_forum_category( $forum_id ) 1964 ? bbp_get_non_public_child_count( $forum_id, bbp_get_reply_post_type() ) 1965 : 0; 1966 1967 // Calculate total replies in this forum 1968 $total_replies = (int) ( $reply_count + $children_reply_count ); 1969 1970 // Update the counts 1971 update_post_meta( $forum_id, '_bbp_reply_count_hidden', $reply_count ); 1972 update_post_meta( $forum_id, '_bbp_total_reply_count_hidden', $total_replies ); 1973 1974 // Filter & return 1975 return (int) apply_filters( 'bbp_update_forum_reply_count_hidden', $total_replies, $forum_id ); 1747 1976 } 1748 1977 … … 1798 2027 bbp_update_forum_subforum_count( $r['forum_id'] ); 1799 2028 1800 // Only update topic count if we' re deleting a topic, or in the dashboard.1801 if ( in_array( current_filter(), array( 'bbp_delete _topic', 'save_post' ), true ) ) {2029 // Only update topic count if we've deleted a topic 2030 if ( in_array( current_filter(), array( 'bbp_deleted_topic', 'save_post' ), true ) ) { 1802 2031 bbp_update_forum_reply_count( $r['forum_id'] ); 1803 2032 bbp_update_forum_topic_count( $r['forum_id'] ); 1804 2033 bbp_update_forum_topic_count_hidden( $r['forum_id'] ); 2034 bbp_update_forum_reply_count_hidden( $r['forum_id'] ); 1805 2035 } 1806 2036 -
trunk/src/includes/forums/template.php
r6903 r6923 484 484 function bbp_get_forum_last_active_id( $forum_id = 0 ) { 485 485 $forum_id = bbp_get_forum_id( $forum_id ); 486 $active_id = get_post_meta( $forum_id, '_bbp_last_active_id', true );487 488 // Filter & return 489 return (int) apply_filters( 'bbp_get_forum_last_active_id', (int)$active_id, $forum_id );486 $active_id = (int) get_post_meta( $forum_id, '_bbp_last_active_id', true ); 487 488 // Filter & return 489 return (int) apply_filters( 'bbp_get_forum_last_active_id', $active_id, $forum_id ); 490 490 } 491 491 … … 606 606 function bbp_get_forum_parent_id( $forum_id = 0 ) { 607 607 $forum_id = bbp_get_forum_id( $forum_id ); 608 $parent_id = get_post_field( 'post_parent', $forum_id );608 $parent_id = (int) get_post_field( 'post_parent', $forum_id ); 609 609 610 610 // Meta-data fallback 611 611 if ( empty( $parent_id ) ) { 612 $parent_id = get_post_meta( $forum_id, '_bbp_forum_id', true );612 $parent_id = (int) get_post_meta( $forum_id, '_bbp_forum_id', true ); 613 613 } 614 614 615 615 // Filter 616 616 if ( ! empty( $parent_id ) ) { 617 $parent_id = bbp_get_forum_id( $parent_id );618 } 619 620 // Filter & return 621 return (int) apply_filters( 'bbp_get_forum_parent_id', (int)$parent_id, $forum_id );617 $parent_id = (int) bbp_get_forum_id( $parent_id ); 618 } 619 620 // Filter & return 621 return (int) apply_filters( 'bbp_get_forum_parent_id', $parent_id, $forum_id ); 622 622 } 623 623 … … 868 868 function bbp_get_forum_last_topic_id( $forum_id = 0 ) { 869 869 $forum_id = bbp_get_forum_id( $forum_id ); 870 $topic_id = get_post_meta( $forum_id, '_bbp_last_topic_id', true );871 872 // Filter & return 873 return (int) apply_filters( 'bbp_get_forum_last_topic_id', (int)$topic_id, $forum_id );870 $topic_id = (int) get_post_meta( $forum_id, '_bbp_last_topic_id', true ); 871 872 // Filter & return 873 return (int) apply_filters( 'bbp_get_forum_last_topic_id', $topic_id, $forum_id ); 874 874 } 875 875 … … 994 994 function bbp_get_forum_last_reply_id( $forum_id = 0 ) { 995 995 $forum_id = bbp_get_forum_id( $forum_id ); 996 $reply_id = get_post_meta( $forum_id, '_bbp_last_reply_id', true );997 998 // Filter & return 999 return (int) apply_filters( 'bbp_get_forum_last_reply_id', (int)$reply_id, $forum_id );996 $reply_id = (int) get_post_meta( $forum_id, '_bbp_last_reply_id', true ); 997 998 // Filter & return 999 return (int) apply_filters( 'bbp_get_forum_last_reply_id', $reply_id, $forum_id ); 1000 1000 } 1001 1001 … … 1176 1176 1177 1177 // Get deleted topics 1178 $deleted_int = bbp_get_forum_topic_count_hidden( $forum_id, true);1178 $deleted_int = bbp_get_forum_topic_count_hidden( $forum_id, false, true ); 1179 1179 1180 1180 // This forum has hidden topics … … 1182 1182 1183 1183 // Hidden text 1184 $deleted_num = bbp_get_forum_topic_count_hidden( $forum_id, false );1184 $deleted_num = bbp_get_forum_topic_count_hidden( $forum_id, false, false ); 1185 1185 $extra = ' ' . sprintf( _n( '(+%s hidden)', '(+%s hidden)', $deleted_int, 'bbpress' ), $deleted_num ); 1186 1186 … … 1217 1217 function bbp_get_forum_subforum_count( $forum_id = 0, $integer = false ) { 1218 1218 $forum_id = bbp_get_forum_id( $forum_id ); 1219 $forum_count = get_post_meta( $forum_id, '_bbp_forum_subforum_count', true );1219 $forum_count = (int) get_post_meta( $forum_id, '_bbp_forum_subforum_count', true ); 1220 1220 $filter = ( true === $integer ) 1221 1221 ? 'bbp_get_forum_subforum_count_int' … … 1251 1251 $forum_id = bbp_get_forum_id( $forum_id ); 1252 1252 $meta_key = empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count'; 1253 $topics = get_post_meta( $forum_id, $meta_key, true );1253 $topics = (int) get_post_meta( $forum_id, $meta_key, true ); 1254 1254 $filter = ( true === $integer ) 1255 1255 ? 'bbp_get_forum_topic_count_int' … … 1285 1285 $forum_id = bbp_get_forum_id( $forum_id ); 1286 1286 $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count'; 1287 $replies = get_post_meta( $forum_id, $meta_key, true );1287 $replies = (int) get_post_meta( $forum_id, $meta_key, true ); 1288 1288 $filter = ( true === $integer ) 1289 1289 ? 'bbp_get_forum_reply_count_int' … … 1320 1320 $topics = bbp_get_forum_topic_count( $forum_id, $total_count, true ); 1321 1321 $replies = bbp_get_forum_reply_count( $forum_id, $total_count, true ); 1322 $retval = $replies + $topics;1322 $retval = ( $replies + $topics ); 1323 1323 $filter = ( true === $integer ) 1324 1324 ? 'bbp_get_forum_post_count_int' … … 1333 1333 * 1334 1334 * @since 2.0.0 bbPress (r2883) 1335 * 1336 * @param int $forum_id Optional. Topic id 1335 * @since 2.6.0 bbPress (r6922) Changed function signature to add total counts 1336 * 1337 * @param int $forum_id Optional. Forum id 1338 * @param bool $total_count Optional. To get the total count or normal count? 1337 1339 * @param boolean $integer Optional. Whether or not to format the result 1338 1340 */ 1339 function bbp_forum_topic_count_hidden( $forum_id = 0, $ integer = false) {1340 echo bbp_get_forum_topic_count_hidden( $forum_id, $ integer );1341 function bbp_forum_topic_count_hidden( $forum_id = 0, $total_count = true, $integer = null ) { 1342 echo bbp_get_forum_topic_count_hidden( $forum_id, $total_count, $integer ); 1341 1343 } 1342 1344 /** … … 1345 1347 * 1346 1348 * @since 2.0.0 bbPress (r2883) 1347 * 1348 * @param int $forum_id Optional. Topic id 1349 * @since 2.6.0 bbPress (r6922) Changed function signature to add total counts 1350 * 1351 * @param int $forum_id Optional. Forum id 1352 * @param bool $total_count Optional. To get the total count or normal count? 1349 1353 * @param boolean $integer Optional. Whether or not to format the result 1350 1354 * @return int Topic hidden topic count 1351 1355 */ 1352 function bbp_get_forum_topic_count_hidden( $forum_id = 0, $ integer = false) {1356 function bbp_get_forum_topic_count_hidden( $forum_id = 0, $total_count = true, $integer = null ) { 1353 1357 $forum_id = bbp_get_forum_id( $forum_id ); 1354 $topics = get_post_meta( $forum_id, '_bbp_topic_count_hidden', true ); 1358 $meta_key = empty( $total_count ) ? '_bbp_topic_count_hidden' : '_bbp_topic_reply_count_hidden'; 1359 $topics = (int) get_post_meta( $forum_id, $meta_key, true ); 1355 1360 $filter = ( true === $integer ) 1356 1361 ? 'bbp_get_forum_topic_count_hidden_int' … … 1358 1363 1359 1364 return apply_filters( $filter, $topics, $forum_id ); 1365 } 1366 1367 /** 1368 * Output total hidden reply count of a forum (hidden includes trashed, spammed, 1369 * and pending replies) 1370 * 1371 * @since 2.6.0 bbPress (r6922) 1372 * 1373 * @param int $forum_id Optional. Forum id 1374 * @param bool $total_count Optional. To get the total count or normal count? 1375 * @param boolean $integer Optional. Whether or not to format the result 1376 */ 1377 function bbp_forum_reply_count_hidden( $forum_id = 0, $total_count = true, $integer = false ) { 1378 echo bbp_get_forum_reply_count_hidden( $forum_id, $total_count, $integer ); 1379 } 1380 /** 1381 * Return total hidden reply count of a forum (hidden includes trashed, 1382 * spammed and pending replies) 1383 * 1384 * @since 2.6.0 bbPress (r6922) 1385 * 1386 * @param int $forum_id Optional. Forum id 1387 * @param bool $total_count Optional. To get the total count or normal 1388 * count? 1389 * @param boolean $integer Optional. Whether or not to format the result 1390 * @return int Forum reply count 1391 */ 1392 function bbp_get_forum_reply_count_hidden( $forum_id = 0, $total_count = true, $integer = false ) { 1393 $forum_id = bbp_get_forum_id( $forum_id ); 1394 $meta_key = empty( $total_count ) ? '_bbp_reply_count_hidden' : '_bbp_total_reply_count_hidden'; 1395 $replies = (int) get_post_meta( $forum_id, $meta_key, true ); 1396 $filter = ( true === $integer ) 1397 ? 'bbp_get_forum_reply_count_hidden_int' 1398 : 'bbp_get_forum_reply_count_hidden'; 1399 1400 return apply_filters( $filter, $replies, $forum_id ); 1360 1401 } 1361 1402 -
trunk/src/includes/replies/functions.php
r6922 r6923 27 27 $reply_data = bbp_parse_args( $reply_data, array( 28 28 'post_parent' => 0, // topic ID 29 'post_status' => bbp_get_public_status_id(),30 29 'post_type' => bbp_get_reply_post_type(), 31 30 'post_author' => bbp_get_current_user_id(), … … 36 35 'comment_status' => 'closed' 37 36 ), 'insert_reply' ); 37 38 // Possibly override status based on parent topic 39 if ( ! empty( $reply_data['post_parent'] ) && empty( $reply_data['post_status'] ) ) { 40 $reply_data['post_status'] = bbp_get_topic_status( $reply_data['post_parent'] ); 41 } 38 42 39 43 // Insert reply … … 96 100 function bbp_insert_reply_update_counts( $reply_id = 0, $topic_id = 0, $forum_id = 0 ) { 97 101 98 // If the reply is public, update the forum/topicreply counts.102 // If the reply is public, update the reply counts. 99 103 if ( bbp_is_reply_published( $reply_id ) ) { 100 104 bbp_increase_topic_reply_count( $topic_id ); 101 105 bbp_increase_forum_reply_count( $forum_id ); 102 106 103 // If the reply isn't public only update the topic reply hidden count.107 // If the reply isn't public only update the reply hidden counts. 104 108 } else { 105 109 bbp_increase_topic_reply_count_hidden( $topic_id ); 110 bbp_increase_forum_reply_count_hidden( $forum_id ); 106 111 } 107 112 } … … 315 320 316 321 // Maybe put into moderation 317 if ( ! bbp_check_for_moderation( $anonymous_data, $reply_author, $reply_title, $reply_content ) ) {322 if ( bbp_is_topic_pending( $topic_id ) || ! bbp_check_for_moderation( $anonymous_data, $reply_author, $reply_title, $reply_content ) ) { 318 323 $reply_status = bbp_get_pending_status_id(); 319 324 … … 920 925 } elseif ( bbp_is_topic( $ancestor ) ) { 921 926 922 // Last reply and active ID's 923 bbp_update_topic_last_reply_id ( $ancestor, $reply_id ); 924 bbp_update_topic_last_active_id( $ancestor, $active_id ); 925 926 // Get the last active time if none was passed 927 $topic_last_active_time = $last_active_time; 928 if ( empty( $last_active_time ) ) { 929 $topic_last_active_time = get_post_field( 'post_date', bbp_get_topic_last_active_id( $ancestor ) ); 927 // Only update if reply is published 928 if ( ! bbp_is_reply_pending( $reply_id ) ) { 929 930 // Last reply and active ID's 931 bbp_update_topic_last_reply_id ( $ancestor, $reply_id ); 932 bbp_update_topic_last_active_id( $ancestor, $active_id ); 933 934 // Get the last active time if none was passed 935 $topic_last_active_time = $last_active_time; 936 if ( empty( $last_active_time ) ) { 937 $topic_last_active_time = get_post_field( 'post_date', bbp_get_topic_last_active_id( $ancestor ) ); 938 } 939 940 bbp_update_topic_last_active_time( $ancestor, $topic_last_active_time ); 930 941 } 931 942 932 // Update the topic last active time regardless of reply status. 933 // See https://bbpress.trac.wordpress.org/ticket/2838 934 bbp_update_topic_last_active_time( $ancestor, $topic_last_active_time ); 935 936 // Only update reply count if we're deleting a reply, or in the dashboard. 943 // Only update reply count if we've deleted a reply 937 944 if ( in_array( current_filter(), array( 'bbp_deleted_reply', 'save_post' ), true ) ) { 938 945 bbp_update_topic_reply_count( $ancestor ); … … 944 951 } elseif ( bbp_is_forum( $ancestor ) ) { 945 952 946 // Last topic and reply ID's947 bbp_update_forum_last_topic_id( $ancestor, $topic_id );948 bbp_update_forum_last_reply_id( $ancestor, $reply_id );949 950 // Last Active951 bbp_update_forum_last_active_id( $ancestor, $active_id );952 953 // Get the last active time if none was passed954 $forum_last_active_time = $last_active_time;955 if ( empty( $last_active_time ) ) {956 $forum_last_active_time = get_post_field( 'post_date', bbp_get_forum_last_active_id( $ancestor ) );957 }958 959 953 // Only update if reply is published 960 if ( bbp_is_reply_published( $reply_id ) ) { 954 if ( bbp_is_reply_pending( $reply_id ) && ! bbp_is_topic_pending( $topic_id ) ) { 955 956 // Last topic and reply ID's 957 bbp_update_forum_last_topic_id( $ancestor, $topic_id ); 958 bbp_update_forum_last_reply_id( $ancestor, $reply_id ); 959 960 // Last Active 961 bbp_update_forum_last_active_id( $ancestor, $active_id ); 962 963 // Get the last active time if none was passed 964 $forum_last_active_time = $last_active_time; 965 if ( empty( $last_active_time ) ) { 966 $forum_last_active_time = get_post_field( 'post_date', bbp_get_forum_last_active_id( $ancestor ) ); 967 } 968 961 969 bbp_update_forum_last_active_time( $ancestor, $forum_last_active_time ); 962 970 } 963 971 964 // Counts 965 // Only update reply count if we're deleting a reply, or in the dashboard. 972 // Only update reply count if we've deleted a reply 966 973 if ( in_array( current_filter(), array( 'bbp_deleted_reply', 'save_post' ), true ) ) { 967 974 bbp_update_forum_reply_count( $ancestor ); -
trunk/src/includes/replies/template.php
r6922 r6923 436 436 437 437 // Set needed variables 438 $reply_id = bbp_get_reply_id ( $reply_id ); 439 $topic_id = bbp_get_reply_topic_id( $reply_id ); 438 $reply_id = bbp_get_reply_id( $reply_id ); 439 440 // Juggle reply & topic IDs for unpretty URL formatting 441 if ( bbp_is_reply( $reply_id ) ) { 442 $topic_id = bbp_get_reply_topic_id( $reply_id ); 443 } elseif ( bbp_is_topic( $reply_id ) ) { 444 $topic_id = bbp_get_topic_id( $reply_id ); 445 $reply_id = $topic_id; 446 } 440 447 441 448 // Hierarchical reply page … … 448 455 } 449 456 457 // Get links & URLS 450 458 $reply_hash = '#post-' . $reply_id; 451 459 $topic_link = bbp_get_topic_permalink( $topic_id, $redirect_to ); 452 460 $topic_url = remove_query_arg( 'view', $topic_link ); 453 461 462 // Get vars needed to support pending topics with unpretty links 463 $has_slug = bbp_get_topic( $topic_id )->post_name; 464 $pretty = bbp_use_pretty_urls(); 465 $published = ! bbp_is_topic_pending( $topic_id ); 466 454 467 // Don't include pagination if on first page 455 468 if ( 1 >= $reply_page ) { 456 $url = user_trailingslashit( $topic_url ) . $reply_hash; 469 470 // Pretty permalinks 471 if ( ! empty( $has_slug ) && ! empty( $pretty ) && ! empty( $published ) ) { 472 $url = user_trailingslashit( $topic_url ) . $reply_hash; 473 474 // Unpretty links 475 } else { 476 $url = $topic_url . $reply_hash; 477 } 457 478 458 479 // Include pagination … … 460 481 461 482 // Pretty permalinks 462 if ( bbp_use_pretty_urls() ) {483 if ( ! empty( $has_slug ) && ! empty( $pretty ) && ! empty( $published ) ) { 463 484 $url = trailingslashit( $topic_url ) . trailingslashit( bbp_get_paged_slug() ) . $reply_page; 464 485 $url = user_trailingslashit( $url ) . $reply_hash; 465 486 466 // Yucky links487 // Unpretty links 467 488 } else { 468 489 $url = add_query_arg( 'paged', $reply_page, $topic_url ) . $reply_hash; … … 762 783 $reply_id = bbp_get_reply_id( $reply_id ); 763 784 $revision_log = get_post_meta( $reply_id, '_bbp_revision_log', true ); 764 $revision_log = empty( $revision_log ) ? array() : $revision_log; 785 $revision_log = ! empty( $revision_log ) 786 ? $revision_log 787 : array(); 765 788 766 789 // Filter & return … … 852 875 * 853 876 * @since 2.0.0 bbPress (r3496) 877 * @since 2.6.0 bbPress (r6922) Returns false if topic is also not published 854 878 * 855 879 * @param int $reply_id Optional. Topic id … … 858 882 function bbp_is_reply_published( $reply_id = 0 ) { 859 883 $reply_id = bbp_get_reply_id( $reply_id ); 884 $topic_id = bbp_get_reply_topic_id( $reply_id ); 860 885 $status = bbp_get_public_status_id(); 861 $reply_status = bbp_get_reply_status( $reply_id ) === $status; 886 $topic_status = bbp_is_topic_published( $topic_id ); 887 $reply_status = ( bbp_get_reply_status( $reply_id ) === $status ); 888 $retval = ( $reply_status && $topic_status ); 862 889 863 890 // Filter & return 864 return (bool) apply_filters( 'bbp_is_reply_published', (bool) $re ply_status, $reply_id );891 return (bool) apply_filters( 'bbp_is_reply_published', (bool) $retval, $reply_id ); 865 892 } 866 893 … … 1396 1423 function bbp_get_reply_topic_id( $reply_id = 0 ) { 1397 1424 $reply_id = bbp_get_reply_id( $reply_id ); 1398 $topic_id = get_post_field( 'post_parent', $reply_id );1425 $topic_id = (int) get_post_field( 'post_parent', $reply_id ); 1399 1426 1400 1427 // Meta-data fallback 1401 1428 if ( empty( $topic_id ) ) { 1402 $topic_id = get_post_meta( $reply_id, '_bbp_topic_id', true );1429 $topic_id = (int) get_post_meta( $reply_id, '_bbp_topic_id', true ); 1403 1430 } 1404 1431 1405 1432 // Filter 1406 1433 if ( ! empty( $topic_id ) ) { 1407 $topic_id = bbp_get_topic_id( $topic_id );1408 } 1409 1410 // Filter & return 1411 return (int) apply_filters( 'bbp_get_reply_topic_id', (int)$topic_id, $reply_id );1434 $topic_id = (int) bbp_get_topic_id( $topic_id ); 1435 } 1436 1437 // Filter & return 1438 return (int) apply_filters( 'bbp_get_reply_topic_id', $topic_id, $reply_id ); 1412 1439 } 1413 1440 … … 1433 1460 function bbp_get_reply_forum_id( $reply_id = 0 ) { 1434 1461 $reply_id = bbp_get_reply_id( $reply_id ); 1435 $forum_id = get_post_field( 'post_parent', bbp_get_reply_topic_id( $reply_id ) ); 1462 $topic_id = bbp_get_reply_topic_id( $reply_id ); 1463 $forum_id = (int) get_post_field( 'post_parent', $topic_id ); 1436 1464 1437 1465 // Meta-data fallback 1438 1466 if ( empty( $forum_id ) ) { 1439 $forum_id = get_post_meta( $reply_id, '_bbp_forum_id', true );1467 $forum_id = (int) get_post_meta( $reply_id, '_bbp_forum_id', true ); 1440 1468 } 1441 1469 1442 1470 // Filter 1443 1471 if ( ! empty( $forum_id ) ) { 1444 $forum_id = bbp_get_forum_id( $forum_id );1472 $forum_id = (int) bbp_get_forum_id( $forum_id ); 1445 1473 } 1446 1474 … … 2272 2300 2273 2301 // If pretty permalinks are enabled, make our pagination pretty 2274 if ( bbp_use_pretty_urls() ) {2302 if ( bbp_use_pretty_urls() && ! bbp_is_topic_pending( $topic_id )) { 2275 2303 2276 2304 // User's replies -
trunk/src/includes/topics/functions.php
r6922 r6923 844 844 /** 845 845 * Walks up the post_parent tree from the current topic_id, and updates the 846 * counts of forums above it. This calls a few internal functions that all run846 * meta data of forums above it. This calls several functions that all run 847 847 * manual queries against the database to get their results. As such, this 848 848 * function can be costly to run but is necessary to keep everything accurate. … … 994 994 $old_forum_ancestors = array_values( array_unique( array_merge( array( $old_forum_id ), (array) get_post_ancestors( $old_forum_id ) ) ) ); 995 995 996 // Get reply count. 997 $public_reply_count = bbp_get_public_child_count( $topic_id, bbp_get_reply_post_type() ); 998 999 // Topic status. 1000 $topic_status = get_post_field( 'post_status', $topic_id ); 1001 1002 // Update old/new forum counts. 1003 if ( $topic_status === bbp_get_public_status_id() ) { 996 // Public counts 997 if ( bbp_is_topic_public( $topic_id ) ) { 1004 998 1005 999 // Update old forum counts. 1006 1000 bbp_decrease_forum_topic_count( $old_forum_id ); 1007 bbp_bump_forum_reply_count( $old_forum_id, -$public_reply_count );1008 1001 1009 1002 // Update new forum counts. 1010 1003 bbp_increase_forum_topic_count( $new_forum_id ); 1011 bbp_bump_forum_reply_count( $new_forum_id, $public_reply_count ); 1004 1005 // Non-public counts 1012 1006 } else { 1013 1007 … … 1018 1012 bbp_increase_forum_topic_count_hidden( $new_forum_id ); 1019 1013 } 1014 1015 // Get reply counts. 1016 $public_reply_count = bbp_get_public_child_count( $topic_id, bbp_get_reply_post_type() ); 1017 $hidden_reply_count = bbp_get_non_public_child_count( $topic_id, bbp_get_reply_post_type() ); 1018 1019 // Bump reply counts. 1020 bbp_bump_forum_reply_count( $old_forum_id, -$public_reply_count ); 1021 bbp_bump_forum_reply_count( $new_forum_id, $public_reply_count ); 1022 bbp_bump_forum_reply_count_hidden( $old_forum_id, -$hidden_reply_count ); 1023 bbp_bump_forum_reply_count_hidden( $new_forum_id, $hidden_reply_count ); 1020 1024 1021 1025 // Loop through ancestors and update them … … 2319 2323 $topic_id = bbp_get_reply_topic_id( $reply_id ); 2320 2324 2321 // If this is a new, unpublished, reply, update hidden count and bail.2322 if ( ! bbp_is_reply_publi shed( $reply_id ) ) {2325 // Update inverse based on item status 2326 if ( ! bbp_is_reply_public( $reply_id ) ) { 2323 2327 bbp_increase_topic_reply_count_hidden( $topic_id ); 2324 2328 return; … … 2326 2330 } 2327 2331 2332 // Bump up 2328 2333 bbp_bump_topic_reply_count( $topic_id ); 2329 2334 } … … 2347 2352 // If it's a reply, get the topic id. 2348 2353 if ( bbp_is_reply( $topic_id ) ) { 2349 $topic_id = bbp_get_reply_topic_id( $topic_id ); 2350 } 2351 2354 $reply_id = $topic_id; 2355 $topic_id = bbp_get_reply_topic_id( $reply_id ); 2356 2357 // Update inverse based on item status 2358 if ( ! bbp_is_reply_public( $reply_id ) ) { 2359 bbp_decrease_topic_reply_count_hidden( $topic_id ); 2360 return; 2361 } 2362 } 2363 2364 // Bump down 2352 2365 bbp_bump_topic_reply_count( $topic_id, -1 ); 2353 2366 } … … 2400 2413 // If it's a reply, get the topic id. 2401 2414 if ( bbp_is_reply( $topic_id ) ) { 2402 $topic_id = bbp_get_reply_topic_id( $topic_id ); 2403 } 2404 2415 $reply_id = $topic_id; 2416 $topic_id = bbp_get_reply_topic_id( $reply_id ); 2417 2418 // Update inverse based on item status 2419 if ( bbp_is_reply_public( $reply_id ) ) { 2420 bbp_increase_topic_reply_count( $topic_id ); 2421 return; 2422 } 2423 } 2424 2425 // Bump up 2405 2426 bbp_bump_topic_reply_count_hidden( $topic_id ); 2406 2427 } … … 2424 2445 // If it's a reply, get the topic id. 2425 2446 if ( bbp_is_reply( $topic_id ) ) { 2426 $topic_id = bbp_get_reply_topic_id( $topic_id ); 2427 } 2428 2447 $reply_id = $topic_id; 2448 $topic_id = bbp_get_reply_topic_id( $reply_id ); 2449 2450 // Update inverse based on item status 2451 if ( bbp_is_reply_public( $reply_id ) ) { 2452 bbp_decrease_topic_reply_count( $topic_id ); 2453 return; 2454 } 2455 } 2456 2457 // Bump down 2429 2458 bbp_bump_topic_reply_count_hidden( $topic_id, -1 ); 2430 2459 } … … 2509 2538 * @return int Topic reply count 2510 2539 */ 2511 function bbp_update_topic_reply_count( $topic_id = 0, $reply_count = 0) {2540 function bbp_update_topic_reply_count( $topic_id = 0, $reply_count = false ) { 2512 2541 2513 2542 // If it's a reply, then get the parent (topic id) … … 2517 2546 2518 2547 // Get replies of topic if not passed 2519 $reply_count = empty( $reply_count )2548 $reply_count = ! is_int( $reply_count ) 2520 2549 ? bbp_get_public_child_count( $topic_id, bbp_get_reply_post_type() ) 2521 2550 : (int) $reply_count; … … 2537 2566 * @return int Topic hidden reply count 2538 2567 */ 2539 function bbp_update_topic_reply_count_hidden( $topic_id = 0, $reply_count = 0) {2568 function bbp_update_topic_reply_count_hidden( $topic_id = 0, $reply_count = false ) { 2540 2569 2541 2570 // If it's a reply, then get the parent (topic id) … … 2545 2574 2546 2575 // Get replies of topic 2547 $reply_count = empty( $reply_count )2576 $reply_count = ! is_int( $reply_count ) 2548 2577 ? bbp_get_non_public_child_count( $topic_id, bbp_get_reply_post_type() ) 2549 2578 : (int) $reply_count; … … 2584 2613 2585 2614 // Update only if published 2586 if ( bbp_get_public_status_id() === get_post_status( $active_id ) ) { 2587 update_post_meta( $topic_id, '_bbp_last_active_id', $active_id ); 2588 } 2615 update_post_meta( $topic_id, '_bbp_last_active_id', $active_id ); 2589 2616 2590 2617 // Filter & return … … 2654 2681 2655 2682 // Update if reply is published 2656 if ( bbp_is_reply_published( $reply_id ) ) { 2657 update_post_meta( $topic_id, '_bbp_last_reply_id', $reply_id ); 2658 } 2683 update_post_meta( $topic_id, '_bbp_last_reply_id', $reply_id ); 2659 2684 2660 2685 // Filter & return -
trunk/src/includes/topics/template.php
r6922 r6923 805 805 ), 'get_topic_pagination' ); 806 806 807 // Slug must be checked for topics that have never been approved/published 808 $has_slug = bbp_get_topic( $r['topic_id'] )->post_name; 809 807 810 // If pretty permalinks are enabled, make our pagination pretty 808 $base = bbp_use_pretty_urls()811 $base = ! empty( $has_slug ) && bbp_use_pretty_urls() && ! bbp_is_topic_pending( $r['topic_id'] ) 809 812 ? trailingslashit( get_permalink( $r['topic_id'] ) ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' ) 810 813 : add_query_arg( 'paged', '%#%', get_permalink( $r['topic_id'] ) ); … … 947 950 948 951 $revision_log = get_post_meta( $topic_id, '_bbp_revision_log', true ); 949 $revision_log = empty( $revision_log ) ? array() : $revision_log; 952 $revision_log = ! empty( $revision_log ) 953 ? $revision_log 954 : array(); 950 955 951 956 // Filter & return … … 1658 1663 function bbp_get_topic_forum_id( $topic_id = 0 ) { 1659 1664 $topic_id = bbp_get_topic_id( $topic_id ); 1660 $forum_id = get_post_field( 'post_parent', $topic_id );1665 $forum_id = (int) get_post_field( 'post_parent', $topic_id ); 1661 1666 1662 1667 // Meta-data fallback 1663 1668 if ( empty( $forum_id ) ) { 1664 $forum_id = get_post_meta( $topic_id, '_bbp_forum_id', true );1669 $forum_id = (int) get_post_meta( $topic_id, '_bbp_forum_id', true ); 1665 1670 } 1666 1671 1667 1672 // Filter 1668 1673 if ( ! empty( $forum_id ) ) { 1669 $forum_id = bbp_get_forum_id( $forum_id );1670 } 1671 1672 // Filter & return 1673 return (int) apply_filters( 'bbp_get_topic_forum_id', (int)$forum_id, $topic_id );1674 $forum_id = (int) bbp_get_forum_id( $forum_id ); 1675 } 1676 1677 // Filter & return 1678 return (int) apply_filters( 'bbp_get_topic_forum_id', $forum_id, $topic_id ); 1674 1679 } 1675 1680 … … 1694 1699 function bbp_get_topic_last_active_id( $topic_id = 0 ) { 1695 1700 $topic_id = bbp_get_topic_id( $topic_id ); 1696 $active_id = get_post_meta( $topic_id, '_bbp_last_active_id', true );1697 1698 // Filter & return 1699 return (int) apply_filters( 'bbp_get_topic_last_active_id', (int)$active_id, $topic_id );1701 $active_id = (int) get_post_meta( $topic_id, '_bbp_last_active_id', true ); 1702 1703 // Filter & return 1704 return (int) apply_filters( 'bbp_get_topic_last_active_id', $active_id, $topic_id ); 1700 1705 } 1701 1706 … … 1856 1861 function bbp_get_topic_last_reply_id( $topic_id = 0 ) { 1857 1862 $topic_id = bbp_get_topic_id( $topic_id ); 1858 $reply_id = get_post_meta( $topic_id, '_bbp_last_reply_id', true );1859 1860 // Filter & return 1861 return (int) apply_filters( 'bbp_get_topic_last_reply_id', (int)$reply_id, $topic_id );1863 $reply_id = (int) get_post_meta( $topic_id, '_bbp_last_reply_id', true ); 1864 1865 // Filter & return 1866 return (int) apply_filters( 'bbp_get_topic_last_reply_id', $reply_id, $topic_id ); 1862 1867 } 1863 1868 … … 2058 2063 function bbp_get_topic_reply_count( $topic_id = 0, $integer = false ) { 2059 2064 $topic_id = bbp_get_topic_id( $topic_id ); 2060 $replies = get_post_meta( $topic_id, '_bbp_reply_count', true );2065 $replies = (int) get_post_meta( $topic_id, '_bbp_reply_count', true ); 2061 2066 $filter = ( true === $integer ) 2062 2067 ? 'bbp_get_topic_reply_count_int' … … 2088 2093 function bbp_get_topic_post_count( $topic_id = 0, $integer = false ) { 2089 2094 $topic_id = bbp_get_topic_id( $topic_id ); 2090 $replies = get_post_meta( $topic_id, '_bbp_reply_count', true) + 1;2095 $replies = ( (int) get_post_meta( $topic_id, '_bbp_reply_count', true ) ) + 1; 2091 2096 $filter = ( true === $integer ) 2092 2097 ? 'bbp_get_topic_post_count_int' … … 2120 2125 function bbp_get_topic_reply_count_hidden( $topic_id = 0, $integer = false ) { 2121 2126 $topic_id = bbp_get_topic_id( $topic_id ); 2122 $replies = get_post_meta( $topic_id, '_bbp_reply_count_hidden', true );2127 $replies = (int) get_post_meta( $topic_id, '_bbp_reply_count_hidden', true ); 2123 2128 $filter = ( true === $integer ) 2124 2129 ? 'bbp_get_topic_reply_count_hidden_int' … … 2148 2153 function bbp_get_topic_voice_count( $topic_id = 0, $integer = false ) { 2149 2154 $topic_id = bbp_get_topic_id( $topic_id ); 2150 $voices = get_post_meta( $topic_id, '_bbp_voice_count', true );2155 $voices = (int) get_post_meta( $topic_id, '_bbp_voice_count', true ); 2151 2156 $filter = ( true === $integer ) 2152 2157 ? 'bbp_get_topic_voice_count_int' … … 2343 2348 // See if links need to be unset 2344 2349 $topic_status = bbp_get_topic_status( $r['id'] ); 2345 if ( in_array( $topic_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id(), bbp_get_pending_status_id() )) ) {2350 if ( in_array( $topic_status, bbp_get_non_public_topic_statuses(), true ) ) { 2346 2351 2347 2352 // Close link shouldn't be visible on trashed/spammed/pending topics -
trunk/src/includes/users/engagements.php
r6876 r6923 417 417 // Is a topic 418 418 } elseif ( bbp_is_topic( $topic_id ) ) { 419 420 // Bail if topic isn't published 421 if ( ! bbp_is_topic_published( $topic_id ) ) { 422 return; 423 } 424 419 425 $author_id = bbp_get_topic_author_id( $topic_id ); 420 426 $topic_id = bbp_get_topic_id( $topic_id );
Note: See TracChangeset
for help on using the changeset viewer.