BP_REST_Topics_Actions_Endpoint::rest_update_sticky( integer $topic_id, string $action, boolean $value )

Update sticky things for the topic.

Description

Parameters

$topic_id

(Required) Topic ID.

$action

(Required) Action name to update.

$value

(Required) Action value.

Return

(bool|WP_Error)

Source

File: bp-forums/classes/class-bp-rest-topics-actions-endpoint.php

1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
protected function rest_update_sticky( $topic_id, $action, $value ) {
    // What is the user doing here?
    if ( ! current_user_can( 'moderate', $topic_id ) ) {
        return new WP_Error(
            'bp_rest_authorization_required',
            __( 'You do not have permission to do this.', 'buddyboss' ),
            array(
                'status' => 404,
            )
        );
    }
 
    $is_super = ( 'super_sticky' === $action ) ? true : false;
 
    $is_sticky = bbp_is_topic_sticky( $topic_id );
    $status    = true;
 
    if ( true === $is_sticky && empty( $value ) ) {
        $status = bbp_unstick_topic( $topic_id );
 
    } elseif ( false === $is_sticky && ! empty( $value ) ) {
        $status = bbp_stick_topic( $topic_id, $is_super );
    }
 
    return $status;
}

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.