Skip to:
Content

bbPress.org


Ignore:
Timestamp:
06/12/2017 05:29:02 PM (7 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.

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