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

Move topic into trash or untrash.

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

1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
protected function rest_update_trash( $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,
            )
        );
    }
 
    $post_status = get_post_status( $topic_id );
 
    if ( 'trash' === $post_status && empty( $value ) ) {
        $status = wp_untrash_post( $topic_id );
    } elseif ( 'trash' !== $post_status && ! empty( $value ) ) {
        $status = wp_trash_post( $topic_id );
    }
 
    return ( ! empty( $status ) && ! is_wp_error( $status ) ? true : $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.