bbp_get_topic_stick_link( mixed $args = '' )

Return the stick link of the topic

Description

Parameters

$args

(Optional) This function supports these args: - id: Optional. Topic id - link_before: Before the link - link_after: After the link - stick_text: Stick text - unstick_text: Unstick text - super_text: Stick to front text

Default value: ''

Return

(string) Topic stick link

Source

File: bp-forums/topics/template.php

2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
function bbp_get_topic_stick_link( $args = '' ) {
 
    // Parse arguments against default values
    $r = bbp_parse_args( $args, array(
        'id'           => 0,
        'link_before'  => '',
        'link_after'   => '',
        'stick_text'   => esc_html__( 'Stick',      'buddyboss' ),
        'unstick_text' => esc_html__( 'Unstick',    'buddyboss' ),
        'super_text'   => esc_html__( '(to front)', 'buddyboss' ),
    ), 'get_topic_stick_link' );
 
    $topic = bbp_get_topic( bbp_get_topic_id( (int) $r['id'] ) );
 
    if ( empty( $topic ) || !current_user_can( 'moderate', $topic->ID ) )
        return;
 
    $is_sticky = bbp_is_topic_sticky( $topic->ID );
 
    $stick_uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_stick', 'topic_id' => $topic->ID ) );
    $stick_uri = wp_nonce_url( $stick_uri, 'stick-topic_' . $topic->ID );
 
    $stick_display = ( true === $is_sticky ) ? $r['unstick_text'] : $r['stick_text'];
    $stick_display = '<a href="' . esc_url( $stick_uri ) . '" class="bbp-topic-sticky-link">' . $stick_display . '</a>';
 
    if ( empty( $is_sticky ) ) {
        $super_uri = add_query_arg( array( 'action' => 'bbp_toggle_topic_stick', 'topic_id' => $topic->ID, 'super' => 1 ) );
        $super_uri = wp_nonce_url( $super_uri, 'stick-topic_' . $topic->ID );
 
        $super_display = ' <a href="' . esc_url( $super_uri ) . '" class="bbp-topic-super-sticky-link">' . $r['super_text'] . '</a>';
    } else {
        $super_display = '';
    }
 
    // Combine the HTML into 1 string
    $retval = $r['link_before'] . $stick_display . $super_display . $r['link_after'];
 
    return apply_filters( 'bbp_get_topic_stick_link', $retval, $r );
}

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.