bbp_get_reply_url( int $reply_id, string $redirect_to = '' )

Return the paginated url to the reply in the reply loop


Description Description


Parameters Parameters

$reply_id

(Optional) Reply id

$redirect_to

(Optional) Pass a redirect value for use with shortcodes and other fun things.

Default value: ''


Top ↑

Return Return

(string) Link to reply relative to paginated topic


Top ↑

Source Source

File: includes/replies/template.php

	function bbp_get_reply_url( $reply_id = 0, $redirect_to = '' ) {

		// Set needed variables
		$reply_id = bbp_get_reply_id( $reply_id );

		// Juggle reply & topic IDs for unpretty URL formatting
		if ( bbp_is_reply( $reply_id ) ) {
			$topic_id = bbp_get_reply_topic_id( $reply_id );
			$topic    = bbp_get_topic( $topic_id );
		} elseif ( bbp_is_topic( $reply_id ) ) {
			$topic_id = bbp_get_topic_id( $reply_id );
			$topic    = bbp_get_topic( $topic_id );
			$reply_id = $topic_id;
		}

		// Hierarchical reply page
		if ( bbp_thread_replies() ) {
			$reply_page = 1;

		// Standard reply page
		} else {
			$reply_page = ceil( (int) bbp_get_reply_position( $reply_id, $topic_id ) / (int) bbp_get_replies_per_page() );
		}

		// Get links & URLS
		$reply_hash = '#post-' . $reply_id;
		$topic_link = bbp_get_topic_permalink( $topic_id, $redirect_to );
		$topic_url  = remove_query_arg( 'view', $topic_link );

		// Get vars needed to support pending topics with unpretty links
		$has_slug   = ! empty( $topic ) ? $topic->post_name : '';
		$pretty     = bbp_use_pretty_urls();
		$published  = ! bbp_is_topic_pending( $topic_id );

		// Don't include pagination if on first page
		if ( 1 >= $reply_page ) {

			// Pretty permalinks
			if ( ! empty( $has_slug ) && ! empty( $pretty ) && ! empty( $published ) ) {
				$url = user_trailingslashit( $topic_url ) . $reply_hash;

			// Unpretty links
			} else {
				$url = $topic_url . $reply_hash;
			}

		// Include pagination
		} else {

			// Pretty permalinks
			if ( ! empty( $has_slug ) && ! empty( $pretty ) && ! empty( $published ) ) {
				$url = trailingslashit( $topic_url ) . trailingslashit( bbp_get_paged_slug() ) . $reply_page;
				$url = user_trailingslashit( $url ) . $reply_hash;

			// Unpretty links
			} else {
				$url = add_query_arg( 'paged', $reply_page, $topic_url ) . $reply_hash;
			}
		}

		// Add topic view query arg back to end if it is set
		if ( bbp_get_view_all() ) {
			$url = bbp_add_view_all( $url );
		}

		// Filter & return
		return apply_filters( 'bbp_get_reply_url', $url, $reply_id, $redirect_to );
	}

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.