BP_REST_Document_Endpoint::bp_documents_update_rest_field_callback_messages( object $object, object $value, string $attribute )

The function to use to update the documents value of the messages REST Field.

Description

Parameters

$object

(Required) The BuddyPress component's object that was just created/updated during the request. (in this case the BP_Messages_Message object).

$value

(Required) The value of the REST Field to save.

$attribute

(Required) The REST Field key used into the REST response.

Return

(object)

Source

File: bp-document/classes/class-bp-rest-document-endpoint.php

2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
protected function bp_documents_update_rest_field_callback_messages( $object, $value, $attribute ) {
 
    if ( 'bp_documents' !== $attribute || empty( $object ) ) {
        $value->bp_documents = null;
        return $value;
    }
 
    $message_id = $value->id;
 
    $thread_id = $value->thread_id;
 
    $documents = wp_parse_id_list( $object );
 
    if ( empty( $documents ) ) {
        $value->bp_documents = null;
        return $value;
    }
 
    $args = array(
        'document_ids' => $documents,
        'privacy'      => 'message',
    );
 
    $document_ids = $this->bp_rest_create_document( $args );
 
    if ( is_wp_error( $document_ids ) ) {
        $value->bp_documents = $document_ids;
        return $value;
    }
 
    if ( ! empty( $document_ids ) ) {
        foreach ( $document_ids as $id ) {
            bp_document_add_meta( $id, 'thread_id', $thread_id );
        }
    }
 
    bp_messages_update_meta( $message_id, 'bp_document_ids', implode( ',', $document_ids ) );
}

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.