Making WordPress.org

Ticket #6443: 6443.patch

File 6443.patch, 1.5 KB (added by tellyworth, 2 years ago)

Call bbp_update_reply_position() after removing replies from a thread

  • support-forums/inc/class-moderators.php

     
    6464                add_action( 'bbp_approved_reply',               array( $this, 'store_moderator_username' ) );
    6565                add_action( 'bbp_unapproved_topic',             array( $this, 'store_moderator_username' ) );
    6666                add_action( 'bbp_unapproved_reply',             array( $this, 'store_moderator_username' ) );
     67
     68                // Clean up after posts are removed from public view
     69                add_action( 'bbp_spammed_reply', array( $this, 'fix_pagination_after_remove' ) );
     70                add_action( 'bbp_deleted_reply', array( $this, 'fix_pagination_after_remove' ) );
     71                add_action( 'wporg_bbp_archived_reply', array( $this, 'fix_pagination_after_remove' ) );
    6772        }
    6873
    6974        /**
     
    10641069
    10651070                return $topic_status;
    10661071        }
     1072
     1073        /**
     1074         * Repaginate a thread after a reply is spammed/deleted/archived.
     1075         *
     1076         * @param int $reply_id ID of removed reply.
     1077         */
     1078        public function fix_pagination_after_remove( $reply_id ) {
     1079                if ( $reply_id ) {
     1080                        if ( $topic_id = bbp_get_reply_topic_id( $reply_id ) ) {
     1081                                $all_reply_ids_in_thread = bbp_get_all_child_ids( $topic_id, bbp_get_reply_post_type() );
     1082                                if ( $all_reply_ids_in_thread ) {
     1083                                        foreach ( $all_reply_ids_in_thread as $_reply_id ) {
     1084                                                $r = bbp_update_reply_position( $_reply_id );
     1085                                        }
     1086                                }
     1087                        }
     1088                }
     1089        }
     1090
    10671091}