Changeset 6923 for trunk/src/includes/topics/functions.php
- Timestamp:
- 11/09/2019 05:35:42 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.