bbp_get_single_topic_description( array $args = array() )

Return a fancy description of the current topic, including total topics, total replies, and last activity.


Description Description


Parameters Parameters

$args

(Optional) This function supports these arguments: - topic_id: Topic id - before: Before the text - after: After the text - size: Size of the avatar

Default value: array()


Top ↑

Return Return

(string) Filtered topic description


Top ↑

Source Source

File: includes/topics/template.php

	function bbp_get_single_topic_description( $args = array() ) {

		// Parse arguments against default values
		$r = bbp_parse_args( $args, array(
			'topic_id'  => 0,
			'before'    => '<div class="bbp-template-notice info"><ul><li class="bbp-topic-description">',
			'after'     => '</li></ul></div>',
			'size'      => 14
		), 'get_single_topic_description' );

		// Validate topic_id
		$topic_id = bbp_get_topic_id( $r['topic_id'] );

		// Unhook the 'view all' query var adder
		remove_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' );

		// Build the topic description
		$vc_int      = bbp_get_topic_voice_count   ( $topic_id, true  );
		$voice_count = bbp_get_topic_voice_count   ( $topic_id, false );
		$reply_count = bbp_get_topic_replies_link  ( $topic_id        );
		$time_since  = bbp_get_topic_freshness_link( $topic_id        );

		// Singular/Plural
		$voice_count = sprintf( _n( '%s voice', '%s voices', $vc_int, 'bbpress' ), $voice_count );

		// Topic has activity (could be from reply or topic author)
		$last_active = bbp_get_topic_last_active_id( $topic_id );
		if ( ! empty( $vc_int ) && ! empty( $last_active ) ) {
			$last_updated_by = bbp_get_author_link( array( 'post_id' => $last_active, 'size' => $r['size'] ) );
			$retstr          = sprintf( esc_html__( 'This topic has %1$s, %2$s, and was last updated %3$s by %4$s.', 'bbpress' ), $reply_count, $voice_count, $time_since, $last_updated_by );

		// Topic has no replies
		} elseif ( ! empty( $vc_int ) && ! empty( $reply_count ) ) {
			$retstr = sprintf( esc_html__( 'This topic has %1$s and %2$s.', 'bbpress' ), $voice_count, $reply_count );

		// Topic has no replies and no voices
		} elseif ( empty( $vc_int ) && empty( $reply_count ) ) {
			$retstr = esc_html__( 'This topic has no replies.', 'bbpress' );

		// Topic is pending
		} elseif ( bbp_get_topic_status( $topic_id ) === bbp_get_pending_status_id() ) {
			$retstr = esc_html__( 'This topic is pending moderation.', 'bbpress' );

		// Fallback
		} else {
			$retstr = esc_html__( 'This topic is empty.', 'bbpress' );
		}

		// Add the 'view all' filter back
		add_filter( 'bbp_get_topic_permalink', 'bbp_add_view_all' );

		// Combine the elements together
		$retstr = $r['before'] . $retstr . $r['after'];

		// Filter & return
		return apply_filters( 'bbp_get_single_topic_description', $retstr, $r, $args );
	}

Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.