add_filter ('bbp_get_forum_last_active_id' , 'rew_get_forum_last_active_id', 10 , 2 ) ; add_filter ('bbp_get_forum_freshness_link' , 'rew_get_forum_freshness_link', 10 , 2 ) ; function rew_get_forum_last_active_id ($active_id, $forum_id) { $sub_forums = bbp_forum_get_subforums($forum_id) ; if ( !empty( $sub_forums ) ) { $active_id = 0; $show = array(); //find the latest permissible foreach ( $sub_forums as $sub_forum ) { $sub_forum_id = $sub_forum->ID ; $active_id = get_post_meta( $sub_forum_id , '_bbp_last_active_id', true ); $last_active = get_post_meta( $sub_forum_id, '_bbp_last_active_time', true ); if ( empty( $active_id ) ) { // not replies, maybe topics ? $active_id = bbp_get_forum_last_topic_id( $sub_forum_id ); if ( !empty( $active_id ) ) { $last_active = bbp_get_topic_last_active_time( $active_id ); } } if ( !empty( $active_id ) ) { $curdate = strtotime($last_active); $show[$curdate] = $active_id ; } } $mostRecent= 0; foreach($show as $date=>$value){ if ($date > $mostRecent) { $mostRecent = $date; } } if ($mostRecent != 0) { $active_id = $show[$mostRecent] ; } else { $active_id = 0; } } return apply_filters( 'rew_get_forum_last_active_id', $active_id, $forum_id ); } function rew_get_forum_freshness_link ($anchor, $forum_id) { global $rpg_settingsf ; $forum_id = bbp_get_forum_id( $forum_id ); $active_id = bbp_get_forum_last_active_id( $forum_id ); if ( empty( $active_id ) ) $active_id = bbp_get_forum_last_reply_id( $forum_id ); if ( empty( $active_id ) ) $active_id = bbp_get_forum_last_topic_id( $forum_id ); $link_url = $title = ''; if ( bbp_is_topic( $active_id ) ) { //then reset forum_id to the forum of the active topic in case it is a sub forum $forum_id = bbp_get_topic_forum_id($active_id); $link_url = bbp_get_forum_last_topic_permalink( $forum_id ); $title = bbp_get_forum_last_topic_title( $forum_id ); } elseif ( bbp_is_reply( $active_id ) ) { //then reset forum_id to the forum of the active topic in case it is a sub forum $forum_id = bbp_get_reply_forum_id($active_id); $link_url = bbp_get_forum_last_reply_url( $forum_id ); $title = bbp_get_forum_last_reply_title( $forum_id ); } $time_since = bbp_get_forum_last_active_time( $forum_id ); if ( !empty( $time_since ) && !empty( $link_url ) ) $anchor = '' . esc_html( $time_since ) . ''; else $anchor = esc_html__( 'No Topics', 'bbpress' ); return apply_filters( 'rew_get_forum_freshness_link', $anchor, $forum_id, $time_since, $link_url, $title, $active_id ); } add_action( 'bbp_theme_before_forum_freshness_link', 'rew_freshness_display_title'); function rew_freshness_display_title ($forum_id = 0) { // Verify forum and get last active meta $forum_id = bbp_get_forum_id( $forum_id ); $active_id = bbp_get_forum_last_active_id( $forum_id ); $link_url = $title = ''; if ( empty( $active_id ) ) $active_id = bbp_get_forum_last_reply_id( $forum_id ); if ( empty( $active_id ) ) $active_id = bbp_get_forum_last_topic_id( $forum_id ); if ( bbp_is_topic( $active_id ) ) { //then reset forum_id to the forum of the active topic in case it is a sub forum $forum_id = bbp_get_topic_forum_id($active_id); $link_url = bbp_get_forum_last_topic_permalink( $forum_id ); $title = bbp_get_forum_last_topic_title( $forum_id ); } elseif ( bbp_is_reply( $active_id ) ) { //then reset forum_id to the forum of the active topic in case it is a sub forum $forum_id = bbp_get_reply_forum_id($active_id); $link_url = bbp_get_forum_last_reply_url( $forum_id ); $title = bbp_get_forum_last_topic_title( $forum_id ); } $anchor = '' . esc_html( $title ) . ''; echo $anchor.'

' ; }