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