Making WordPress.org

Changeset 11980


Ignore:
Timestamp:
07/20/2022 07:39:18 AM (21 months ago)
Author:
dd32
Message:

Support Forums: Subscriptions: When sending subscriptions for previously-non-published posts, unhook the proper function.

For performance reasons, the support forums have a number of deep bbPress customizations, some of which remove default bbPress functions and replace it with their own.

One such case is bbp_update_{topic,reply}() where we've replaced it with a variant that doesn't call bbp_update_{topic,reply}_walker() for new/edited posts.

By having this function hooked, it appears that under certain circumstances, it would've been possible to overwrite certain post-meta of previously-moderated posts upon approval/unspam.

See [11978], #3674.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-emails.php

    r11978 r11980  
    165165        $topic_author = bbp_get_reply_author_id( $reply_id );
    166166
     167        // For performance reasons, we've removed the bbPress bbp_update_topic() method, and replaced it with our slightly altered variant.
     168        $bbp_update_topic = [ Plugin::get_instance()->dropin, 'bbp_update_topic' ];
     169        if ( ! has_filter( 'bbp_new_topic', $bbp_update_topic ) ) {
     170            // Fallback to the default bbPress function if ours isn't present (ie. Rosetta, or when we've successfully removed our performance customizations).
     171            $bbp_update_topic = 'bbp_update_topic';
     172        }
     173
    167174        // Remove the bbPress topic update handler
    168         remove_action( 'bbp_new_topic', 'bbp_update_topic' );
     175        remove_action( 'bbp_new_topic', $bbp_update_topic );
    169176
    170177        // Call the bbp_new_topic action..
    171178        do_action( 'bbp_new_topic', $topic_id, $forum_id, array(), $topic_author );
    172179
    173         add_action( 'bbp_new_topic', 'bbp_update_topic', 10, 5 ); // bbPress requests 5, but calls it with 4..
     180        add_action( 'bbp_new_topic', $bbp_update_topic, 10, 5 ); // bbPress requests 5, but calls it with 4..
    174181
    175182        delete_post_meta( $topic_id, self::SUBSCRIPTIONS_TRIGGER_KEY );
     
    192199        }
    193200
    194         remove_action( 'bbp_new_reply', 'bbp_update_reply' );
     201        // For performance reasons, we've removed the bbPress bbp_update_reply() method, and replaced it with our slightly altered variant.
     202        $bbp_update_reply = [ Plugin::get_instance()->dropin, 'bbp_update_reply' ];
     203        if ( ! has_filter( 'bbp_new_reply', $bbp_update_reply ) ) {
     204            // Fallback to the default bbPress function if ours isn't present (ie. Rosetta, or when we've successfully removed our performance customizations).
     205            $bbp_update_reply = 'bbp_update_reply';
     206        }
     207
     208        // Remove the bbPress topic update handler
     209        remove_action( 'bbp_new_reply', $bbp_update_reply );
    195210
    196211        do_action( 'bbp_new_reply', $reply_id, $topic_id, $forum_id, array(), $reply_author, false, false );
    197212
    198         add_action( 'bbp_new_reply',  'bbp_update_reply', 10, 7 );
     213        add_action( 'bbp_new_reply',  $bbp_update_reply, 10, 7 );
    199214
    200215        delete_post_meta( $reply_id, self::SUBSCRIPTIONS_TRIGGER_KEY );
Note: See TracChangeset for help on using the changeset viewer.