WordPress.org

Making WordPress.org

Changeset 5686


Ignore:
Timestamp:
07/18/17 00:29:59 (5 months ago)
Author:
SergeyBiryukov
Message:

Support Forums: Update topic replies count if the reply status changes on editing.

This is neccesary to properly account for the status change as a result of Akismet check or user flagging rather than an explicit moderator action.

Fixes #1971.

File:
1 edited

Legend:

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

    r5685 r5686  
    4747        add_action( 'bbp_new_reply',  array( $this, 'handle_extra_reply_actions' ), 10, 2 ); 
    4848        add_action( 'bbp_edit_reply', array( $this, 'handle_extra_reply_actions' ), 10, 2 ); 
     49 
     50        // Update topic replies count if the reply status changes on editing. 
     51        add_filter( 'bbp_edit_reply_pre_insert', array( $this, 'update_replies_count_on_editing_reply' ), 20 ); 
    4952 
    5053        // Honor i18n number formatting. 
     
    419422 
    420423    /** 
     424     * Update topic replies count if the reply status changes on editing. 
     425     * 
     426     * This is neccesary to properly account for the status change as a result of 
     427     * Akismet check or user flagging rather than an explicit moderator action. 
     428     * 
     429     * @param array $data Reply post data. 
     430     * @return array Filtered reply data. 
     431     */ 
     432    public function update_replies_count_on_editing_reply( $data ) { 
     433        // Bail if the reply is not published. 
     434        if ( 'publish' !== get_post_status( $data['ID'] ) ) { 
     435            return $data; 
     436        } 
     437 
     438        // Bail if the new status is not pending or spam. 
     439        if ( ! in_array( $data['post_status'], array( 'pending', 'spam' ) ) ) { 
     440            return $data; 
     441        }    
     442 
     443        $topic_id = bbp_get_reply_topic_id( $data['ID'] ); 
     444 
     445        bbp_update_topic_last_reply_id( $topic_id ); 
     446        bbp_update_topic_last_active_id( $topic_id ); 
     447        bbp_update_topic_last_active_time( $topic_id ); 
     448        bbp_update_topic_voice_count( $topic_id ); 
     449 
     450        bbp_decrease_topic_reply_count( $topic_id ); 
     451        bbp_increase_topic_reply_count_hidden( $topic_id ); 
     452 
     453        return $data; 
     454    } 
     455 
     456    /** 
    421457     * Override `bbp_number_format()` to behave like `bbp_number_format_i18n()` under default conditions. 
    422458     * 
Note: See TracChangeset for help on using the changeset viewer.