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