From c34673079e22dedc1d06d35d4ed976de037f3d97 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..8ced4eb 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 correct_last_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;
+	}
 }
