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

3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
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

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.