Skip to:
Content

bbPress.org

Changeset 6528


Ignore:
Timestamp:
06/12/2017 05:29:02 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Hierarchy: Use post_parent when not empty, and fallback to meta-data.

This fixes a few weird inconsistencies with how deleting content works, because delete_ hooks fire after meta & terms have already been deleted from the database, deleted_ hooks fire after the post itself is deleted from the database, but the post object cache has not yet been cleaned (even though term & meta caches have.)

We also call a few functions like bbp_is_reply() on the deleted $postid, and even though the state of the object-cache should not be relied on, it has not been purged yet.

Relatedly, updates to forum & topic descriptions can more reliably identify their state, so this commit adjusts some logic there also.

Location:
trunk/src/includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/forums/template.php

    r6438 r6528  
    664664        $parent_id = get_post_field( 'post_parent', $forum_id );
    665665
     666        // Meta-data fallback
     667        if ( empty( $parent_id ) ) {
     668            $parent_id = get_post_meta( $forum_id, '_bbp_forum_id', true );
     669        }
     670
     671        // Filter
     672        if ( ! empty( $parent_id ) ) {
     673            $parent_id = bbp_get_forum_id( $parent_id );
     674        }
     675
    666676        // Filter & return
    667677        return (int) apply_filters( 'bbp_get_forum_parent_id', (int) $parent_id, $forum_id );
     
    21872197        if ( ! empty( $last_active ) ) {
    21882198
     2199            // Has replies
    21892200            if ( ! empty( $reply_count ) ) {
    2190 
    2191                 if ( bbp_is_forum_category( $forum_id ) ) {
    2192                     $retstr = sprintf( esc_html__( 'This category contains %1$s and %2$s, and was last updated by %3$s %4$s.', 'bbpress' ), $topic_text, $reply_text, $last_updated_by, $time_since );
    2193                 } else {
    2194                     $retstr = sprintf( esc_html__( 'This forum contains %1$s and %2$s, and was last updated by %3$s %4$s.',    'bbpress' ), $topic_text, $reply_text, $last_updated_by, $time_since );
    2195                 }
    2196 
     2201                $retstr = bbp_is_forum_category( $forum_id )
     2202                    ? sprintf( esc_html__( 'This category has %1$s, %2$s, and was last updated %3$s by %4$s.', 'bbpress' ), $topic_text, $reply_text, $time_since, $last_updated_by )
     2203                    : sprintf( esc_html__( 'This forum has %1$s, %2$s, and was last updated %3$s by %4$s.',    'bbpress' ), $topic_text, $reply_text, $time_since, $last_updated_by );
     2204
     2205            // Only has topics
    21972206            } else {
    2198 
    2199                 if ( bbp_is_forum_category( $forum_id ) ) {
    2200                     $retstr = sprintf( esc_html__( 'This category contains %1$s, and was last updated by %2$s %3$s.', 'bbpress' ), $topic_text, $last_updated_by, $time_since );
    2201                 } else {
    2202                     $retstr = sprintf( esc_html__( 'This forum contains %1$s, and was last updated by %2$s %3$s.',    'bbpress' ), $topic_text, $last_updated_by, $time_since );
    2203                 }
     2207                $retstr = bbp_is_forum_category( $forum_id )
     2208                    ? sprintf( esc_html__( 'This category has %1$s, and was last updated %2$s by %3$s.', 'bbpress' ), $topic_text, $time_since, $last_updated_by )
     2209                    : sprintf( esc_html__( 'This forum has %1$s, and was last updated %2$s by %3$s.',    'bbpress' ), $topic_text, $time_since, $last_updated_by );
    22042210            }
    22052211
    2206         // Forum has no last active data
     2212        // Forum has no last active data (but does have topics & replies)
     2213        } elseif ( ! empty( $reply_count ) ) {
     2214            $retstr = bbp_is_forum_category( $forum_id )
     2215                ? sprintf( esc_html__( 'This category has %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text )
     2216                : sprintf( esc_html__( 'This forum has %1$s and %2$s.',    'bbpress' ), $topic_text, $reply_text );
     2217
     2218        // Forum has no last active data or replies (but does have topics)
     2219        } elseif ( ! empty( $topic_count ) ) {
     2220            $retstr = bbp_is_forum_category( $forum_id )
     2221                ? sprintf( esc_html__( 'This category has %1$s.', 'bbpress' ), $topic_text )
     2222                : sprintf( esc_html__( 'This forum has %1$s.',    'bbpress' ), $topic_text );
     2223
     2224        // Forum is empty
    22072225        } else {
    2208 
    2209             if ( ! empty( $reply_count ) ) {
    2210 
    2211                 if ( bbp_is_forum_category( $forum_id ) ) {
    2212                     $retstr = sprintf( esc_html__( 'This category contains %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text );
    2213                 } else {
    2214                     $retstr = sprintf( esc_html__( 'This forum contains %1$s and %2$s.',    'bbpress' ), $topic_text, $reply_text );
    2215                 }
    2216 
    2217             } else {
    2218 
    2219                 if ( ! empty( $topic_count ) ) {
    2220 
    2221                     if ( bbp_is_forum_category( $forum_id ) ) {
    2222                         $retstr = sprintf( esc_html__( 'This category contains %1$s.', 'bbpress' ), $topic_text );
    2223                     } else {
    2224                         $retstr = sprintf( esc_html__( 'This forum contains %1$s.',    'bbpress' ), $topic_text );
    2225                     }
    2226 
    2227                 } else {
    2228                     $retstr = esc_html__( 'This forum is empty.', 'bbpress' );
    2229                 }
    2230             }
    2231         }
    2232 
    2233         // Add feeds
    2234         //$feed_links = ( ! empty( $r['feed'] ) ) ? bbp_get_forum_topics_feed_link ( $forum_id ) . bbp_get_forum_replies_feed_link( $forum_id ) : '';
     2226            $retstr = esc_html__( 'This forum is empty.', 'bbpress' );
     2227        }
    22352228
    22362229        // Add the 'view all' filter back
  • trunk/src/includes/replies/template.php

    r6526 r6528  
    15711571     */
    15721572    function bbp_get_reply_topic_id( $reply_id = 0 ) {
    1573 
    1574         // Assume there is no topic id
    1575         $topic_id = 0;
    1576 
    1577         // Check that reply_id is valid
    15781573        $reply_id = bbp_get_reply_id( $reply_id );
    1579         if ( ! empty( $reply_id ) ) {
     1574        $topic_id = get_post_field( 'post_parent', $reply_id );
     1575
     1576        // Meta-data fallback
     1577        if ( empty( $topic_id ) ) {
    15801578            $topic_id = get_post_meta( $reply_id, '_bbp_topic_id', true );
    1581             if ( ! empty( $topic_id ) ) {
    1582                 $topic_id = bbp_get_topic_id( $topic_id );
    1583             }
    1584         }
    1585 
    1586         // Filter & return
    1587         return (int) apply_filters( 'bbp_get_reply_topic_id', $topic_id, $reply_id );
     1579        }
     1580
     1581        // Filter
     1582        if ( ! empty( $topic_id ) ) {
     1583            $topic_id = bbp_get_topic_id( $topic_id );
     1584        }
     1585
     1586        // Filter & return
     1587        return (int) apply_filters( 'bbp_get_reply_topic_id', (int) $topic_id, $reply_id );
    15881588    }
    15891589
     
    16121612     */
    16131613    function bbp_get_reply_forum_id( $reply_id = 0 ) {
    1614 
    1615         // Assume there is no forum
    1616         $forum_id = 0;
    1617 
    1618         // Check that reply_id is valid
    16191614        $reply_id = bbp_get_reply_id( $reply_id );
    1620         if ( ! empty( $reply_id ) ) {
     1615        $forum_id = get_post_field( 'post_parent', bbp_get_reply_topic_id( $reply_id ) );
     1616
     1617        // Meta-data fallback
     1618        if ( empty( $forum_id ) ) {
    16211619            $forum_id = get_post_meta( $reply_id, '_bbp_forum_id', true );
    1622             if ( ! empty( $forum_id ) ) {
    1623                 $forum_id = bbp_get_forum_id( $forum_id );
    1624             }
     1620        }
     1621
     1622        // Filter
     1623        if ( ! empty( $forum_id ) ) {
     1624            $forum_id = bbp_get_forum_id( $forum_id );
    16251625        }
    16261626
  • trunk/src/includes/topics/template.php

    r6438 r6528  
    18811881    function bbp_get_topic_forum_id( $topic_id = 0 ) {
    18821882        $topic_id = bbp_get_topic_id( $topic_id );
    1883         $forum_id = get_post_meta( $topic_id, '_bbp_forum_id', true );
     1883        $forum_id = get_post_field( 'post_parent', $topic_id );
     1884
     1885        // Meta-data fallback
     1886        if ( empty( $forum_id ) ) {
     1887            $forum_id = get_post_meta( $topic_id, '_bbp_forum_id', true );
     1888        }
     1889
     1890        // Filter
     1891        if ( ! empty( $forum_id ) ) {
     1892            $forum_id = bbp_get_forum_id( $forum_id );
     1893        }
    18841894
    18851895        // Filter & return
     
    36763686        $voice_count = sprintf( _n( '%s voice', '%s voices', $vc_int, 'bbpress' ), $voice_count );
    36773687
    3678         // Topic has replies
    3679         $last_reply = bbp_get_topic_last_reply_id( $topic_id );
    3680         if ( ! empty( $last_reply ) ) {
    3681             $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_reply, 'size' => $r['size'] ) );
    3682             $retstr          = sprintf( esc_html__( 'This topic contains %1$s, has %2$s, and was last updated by %3$s %4$s.', 'bbpress' ), $reply_count, $voice_count, $last_updated_by, $time_since );
     3688        // Topic has activity (could be from reply or topic author)
     3689        $last_active = bbp_get_topic_last_active_id( $topic_id );
     3690        if ( ! empty( $last_active ) ) {
     3691            $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_active, 'size' => $r['size'] ) );
     3692            $retstr          = sprintf( esc_html__( 'This topic has %1$s, %2$s, and was last updated %3$s by %4$s.', 'bbpress' ), $reply_count, $voice_count, $time_since, $last_updated_by );
    36833693
    36843694        // Topic has no replies
    36853695        } elseif ( ! empty( $voice_count ) && ! empty( $reply_count ) ) {
    3686             $retstr = sprintf( esc_html__( 'This topic contains %1$s and has %2$s.', 'bbpress' ), $voice_count, $reply_count );
     3696            $retstr = sprintf( esc_html__( 'This topic has %1$s and %2$s.', 'bbpress' ), $voice_count, $reply_count );
    36873697
    36883698        // Topic has no replies and no voices
     
    41124122
    41134123/**
    4114  * Allow topic rows to have adminstrative actions
     4124 * Allow topic rows to have administrative actions
    41154125 *
    41164126 * @since 2.1.0 bbPress (r3653)
Note: See TracChangeset for help on using the changeset viewer.