From e15c6f52783d8f35eb9dcd625a63f5215f7e0e83 Mon Sep 17 00:00:00 2001
From: denis <denis@deniska>
Date: Feb 9, 2017 3:15:20 AM

Correct last reply position in "Last Post" column

diff --git a/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php b/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php
index 56eb051..7af6b16 100644
--- a/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php
+++ b/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php
@@ -35,6 +35,9 @@
 
 		// REST API.
 		add_filter( 'rest_endpoints', array( $this, 'disable_rest_api_users_endpoint' ) );
+
+		// Correct last reply position
+		add_filter( 'bbp_get_reply_position', array( $this, 'correct_last_reply_position' ), 10, 3 );
 	}
 
 	/**
@@ -366,4 +369,17 @@
 		}
 		return $bound_id;
 	}
+        
+	/**
+	 * Correct last reply position with considering hidden replies
+	 * with status Spam, Pending, Archived, etc.
+	 *
+	 * @link https://meta.trac.wordpress.org/ticket/2043
+	 */
+	function bbp_get_reply_position( $reply_position, $reply_id, $topic_id ) {
+		$reply_count_hidden = bbp_get_topic_reply_count_hidden( $topic_id, true );
+		$reply_count = bbp_get_topic_reply_count( $topic_id, true );
+
+		return $reply_count - $reply_count_hidden;
+	}
 }
