Skip to:
Content

bbPress.org

Changeset 6923


Ignore:
Timestamp:
11/09/2019 05:35:42 AM (2 years ago)
Author:
johnjamesjacoby
Message:

Counts (meta-data): full audit of forum/topic/reply, public/non-public counts.

This commit is the result of a full count audit, exposing multiple inconsistencies and voids in relation to how public and non-public counts are (re)calculated.

For instance, hidden forum replies are not counted at all, until now. By introducing a new Repair tool, hidden forum reply counts are now counted.

In addition, there were multiple bugs with topic & reply moderation, where the act of approving or unapproving topics or replies would cause the numbers to be inaccurate, or where topics & replies being caught in moderation were still increasing public counts.

It was also possible to, as a Key Master, publicly reply to unapproved topics, which was a completely unanticipated side-effect of allowing Key Masters to do pretty much anything. Going forward, the default reply status is the topic status, but is still beholden to all existing moderation settings and user role capabilities. This results in a more sane user experience, and prevents the unusual circumstance of there being "0 topics and 30 replies" in public-facing forums.

Certain count increase/decrease actions have been reprioritized to avoid collisions and race conditions, proving once again that ya gotta get up to get down.

See #2838. Fixes #1799.

Location:
trunk/src/includes
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/tools.php

    r6897 r6923  
    241241    ) );
    242242
     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
    243255    // Count topic replies
    244256    bbp_register_repair_tool( array(
     
    248260        'description' => esc_html__( 'Run this if the number of topics in any topics are incorrect.', 'bbpress' ),
    249261        'callback'    => 'bbp_admin_repair_topic_reply_count',
    250         'priority'    => 60,
     262        'priority'    => 65,
    251263        'overhead'    => 'high',
    252264        'components'  => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() )
     
    258270        'type'        => 'repair',
    259271        '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' ),
    261273        'callback'    => 'bbp_admin_repair_topic_hidden_reply_count',
    262         'priority'    => 65,
     274        'priority'    => 70,
    263275        'overhead'    => 'high',
    264276        'components'  => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() )
     
    272284        'description' => esc_html__( 'Run this to get fresh topic counts for all users.', 'bbpress' ),
    273285        'callback'    => 'bbp_admin_repair_user_topic_count',
    274         'priority'    => 70,
     286        'priority'    => 75,
    275287        'overhead'    => 'medium',
    276288        'components'  => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() )
     
    284296        'description' => esc_html__( 'Run this to get fresh reply counts for all users.', 'bbpress' ),
    285297        'callback'    => 'bbp_admin_repair_user_reply_count',
    286         'priority'    => 75,
     298        'priority'    => 80,
    287299        'overhead'    => 'medium',
    288300        'components'  => array( bbp_get_reply_post_type(), bbp_get_user_rewrite_id() )
     
    296308        'description' => esc_html__( 'Run this to remove trashed or deleted topics from all user favorites.', 'bbpress' ),
    297309        'callback'    => 'bbp_admin_repair_user_favorites',
    298         'priority'    => 80,
     310        'priority'    => 85,
    299311        'overhead'    => 'medium',
    300312        'components'  => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() )
     
    308320        'description' => esc_html__( 'Run this to remove trashed or deleted topics from all user subscriptions.', 'bbpress' ),
    309321        'callback'    => 'bbp_admin_repair_user_topic_subscriptions',
    310         'priority'    => 85,
     322        'priority'    => 90,
    311323        'overhead'    => 'medium',
    312324        'components'  => array( bbp_get_topic_post_type(), bbp_get_user_rewrite_id() )
     
    320332        'description' => esc_html__( 'Run this to remove trashed or deleted forums from all user subscriptions.', 'bbpress' ),
    321333        'callback'    => 'bbp_admin_repair_user_forum_subscriptions',
    322         'priority'    => 90,
     334        'priority'    => 95,
    323335        'overhead'    => 'medium',
    324336        'components'  => array( bbp_get_forum_post_type(), bbp_get_user_rewrite_id() )
     
    332344        'description' => esc_html__( 'Run this if users have issues accessing the forums.', 'bbpress' ),
    333345        'callback'    => 'bbp_admin_repair_user_roles',
    334         'priority'    => 95,
     346        'priority'    => 100,
    335347        'overhead'    => 'low',
    336348        'components'  => array( bbp_get_user_rewrite_id() )
     
    344356        'description' => esc_html__( 'Copies engagements from user meta to topic meta.', 'bbpress' ),
    345357        'callback'    => 'bbp_admin_upgrade_user_engagements',
    346         'priority'    => 100,
     358        'priority'    => 105,
    347359        'version'     => '2.6.0',
    348360        'overhead'    => 'high',
     
    357369        'description' => esc_html__( 'Copies favorites from user meta to topic meta.', 'bbpress' ),
    358370        'callback'    => 'bbp_admin_upgrade_user_favorites',
    359         'priority'    => 105,
     371        'priority'    => 110,
    360372        'version'     => '2.6.0',
    361373        'overhead'    => 'high',
     
    370382        'description' => esc_html__( 'Copies topic subscriptions from user meta to topic meta.', 'bbpress' ),
    371383        'callback'    => 'bbp_admin_upgrade_user_topic_subscriptions',
    372         'priority'    => 110,
     384        'priority'    => 115,
    373385        'version'     => '2.6.0',
    374386        'overhead'    => 'high',
     
    383395        'description' => esc_html__( 'Copies forum subscriptions from user meta to forum meta.', 'bbpress' ),
    384396        'callback'    => 'bbp_admin_upgrade_user_forum_subscriptions',
    385         'priority'    => 115,
     397        'priority'    => 120,
    386398        'version'     => '2.6.0',
    387399        'overhead'    => 'high',
     
    396408        'description' => esc_html__( 'Run this to delete old data (after confirming successful favorites upgrade)', 'bbpress' ),
    397409        'callback'    => 'bbp_admin_upgrade_remove_favorites_from_usermeta',
    398         'priority'    => 120,
     410        'priority'    => 125,
    399411        'version'     => '2.6.1',
    400412        'overhead'    => 'medium',
     
    409421        'description' => esc_html__( 'Run this to delete old data (after confirming successful topic subscriptions upgrade)', 'bbpress' ),
    410422        'callback'    => 'bbp_admin_upgrade_remove_topic_subscriptions_from_usermeta',
    411         'priority'    => 125,
     423        'priority'    => 130,
    412424        'version'     => '2.6.1',
    413425        'overhead'    => 'medium',
     
    422434        'description' => esc_html__( 'Run this to delete old data (after confirming successful forum subscriptions upgrade)', 'bbpress' ),
    423435        'callback'    => 'bbp_admin_upgrade_remove_forum_subscriptions_from_usermeta',
    424         'priority'    => 130,
     436        'priority'    => 135,
    425437        'version'     => '2.6.1',
    426438        'overhead'    => 'medium',
     
    435447        'description' => esc_html__( 'Run this if you just upgraded BuddyPress Forums from Legacy.', 'bbpress' ),
    436448        'callback'    => 'bbp_admin_upgrade_group_forum_relationship',
    437         'priority'    => 135,
     449        'priority'    => 140,
    438450        'overhead'    => 'low',
    439451        'components'  => array( bbp_get_forum_post_type() )
  • trunk/src/includes/admin/tools/repair.php

    r6908 r6923  
    263263
    264264/**
    265  * Recount topic hidden replies (spammed/trashed)
     265 * Recount non-public replies per topic (pending/spammed/trashed)
    266266 *
    267267 * @since 2.0.0 bbPress (r2747)
     
    405405        foreach ( $forums as $forum ) {
    406406            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 */
     422function 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 );
    407448        }
    408449    } else {
  • trunk/src/includes/common/functions.php

    r6922 r6923  
    16641664    }
    16651665
    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;
    16721684    }
    16731685
     
    18231835        // Forum
    18241836        case bbp_get_forum_post_type() :
    1825             $post_status = array( bbp_get_public_status_id() );
     1837            $post_status = bbp_get_public_forum_statuses();
    18261838            break;
    18271839
  • trunk/src/includes/core/actions.php

    r6915 r6923  
    231231
    232232// 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 );
     233add_action( 'bbp_spam_topic',   'bbp_remove_topic_from_all_subscriptions' );
     234add_action( 'bbp_trash_topic',  'bbp_remove_topic_from_all_subscriptions' );
     235add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions' );
     236add_action( 'bbp_trash_forum',  'bbp_remove_forum_from_all_subscriptions' );
     237add_action( 'bbp_delete_forum', 'bbp_remove_forum_from_all_subscriptions' );
     238
     239// Subscription notifications
     240add_action( 'bbp_new_reply',    'bbp_notify_topic_subscribers', 11, 5 );
     241add_action( 'bbp_new_topic',    'bbp_notify_forum_subscribers', 11, 4 );
    240242
    241243// Sticky
     
    264266add_action( 'bbp_unapproved_reply', 'bbp_update_reply_walker' );
    265267
    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
     269add_action( 'bbp_new_reply',        'bbp_increase_forum_reply_count' );
     270add_action( 'bbp_untrashed_reply',  'bbp_increase_forum_reply_count' );
     271add_action( 'bbp_unspammed_reply',  'bbp_increase_forum_reply_count' );
     272add_action( 'bbp_approved_reply',   'bbp_increase_forum_reply_count' );
     273add_action( 'bbp_trash_reply',      'bbp_decrease_forum_reply_count' );
     274add_action( 'bbp_spam_reply',       'bbp_decrease_forum_reply_count' );
     275add_action( 'bbp_unapprove_reply',  'bbp_decrease_forum_reply_count' );
     276
     277// Update forum hidden reply counts
     278add_action( 'bbp_trashed_reply',    'bbp_increase_forum_reply_count_hidden' );
     279add_action( 'bbp_spammed_reply',    'bbp_increase_forum_reply_count_hidden' );
     280add_action( 'bbp_unapproved_reply', 'bbp_increase_forum_reply_count_hidden' );
     281add_action( 'bbp_untrash_reply',    'bbp_decrease_forum_reply_count_hidden' );
     282add_action( 'bbp_unspam_reply',     'bbp_decrease_forum_reply_count_hidden' );
     283add_action( 'bbp_approve_reply',    'bbp_decrease_forum_reply_count_hidden' );
     284add_action( 'bbp_delete_reply',     'bbp_decrease_forum_reply_count_hidden' );
     285
     286// Update forum topic counts
     287add_action( 'bbp_new_topic',        'bbp_increase_forum_topic_count' );
     288add_action( 'bbp_untrashed_topic',  'bbp_increase_forum_topic_count' );
     289add_action( 'bbp_unspammed_topic',  'bbp_increase_forum_topic_count' );
     290add_action( 'bbp_approved_topic',   'bbp_increase_forum_topic_count' );
     291add_action( 'bbp_trash_topic',      'bbp_decrease_forum_topic_count' );
     292add_action( 'bbp_spam_topic',       'bbp_decrease_forum_topic_count' );
     293add_action( 'bbp_unapprove_topic',  'bbp_decrease_forum_topic_count' );
     294
     295// Update forum hidden topic counts
    281296add_action( 'bbp_trashed_topic',    'bbp_increase_forum_topic_count_hidden' );
    282 add_action( 'bbp_untrashed_topic',  'bbp_decrease_forum_topic_count_hidden' );
    283297add_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' );
    286298add_action( 'bbp_unapproved_topic', 'bbp_increase_forum_topic_count_hidden' );
    287 
    288 // Update forum reply counts for approved/unapproved topics.
     299add_action( 'bbp_untrash_topic',    'bbp_decrease_forum_topic_count_hidden' );
     300add_action( 'bbp_unspam_topic',     'bbp_decrease_forum_topic_count_hidden' );
     301add_action( 'bbp_approve_topic',    'bbp_decrease_forum_topic_count_hidden' );
     302add_action( 'bbp_delete_topic',     'bbp_decrease_forum_topic_count_hidden' );
     303
     304// Update topic reply counts
     305add_action( 'bbp_new_reply',        'bbp_increase_topic_reply_count' );
     306add_action( 'bbp_untrashed_reply',  'bbp_increase_topic_reply_count' );
     307add_action( 'bbp_unspammed_reply',  'bbp_increase_topic_reply_count' );
     308add_action( 'bbp_approved_reply',   'bbp_increase_topic_reply_count' );
     309add_action( 'bbp_trash_reply',      'bbp_decrease_topic_reply_count' );
     310add_action( 'bbp_spam_reply',       'bbp_decrease_topic_reply_count' );
     311add_action( 'bbp_unapprove_reply',  'bbp_decrease_topic_reply_count' );
     312
     313// Update topic hidden reply counts
     314add_action( 'bbp_trashed_reply',    'bbp_increase_topic_reply_count_hidden' );
     315add_action( 'bbp_unapproved_reply', 'bbp_increase_topic_reply_count_hidden' );
     316add_action( 'bbp_spammed_reply',    'bbp_increase_topic_reply_count_hidden' );
     317add_action( 'bbp_untrash_reply',    'bbp_decrease_topic_reply_count_hidden' );
     318add_action( 'bbp_unspam_reply',     'bbp_decrease_topic_reply_count_hidden' );
     319add_action( 'bbp_approve_reply',    'bbp_decrease_topic_reply_count_hidden' );
     320add_action( 'bbp_delete_reply',     'bbp_decrease_topic_reply_count_hidden' );
     321
     322// Update forum reply counts for approved/unapproved topics
    289323add_action( 'bbp_approved_topic',   'bbp_approved_unapproved_topic_update_forum_reply_count' );
    290324add_action( 'bbp_unapproved_topic', 'bbp_approved_unapproved_topic_update_forum_reply_count' );
    291325
    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
    309327add_action( 'bbp_new_topic',     'bbp_increase_user_topic_count' );
    310328add_action( 'bbp_new_reply',     'bbp_increase_user_reply_count' );
     
    325343add_action( 'bbp_unspam_topic',  'bbp_unspam_topic_replies'  );
    326344
    327 // Topic engagements on user creation.
     345// Topic engagements on user creation
    328346add_action( 'bbp_new_topic', 'bbp_update_topic_engagements', 20 );
    329347add_action( 'bbp_new_reply', 'bbp_update_topic_engagements', 20 );
     
    344362add_action( 'bbp_insert_reply', 'bbp_update_topic_voice_count', 30 );
    345363
    346 // Recalculate engagements.
     364// Recalculate engagements
    347365add_action( 'bbp_trashed_reply',    'bbp_recalculate_topic_engagements' );
    348366add_action( 'bbp_untrashed_reply',  'bbp_recalculate_topic_engagements' );
     
    360378add_action( 'bbp_deleted_topic',    'bbp_recalculate_topic_engagements' );
    361379
    362 // Update engagement counts.
     380// Update engagement counts
    363381add_action( 'bbp_trashed_reply',    'bbp_update_topic_voice_count', 30 );
    364382add_action( 'bbp_untrashed_reply',  'bbp_update_topic_voice_count', 30 );
  • trunk/src/includes/core/sub-actions.php

    r6919 r6923  
    265265    do_action( 'bbp_login_form_login' );
    266266}
    267 
    268267
    269268/**
  • trunk/src/includes/forums/functions.php

    r6922 r6923  
    11351135        $forum_id = bbp_get_topic_forum_id( $topic_id );
    11361136
    1137         // Bail if not public.
     1137        // Update inverse based on item status
    11381138        if ( ! bbp_is_topic_public( $topic_id ) ) {
    11391139            bbp_increase_forum_topic_count_hidden( $forum_id );
     
    11421142    }
    11431143
     1144    // Bump up
    11441145    bbp_bump_forum_topic_count( $forum_id );
    11451146}
     
    11631164    // If it's a topic, get the forum id.
    11641165    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
    11681177    bbp_bump_forum_topic_count( $forum_id, -1 );
    11691178}
    11701179
    11711180/**
    1172  * Bump the total hidden topic count of a forum
     1181 * Bump the total topic count of a forum
    11731182 *
    11741183 * @since 2.1.0 bbPress (r3825)
     
    11761185 * @param int $forum_id Optional. Forum id.
    11771186 * @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 */
     1191function bbp_bump_forum_topic_count_hidden( $forum_id = 0, $difference = 1, $update_ancestors = true ) {
    11821192
    11831193    // Bail if no bump
     
    11871197
    11881198    // 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;
    11931203
    11941204    // 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 );
    11961234
    11971235    // 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 );
    11991237}
    12001238
     
    12171255    // If it's a topic, get the forum id.
    12181256    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
    12221268    bbp_bump_forum_topic_count_hidden( $forum_id );
    12231269}
     
    12411287    // If it's a topic, get the forum id.
    12421288    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
    12461300    bbp_bump_forum_topic_count_hidden( $forum_id, -1 );
    12471301}
     
    12671321    // Get some counts
    12681322    $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 );
    12701324    $total_reply_count = bbp_get_forum_reply_count( $forum_id, true,  true );
    12711325    $difference        = (int) $difference;
    12721326
    12731327    // 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 ) );
    12751329    update_post_meta( $forum_id, '_bbp_total_reply_count', (int) ( $total_reply_count + $difference ) );
    12761330
     
    13071361
    13081362/**
     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 */
     1373function 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/**
    13091422 * Increase the total reply count of a forum by one.
    13101423 *
     
    13241437    // If it's a reply, get the forum id.
    13251438    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
    13291450    bbp_bump_forum_reply_count( $forum_id );
    13301451}
     
    13481469    // If it's a reply, get the forum id.
    13491470    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
    13531482    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 */
     1494function 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 */
     1526function 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 );
    13541547}
    13551548
     
    13781571    }
    13791572
    1380     // Update counts.
     1573    // Bump up or down
    13811574    bbp_bump_forum_reply_count( bbp_get_topic_forum_id( $topic_id ), $count );
    13821575}
     
    14371630
    14381631    // 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 );
    14421633
    14431634    // Filter & return
     
    14791670
    14801671            // ...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 );
    14821675        }
    14831676    }
     
    14931686
    14941687    // 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 );
    14981689
    14991690    // Filter & return
     
    15201711    if ( empty( $active_id ) ) {
    15211712
    1522         // Loop through children and add together forum reply counts
     1713        // Loop through children and get the last active ID
    15231714        $children = bbp_forum_query_subforum_ids( $forum_id );
    15241715        if ( ! empty( $children ) ) {
     
    15281719        }
    15291720
    1530         // Don't count replies if the forum is a category
     1721        // Get topic IDs and only accept larger IDs
    15311722        $topic_ids = bbp_forum_query_topic_ids( $forum_id );
    15321723        if ( ! empty( $topic_ids ) ) {
     1724
     1725            // Make sure ID is larger
    15331726            $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 );
    15351730
    15361731        // Forum has no topics
     
    15441739    $children_last_active = (int) $children_last_active;
    15451740
    1546     // If child forums have higher id, use that instead
     1741    // If child forums have higher ID, use that instead
    15471742    if ( ! empty( $children ) && ( $children_last_active > $active_id ) ) {
    15481743        $active_id = $children_last_active;
    15491744    }
    15501745
    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 );
    15551747
    15561748    // Filter & return
     
    15911783 *
    15921784 * @param int $forum_id Optional. Forum id
     1785 * @param int $subforums Optional. Number of subforums
    15931786 * @return bool True on success, false on failure
    15941787 */
    1595 function bbp_update_forum_subforum_count( $forum_id = 0, $subforums = 0 ) {
     1788function bbp_update_forum_subforum_count( $forum_id = 0, $subforums = false ) {
    15961789    $forum_id = bbp_get_forum_id( $forum_id );
    15971790
    15981791    // 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;
    16041795
    16051796    update_post_meta( $forum_id, '_bbp_forum_subforum_count', $subforums );
     
    16581849 * @return int Topic hidden topic count
    16591850 */
    1660 function bbp_update_forum_topic_count_hidden( $forum_id = 0, $topic_count = 0 ) {
     1851function bbp_update_forum_topic_count_hidden( $forum_id = 0, $topic_count = false ) {
    16611852
    16621853    // If topic_id was passed as $forum_id, then get its forum
     
    16741865
    16751866        // Get topics of forum
    1676         if ( empty( $topic_count ) ) {
     1867        if ( ! is_int( $topic_count ) ) {
    16771868            $query = new WP_Query( array(
    16781869                'fields'         => 'ids',
     
    17301921
    17311922    // 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;
    17371926
    17381927    // Calculate total replies in this forum
    17391928    $total_replies = (int) ( $reply_count + $children_reply_count );
    17401929
    1741     // Update the count
     1930    // Update the counts
    17421931    update_post_meta( $forum_id, '_bbp_reply_count',       $reply_count   );
    17431932    update_post_meta( $forum_id, '_bbp_total_reply_count', $total_replies );
     
    17451934    // Filter & return
    17461935    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 */
     1949function 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 );
    17471976}
    17481977
     
    17982027    bbp_update_forum_subforum_count( $r['forum_id'] );
    17992028
    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 ) ) {
    18022031        bbp_update_forum_reply_count(        $r['forum_id'] );
    18032032        bbp_update_forum_topic_count(        $r['forum_id'] );
    18042033        bbp_update_forum_topic_count_hidden( $r['forum_id'] );
     2034        bbp_update_forum_reply_count_hidden( $r['forum_id'] );
    18052035    }
    18062036
  • trunk/src/includes/forums/template.php

    r6903 r6923  
    484484    function bbp_get_forum_last_active_id( $forum_id = 0 ) {
    485485        $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 );
    490490    }
    491491
     
    606606    function bbp_get_forum_parent_id( $forum_id = 0 ) {
    607607        $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 );
    609609
    610610        // Meta-data fallback
    611611        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 );
    613613        }
    614614
    615615        // Filter
    616616        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 );
    622622    }
    623623
     
    868868    function bbp_get_forum_last_topic_id( $forum_id = 0 ) {
    869869        $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 );
    874874    }
    875875
     
    994994    function bbp_get_forum_last_reply_id( $forum_id = 0 ) {
    995995        $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 );
    10001000    }
    10011001
     
    11761176
    11771177        // 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 );
    11791179
    11801180        // This forum has hidden topics
     
    11821182
    11831183            // 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 );
    11851185            $extra       = ' ' . sprintf( _n( '(+%s hidden)', '(+%s hidden)', $deleted_int, 'bbpress' ), $deleted_num );
    11861186
     
    12171217    function bbp_get_forum_subforum_count( $forum_id = 0, $integer = false ) {
    12181218        $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 );
    12201220        $filter      = ( true === $integer )
    12211221            ? 'bbp_get_forum_subforum_count_int'
     
    12511251        $forum_id = bbp_get_forum_id( $forum_id );
    12521252        $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 );
    12541254        $filter   = ( true === $integer )
    12551255            ? 'bbp_get_forum_topic_count_int'
     
    12851285        $forum_id = bbp_get_forum_id( $forum_id );
    12861286        $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 );
    12881288        $filter   = ( true === $integer )
    12891289            ? 'bbp_get_forum_reply_count_int'
     
    13201320        $topics   = bbp_get_forum_topic_count( $forum_id, $total_count, true );
    13211321        $replies  = bbp_get_forum_reply_count( $forum_id, $total_count, true );
    1322         $retval   = $replies + $topics;
     1322        $retval   = ( $replies + $topics );
    13231323        $filter   = ( true === $integer )
    13241324            ? 'bbp_get_forum_post_count_int'
     
    13331333 *
    13341334 * @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?
    13371339 * @param boolean $integer Optional. Whether or not to format the result
    13381340 */
    1339 function bbp_forum_topic_count_hidden( $forum_id = 0, $integer = false ) {
    1340     echo bbp_get_forum_topic_count_hidden( $forum_id, $integer );
     1341function 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 );
    13411343}
    13421344    /**
     
    13451347     *
    13461348     * @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?
    13491353     * @param boolean $integer Optional. Whether or not to format the result
    13501354     * @return int Topic hidden topic count
    13511355     */
    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 ) {
    13531357        $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 );
    13551360        $filter   = ( true === $integer )
    13561361            ? 'bbp_get_forum_topic_count_hidden_int'
     
    13581363
    13591364        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 */
     1377function 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 );
    13601401    }
    13611402
  • trunk/src/includes/replies/functions.php

    r6922 r6923  
    2727    $reply_data = bbp_parse_args( $reply_data, array(
    2828        'post_parent'    => 0, // topic ID
    29         'post_status'    => bbp_get_public_status_id(),
    3029        'post_type'      => bbp_get_reply_post_type(),
    3130        'post_author'    => bbp_get_current_user_id(),
     
    3635        'comment_status' => 'closed'
    3736    ), '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    }
    3842
    3943    // Insert reply
     
    96100function bbp_insert_reply_update_counts( $reply_id = 0, $topic_id = 0, $forum_id = 0 ) {
    97101
    98     // If the reply is public, update the forum/topic reply counts.
     102    // If the reply is public, update the reply counts.
    99103    if ( bbp_is_reply_published( $reply_id ) ) {
    100104        bbp_increase_topic_reply_count( $topic_id );
    101105        bbp_increase_forum_reply_count( $forum_id );
    102106
    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.
    104108    } else {
    105109        bbp_increase_topic_reply_count_hidden( $topic_id );
     110        bbp_increase_forum_reply_count_hidden( $forum_id );
    106111    }
    107112}
     
    315320
    316321    // 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 ) ) {
    318323        $reply_status = bbp_get_pending_status_id();
    319324
     
    920925            } elseif ( bbp_is_topic( $ancestor ) ) {
    921926
    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 );
    930941                }
    931942
    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
    937944                if ( in_array( current_filter(), array( 'bbp_deleted_reply', 'save_post' ), true ) ) {
    938945                    bbp_update_topic_reply_count(        $ancestor );
     
    944951            } elseif ( bbp_is_forum( $ancestor ) ) {
    945952
    946                 // Last topic and reply ID's
    947                 bbp_update_forum_last_topic_id( $ancestor, $topic_id );
    948                 bbp_update_forum_last_reply_id( $ancestor, $reply_id );
    949 
    950                 // Last Active
    951                 bbp_update_forum_last_active_id( $ancestor, $active_id );
    952 
    953                 // Get the last active time if none was passed
    954                 $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 
    959953                // 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
    961969                    bbp_update_forum_last_active_time( $ancestor, $forum_last_active_time );
    962970                }
    963971
    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
    966973                if ( in_array( current_filter(), array( 'bbp_deleted_reply', 'save_post' ), true ) ) {
    967974                    bbp_update_forum_reply_count( $ancestor );
  • trunk/src/includes/replies/template.php

    r6922 r6923  
    436436
    437437        // 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        }
    440447
    441448        // Hierarchical reply page
     
    448455        }
    449456
     457        // Get links & URLS
    450458        $reply_hash = '#post-' . $reply_id;
    451459        $topic_link = bbp_get_topic_permalink( $topic_id, $redirect_to );
    452460        $topic_url  = remove_query_arg( 'view', $topic_link );
    453461
     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
    454467        // Don't include pagination if on first page
    455468        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            }
    457478
    458479        // Include pagination
     
    460481
    461482            // Pretty permalinks
    462             if ( bbp_use_pretty_urls() ) {
     483            if ( ! empty( $has_slug ) && ! empty( $pretty ) && ! empty( $published ) ) {
    463484                $url = trailingslashit( $topic_url ) . trailingslashit( bbp_get_paged_slug() ) . $reply_page;
    464485                $url = user_trailingslashit( $url ) . $reply_hash;
    465486
    466             // Yucky links
     487            // Unpretty links
    467488            } else {
    468489                $url = add_query_arg( 'paged', $reply_page, $topic_url ) . $reply_hash;
     
    762783            $reply_id     = bbp_get_reply_id( $reply_id );
    763784            $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();
    765788
    766789            // Filter & return
     
    852875 *
    853876 * @since 2.0.0 bbPress (r3496)
     877 * @since 2.6.0 bbPress (r6922) Returns false if topic is also not published
    854878 *
    855879 * @param int $reply_id Optional. Topic id
     
    858882function bbp_is_reply_published( $reply_id = 0 ) {
    859883    $reply_id     = bbp_get_reply_id( $reply_id );
     884    $topic_id     = bbp_get_reply_topic_id( $reply_id );
    860885    $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 );
    862889
    863890    // Filter & return
    864     return (bool) apply_filters( 'bbp_is_reply_published', (bool) $reply_status, $reply_id );
     891    return (bool) apply_filters( 'bbp_is_reply_published', (bool) $retval, $reply_id );
    865892}
    866893
     
    13961423    function bbp_get_reply_topic_id( $reply_id = 0 ) {
    13971424        $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 );
    13991426
    14001427        // Meta-data fallback
    14011428        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 );
    14031430        }
    14041431
    14051432        // Filter
    14061433        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 );
    14121439    }
    14131440
     
    14331460    function bbp_get_reply_forum_id( $reply_id = 0 ) {
    14341461        $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 );
    14361464
    14371465        // Meta-data fallback
    14381466        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 );
    14401468        }
    14411469
    14421470        // Filter
    14431471        if ( ! empty( $forum_id ) ) {
    1444             $forum_id = bbp_get_forum_id( $forum_id );
     1472            $forum_id = (int) bbp_get_forum_id( $forum_id );
    14451473        }
    14461474
     
    22722300
    22732301    // 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 )) {
    22752303
    22762304        // User's replies
  • trunk/src/includes/topics/functions.php

    r6922 r6923  
    844844/**
    845845 * 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 run
     846 * meta data of forums above it. This calls several functions that all run
    847847 * manual queries against the database to get their results. As such, this
    848848 * function can be costly to run but is necessary to keep everything accurate.
     
    994994    $old_forum_ancestors = array_values( array_unique( array_merge( array( $old_forum_id ), (array) get_post_ancestors( $old_forum_id ) ) ) );
    995995
    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 ) ) {
    1004998
    1005999        // Update old forum counts.
    10061000        bbp_decrease_forum_topic_count( $old_forum_id );
    1007         bbp_bump_forum_reply_count( $old_forum_id, -$public_reply_count );
    10081001
    10091002        // Update new forum counts.
    10101003        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
    10121006    } else {
    10131007
     
    10181012        bbp_increase_forum_topic_count_hidden( $new_forum_id );
    10191013    }
     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 );
    10201024
    10211025    // Loop through ancestors and update them
     
    23192323        $topic_id = bbp_get_reply_topic_id( $reply_id );
    23202324
    2321         // If this is a new, unpublished, reply, update hidden count and bail.
    2322         if ( ! bbp_is_reply_published( $reply_id ) ) {
     2325        // Update inverse based on item status
     2326        if ( ! bbp_is_reply_public( $reply_id ) ) {
    23232327            bbp_increase_topic_reply_count_hidden( $topic_id );
    23242328            return;
     
    23262330    }
    23272331
     2332    // Bump up
    23282333    bbp_bump_topic_reply_count( $topic_id );
    23292334}
     
    23472352    // If it's a reply, get the topic id.
    23482353    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
    23522365    bbp_bump_topic_reply_count( $topic_id, -1 );
    23532366}
     
    24002413    // If it's a reply, get the topic id.
    24012414    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
    24052426    bbp_bump_topic_reply_count_hidden( $topic_id );
    24062427}
     
    24242445    // If it's a reply, get the topic id.
    24252446    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
    24292458    bbp_bump_topic_reply_count_hidden( $topic_id, -1 );
    24302459}
     
    25092538 * @return int Topic reply count
    25102539 */
    2511 function bbp_update_topic_reply_count( $topic_id = 0, $reply_count = 0 ) {
     2540function bbp_update_topic_reply_count( $topic_id = 0, $reply_count = false ) {
    25122541
    25132542    // If it's a reply, then get the parent (topic id)
     
    25172546
    25182547    // Get replies of topic if not passed
    2519     $reply_count = empty( $reply_count )
     2548    $reply_count = ! is_int( $reply_count )
    25202549        ? bbp_get_public_child_count( $topic_id, bbp_get_reply_post_type() )
    25212550        : (int) $reply_count;
     
    25372566 * @return int Topic hidden reply count
    25382567 */
    2539 function bbp_update_topic_reply_count_hidden( $topic_id = 0, $reply_count = 0 ) {
     2568function bbp_update_topic_reply_count_hidden( $topic_id = 0, $reply_count = false ) {
    25402569
    25412570    // If it's a reply, then get the parent (topic id)
     
    25452574
    25462575    // Get replies of topic
    2547     $reply_count = empty( $reply_count )
     2576    $reply_count = ! is_int( $reply_count )
    25482577        ? bbp_get_non_public_child_count( $topic_id, bbp_get_reply_post_type() )
    25492578        : (int) $reply_count;
     
    25842613
    25852614    // 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 );
    25892616
    25902617    // Filter & return
     
    26542681
    26552682    // 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 );
    26592684
    26602685    // Filter & return
  • trunk/src/includes/topics/template.php

    r6922 r6923  
    805805        ), 'get_topic_pagination' );
    806806
     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
    807810        // 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'] )
    809812            ? trailingslashit( get_permalink( $r['topic_id'] ) ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' )
    810813            : add_query_arg( 'paged', '%#%', get_permalink( $r['topic_id'] ) );
     
    947950
    948951            $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();
    950955
    951956            // Filter & return
     
    16581663    function bbp_get_topic_forum_id( $topic_id = 0 ) {
    16591664        $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 );
    16611666
    16621667        // Meta-data fallback
    16631668        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 );
    16651670        }
    16661671
    16671672        // Filter
    16681673        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 );
    16741679    }
    16751680
     
    16941699    function bbp_get_topic_last_active_id( $topic_id = 0 ) {
    16951700        $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 );
    17001705    }
    17011706
     
    18561861    function bbp_get_topic_last_reply_id( $topic_id = 0 ) {
    18571862        $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 );
    18621867    }
    18631868
     
    20582063    function bbp_get_topic_reply_count( $topic_id = 0, $integer = false ) {
    20592064        $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 );
    20612066        $filter   = ( true === $integer )
    20622067            ? 'bbp_get_topic_reply_count_int'
     
    20882093    function bbp_get_topic_post_count( $topic_id = 0, $integer = false ) {
    20892094        $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;
    20912096        $filter   = ( true === $integer )
    20922097            ? 'bbp_get_topic_post_count_int'
     
    21202125    function bbp_get_topic_reply_count_hidden( $topic_id = 0, $integer = false ) {
    21212126        $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 );
    21232128        $filter   = ( true === $integer )
    21242129            ? 'bbp_get_topic_reply_count_hidden_int'
     
    21482153    function bbp_get_topic_voice_count( $topic_id = 0, $integer = false ) {
    21492154        $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 );
    21512156        $filter   = ( true === $integer )
    21522157            ? 'bbp_get_topic_voice_count_int'
     
    23432348        // See if links need to be unset
    23442349        $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 ) ) {
    23462351
    23472352            // Close link shouldn't be visible on trashed/spammed/pending topics
  • trunk/src/includes/users/engagements.php

    r6876 r6923  
    417417    // Is a topic
    418418    } 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
    419425        $author_id = bbp_get_topic_author_id( $topic_id );
    420426        $topic_id  = bbp_get_topic_id( $topic_id );
Note: See TracChangeset for help on using the changeset viewer.