bbp_stick_topic( int $topic_id, int $super = false )
Sticks a topic to a forum or front
Description
Parameters
- $topic_id
-
(Optional) Topic id
- $super
-
(Optional) Should we make the topic a super sticky?
Default value: false
Return
(bool) True on success, false on failure
Source
File: bp-forums/topics/functions.php
function bbp_stick_topic( $topic_id = 0, $super = false ) {
$topic_id = bbp_get_topic_id( $topic_id );
// Bail if a topic is not a topic (prevents revisions as stickies)
if ( ! bbp_is_topic( $topic_id ) )
return false;
// We may have a super sticky to which we want to convert into a normal
// sticky and vice versa; unstick the topic first to avoid any possible error.
bbp_unstick_topic( $topic_id );
$forum_id = empty( $super ) ? bbp_get_topic_forum_id( $topic_id ) : 0;
$stickies = bbp_get_stickies( $forum_id );
do_action( 'bbp_stick_topic', $topic_id, $super );
if ( !is_array( $stickies ) ) {
$stickies = array( $topic_id );
} else {
$stickies[] = $topic_id;
}
// Pull out duplicates and empties
$stickies = array_unique( array_filter( $stickies ) );
// Unset incorrectly stuck revisions
foreach ( (array) $stickies as $key => $id ) {
if ( ! bbp_is_topic( $id ) ) {
unset( $stickies[$key] );
}
}
// Reset keys
$stickies = array_values( $stickies );
$success = !empty( $super ) ? update_option( '_bbp_super_sticky_topics', $stickies ) : update_post_meta( $forum_id, '_bbp_sticky_topics', $stickies );
do_action( 'bbp_sticked_topic', $topic_id, $super, $success );
return (bool) $success;
}
Changelog
| Version | Description |
|---|---|
| bbPress (r2754) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.