Index: /trunk/src/includes/forums/functions.php
===================================================================
--- /trunk/src/includes/forums/functions.php	(revision 5730)
+++ /trunk/src/includes/forums/functions.php	(revision 5731)
@@ -1193,5 +1193,5 @@
 		$children = bbp_forum_query_subforum_ids( $forum_id );
 		if ( !empty( $children ) ) {
-			foreach ( (array) $children as $child ) {
+			foreach ( $children as $child ) {
 				$children_last_topic = bbp_update_forum_last_topic_id( $child ); // Recursive
 			}
@@ -1263,5 +1263,5 @@
 		$children = bbp_forum_query_subforum_ids( $forum_id );
 		if ( !empty( $children ) ) {
-			foreach ( (array) $children as $child ) {
+			foreach ( $children as $child ) {
 				$children_last_reply = bbp_update_forum_last_reply_id( $child ); // Recursive
 			}
@@ -1329,5 +1329,5 @@
 		$children = bbp_forum_query_subforum_ids( $forum_id );
 		if ( !empty( $children ) ) {
-			foreach ( (array) $children as $child ) {
+			foreach ( $children as $child ) {
 				$children_last_active = bbp_update_forum_last_active_id( $child, $active_id );
 			}
@@ -1357,8 +1357,8 @@
 	// Update only if published
 	if ( bbp_get_public_status_id() === get_post_status( $active_id ) ) {
-		update_post_meta( $forum_id, '_bbp_last_active_id', (int) $active_id );
-	}
-
-	return (int) apply_filters( 'bbp_update_forum_last_active_id', (int) $active_id, $forum_id );
+		update_post_meta( $forum_id, '_bbp_last_active_id', $active_id );
+	}
+
+	return (int) apply_filters( 'bbp_update_forum_last_active_id', $active_id, $forum_id );
 }
 
@@ -1410,7 +1410,9 @@
 	}
 
-	update_post_meta( $forum_id, '_bbp_forum_subforum_count', (int) $subforums );
-
-	return (int) apply_filters( 'bbp_update_forum_subforum_count', (int) $subforums, $forum_id );
+	$subforums = (int) $subforums;
+
+	update_post_meta( $forum_id, '_bbp_forum_subforum_count', $subforums );
+
+	return (int) apply_filters( 'bbp_update_forum_subforum_count', $subforums, $forum_id );
 }
 
@@ -1441,5 +1443,5 @@
 	$children = bbp_forum_query_subforum_ids( $forum_id );
 	if ( !empty( $children ) ) {
-		foreach ( (array) $children as $child ) {
+		foreach ( $children as $child ) {
 			$children_topic_count += bbp_update_forum_topic_count( $child ); // Recursive
 		}
@@ -1450,11 +1452,11 @@
 
 	// Calculate total topics in this forum
-	$total_topics = $topics + $children_topic_count;
+	$total_topics = (int) ( $topics + $children_topic_count );
 
 	// Update the count
-	update_post_meta( $forum_id, '_bbp_topic_count',       (int) $topics       );
-	update_post_meta( $forum_id, '_bbp_total_topic_count', (int) $total_topics );
-
-	return (int) apply_filters( 'bbp_update_forum_topic_count', (int) $total_topics, $forum_id );
+	update_post_meta( $forum_id, '_bbp_topic_count',       $topics       );
+	update_post_meta( $forum_id, '_bbp_total_topic_count', $total_topics );
+
+	return (int) apply_filters( 'bbp_update_forum_topic_count', $total_topics, $forum_id );
 }
 
@@ -1503,9 +1505,11 @@
 		}
 
+		$topic_count = (int) $topic_count;
+
 		// Update the count
-		update_post_meta( $forum_id, '_bbp_topic_count_hidden', (int) $topic_count );
-	}
-
-	return (int) apply_filters( 'bbp_update_forum_topic_count_hidden', (int) $topic_count, $forum_id );
+		update_post_meta( $forum_id, '_bbp_topic_count_hidden', $topic_count );
+	}
+
+	return (int) apply_filters( 'bbp_update_forum_topic_count_hidden', $topic_count, $forum_id );
 }
 
@@ -1546,20 +1550,19 @@
 
 	// Don't count replies if the forum is a category
-	$topic_ids = bbp_forum_query_topic_ids( $forum_id );
-	if ( !empty( $topic_ids ) ) {
+	$reply_count = 0;
+	$topic_ids   = bbp_forum_query_topic_ids( $forum_id );
+	if ( ! empty( $topic_ids ) ) {
 		$topic_ids   = implode( ',', wp_parse_id_list( $topic_ids ) );
 		$reply_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s';", bbp_get_public_status_id(), bbp_get_reply_post_type() ) );
-	} else {
-		$reply_count = 0;
 	}
 
 	// Calculate total replies in this forum
-	$total_replies = (int) $reply_count + $children_reply_count;
+	$total_replies = (int) ( $reply_count + $children_reply_count );
 
 	// Update the count
-	update_post_meta( $forum_id, '_bbp_reply_count',       (int) $reply_count   );
-	update_post_meta( $forum_id, '_bbp_total_reply_count', (int) $total_replies );
-
-	return (int) apply_filters( 'bbp_update_forum_reply_count', (int) $total_replies, $forum_id );
+	update_post_meta( $forum_id, '_bbp_reply_count',       $reply_count   );
+	update_post_meta( $forum_id, '_bbp_total_reply_count', $total_replies );
+
+	return (int) apply_filters( 'bbp_update_forum_reply_count', $total_replies, $forum_id );
 }
 
