bbp_unstick_topic( int $topic_id )

Unsticks a topic both from front and it’s forum


Description Description


Parameters Parameters

$topic_id

(Optional) Topic id


Top ↑

Return Return

(bool) Always true.


Top ↑

Source Source

File: includes/topics/functions.php

function bbp_unstick_topic( $topic_id = 0 ) {

	// Get topic sticky status
	$topic_id = bbp_get_topic_id( $topic_id );
	$super    = bbp_is_topic_super_sticky( $topic_id );
	$forum_id = empty( $super ) ? bbp_get_topic_forum_id( $topic_id ) : 0;
	$stickies = bbp_get_stickies( $forum_id );
	$offset   = array_search( $topic_id, $stickies );

	do_action( 'bbp_unstick_topic', $topic_id );

	// Nothing to unstick
	if ( empty( $stickies ) ) {
		$success = true;

	// Topic not in stickies
	} elseif ( ! in_array( $topic_id, $stickies, true ) ) {
		$success = true;

	// Topic not in stickies
	} elseif ( false === $offset ) {
		$success = true;

	// Splice out the offset
	} else {
		array_splice( $stickies, $offset, 1 );

		if ( empty( $stickies ) ) {
			$success = ! empty( $super )
				? delete_option( '_bbp_super_sticky_topics' )
				: delete_post_meta( $forum_id, '_bbp_sticky_topics' );
		} else {
			$success = ! empty( $super )
				? update_option( '_bbp_super_sticky_topics', $stickies )
				: update_post_meta( $forum_id, '_bbp_sticky_topics', $stickies );
		}
	}

	do_action( 'bbp_unstuck_topic', $topic_id, $success );

	return (bool) $success;
}

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.