BP_REST_Topics_Actions_Endpoint::rest_update_close( integer $topic_id, boolean $value )

Update status for the topic.

Description

Parameters

$topic_id

(Required) Topic ID.

$value

(Required) Action value.

Return

(bool|WP_Error)

Source

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

1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
protected function rest_update_close( $topic_id, $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_open = bbp_is_topic_open( $topic_id );
    $status  = true;
 
    if ( true === $is_open && ! empty( $value ) ) {
        $status = bbp_close_topic( $topic_id );
 
    } elseif ( false === $is_open && empty( $value ) ) {
        $status = bbp_open_topic( $topic_id );
    }
 
    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.