Skip to:
Content

bbPress.org


Ignore:
Timestamp:
11/09/2019 05:35:42 AM (4 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.