function custom_freshness_link($forum_id = 0)
{
    global $rpg_settingsf;
    $forum_id = bbp_get_forum_id($forum_id);
    $active_id = bbp_get_forum_last_active_id($forum_id);
    $link_url = $title = '';
    $forum_title = bbp_get_forum_title($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);
    }
    if (bbp_is_topic($active_id)) {
        $link_url = bbp_get_forum_last_topic_permalink($forum_id);
        //$link_id added to get post_id and type to allow for later check
        $link_id = bbp_get_forum_last_topic_id($forum_id);
        $check = "topic";
        $title = bbp_get_forum_last_topic_title($forum_id);
        $forum_id_last_active = bbp_get_topic_forum_id($active_id);
    } elseif (bbp_is_reply($active_id)) {
        $link_url = bbp_get_forum_last_reply_url($forum_id);
        //$link-id added to get post-id and type to allow for later check
        $link_id = bbp_get_forum_last_reply_id($forum_id);
        $check = "reply";
        $title = bbp_get_forum_last_reply_title($forum_id);
        $forum_id_last_active = bbp_get_reply_forum_id($active_id);
    }
    $time_since = bbp_get_forum_last_active_time($forum_id);
    if (!empty($time_since) && !empty($link_url)) {
        //ADDITIONAL CODE to original bbp_get_forum_freshness_link function
        //test if user can see this post, and post link if they can
        $user_id = wp_get_current_user()->ID;
        //get the forum id for the post - that's the forum ID against which we check to see if it is in a group - no idea what forum group the stuff above produces, suspect post id of when last changed.
        $forum_id_check = private_groups_get_forum_id_from_post_id($link_id, $check);
        //now we can check if the user can view this, and if it's not private
        if (private_groups_can_user_view_post($user_id, $forum_id_check) && !bbp_is_forum_private($forum_id_last_active)) {
            $anchor = '<a href="' . esc_url($link_url) . '" title="' . esc_attr($title) . '">' . esc_html($time_since) . '</a>';
        } elseif (private_groups_can_user_view_post($user_id, $forum_id_check) && bbp_is_forum_private($forum_id_last_active) && current_user_can('read_private_forums')) {
            $anchor = '<a href="' . esc_url($link_url) . '" title="' . esc_attr($title) . '">' . esc_html($time_since) . '</a>';
        } else {
            //set up which link to send them to
            if (!is_user_logged_in()) {
                if ($rpg_settingsf['redirect_page2']) {
                    $link = $rpg_settingsf['redirect_page2'];
                } else {
                    $link = "/wp-login";
                }
            } else {
                if ($rpg_settingsf['redirect_page1']) {
                    $link = $rpg_settingsf['redirect_page1'];
                } else {
                    $link = '/404';
                }
            }
            //now see if there is a freshness message
            if ($rpg_settingsf['set_freshness_message']) {
                $title = $rpg_settingsf['freshness_message'];
                //and set up anchor
                $anchor = '<a href="' . esc_url($link) . '">' . $title . '</a>';
            } else {
                $anchor = '<a href="' . esc_url($link) . '">' . esc_html($time_since) . '</a>';
            }
        }
    } else {
        $anchor = esc_html__('No Topics', 'bbpress');
    }
    return $anchor;
}
/**
 * Output the url to the last reply in a forum
 *
 * @since bbPress (r2683)
 *
 * @param int $forum_id Optional. Forum id
 * @uses bbp_get_forum_last_reply_url() To get the forum last reply url
 */
function bbp_forum_last_reply_url($forum_id = 0)
{
    echo bbp_get_forum_last_reply_url($forum_id);
}
function firmasite_social_bbp_get_forum_freshness_link($forum_id = 0)
{
    $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);
    }
    if (bbp_is_topic($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)) {
        $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 = '<a href="' . $link_url . '" data-toggle="popover" data-rel="popover" data-placement="left" data-trigger="hover" data-html="true" data-original-title="' . __('Freshness', 'firmasite') . '" data-content="' . esc_attr($time_since) . '"><i class="icon-time"></i></a>&nbsp;' . __('Freshness', 'firmasite') . ':';
    } else {
        $anchor = __('No Topics', 'firmasite');
    }
    return apply_filters('bbp_get_forum_freshness_link', $anchor, $forum_id);
}