bp_document_attach_document_to_message( $message )
Attach document to the message object.
Description
Parameters
- $message
-
(Required)
Source
File: bp-document/bp-document-filters.php
function bp_document_attach_document_to_message( &$message ) { if ( bp_is_messages_document_support_enabled() && ! empty( $message->id ) && ! empty( $_POST['document'] ) ) { remove_action( 'bp_document_add', 'bp_activity_document_add', 9 ); remove_filter( 'bp_document_add_handler', 'bp_activity_create_parent_document_activity', 9 ); $document_list = $_POST['document']; $document_ids = array(); foreach ( $document_list as $document_index => $document ) { $title = ! empty( $document['name'] ) ? $document['name'] : ' '; $attachment_id = ! empty( $document['id'] ) ? $document['id'] : 0; $menu_order = ! empty( $document['menu_order'] ) ? $document['menu_order'] : 0; $attachment_data = get_post( $document['id'] ); $file = get_attached_file( $document['id'] ); $file_type = wp_check_filetype( $file ); $file_name = basename( $file ); $document_id = bp_document_add( array( 'attachment_id' => $attachment_id, 'title' => $title, 'privacy' => 'message', 'error_type' => 'wp_error', 'menu_order' => $menu_order, ) ); if ( ! empty( $document_id ) && ! is_wp_error( $document_id ) ) { $document_ids[] = $document_id; // save document meta. bp_document_update_meta( $document_id, 'file_name', $file_name ); bp_document_update_meta( $document_id, 'thread_id', $message->thread_id ); bp_document_update_meta( $document_id, 'extension', '.' . $file_type['ext'] ); // save document is saved in attachment. update_post_meta( $attachment_id, 'bp_document_saved', true ); } } $document_ids = implode( ',', $document_ids ); // save document meta for message. bp_messages_update_meta( $message->id, 'bp_document_ids', $document_ids ); add_action( 'bp_document_add', 'bp_activity_document_add', 9 ); add_filter( 'bp_document_add_handler', 'bp_activity_create_parent_document_activity', 9 ); } }
Changelog
Version | Description |
---|---|
BuddyBoss 1.4.0 | 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.