bp_document_add_handler( array $documents = array(), string $privacy = 'public', string $content = '', int $group_id = false, int $folder_id = false )
Document add handler function
Description
Parameters
- $documents
-
(Optional)
Default value: array()
- $privacy
-
(Optional)
Default value: 'public'
- $content
-
(Optional)
Default value: ''
- $group_id
-
(Optional)
Default value: false
- $folder_id
-
(Optional)
Default value: false
Return
(mixed|void)
Source
File: bp-document/bp-document-functions.php
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 | function bp_document_add_handler( $documents = array () ) { global $bp_document_upload_count ; $document_ids = array (); if ( ! is_user_logged_in() ) { return false; } if ( empty ( $documents ) && ! empty ( $_POST [ 'document' ] ) ) { $documents = $_POST [ 'document' ]; } $privacy = ! empty ( $_POST [ 'privacy' ] ) && in_array( $_POST [ 'privacy' ], array_keys ( bp_document_get_visibility_levels() ) ) ? $_POST [ 'privacy' ] : 'public' ; if ( ! empty ( $documents ) && is_array ( $documents ) ) { // update count of documents for later use. $bp_document_upload_count = count ( $documents ); // save document. foreach ( $documents as $document ) { $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' => $document [ 'id' ], 'title' => $document [ 'name' ], 'folder_id' => ! empty ( $document [ 'folder_id' ] ) ? $document [ 'folder_id' ] : false, 'group_id' => ! empty ( $document [ 'group_id' ] ) ? $document [ 'group_id' ] : false, 'privacy' => ! empty ( $document [ 'privacy' ] ) && in_array( $document [ 'privacy' ], array_merge ( array_keys ( bp_document_get_visibility_levels() ), array ( 'message' ) ) ) ? $document [ 'privacy' ] : $privacy , 'menu_order' => ! empty ( $document [ 'menu_order' ] ) ? $document [ 'menu_order' ] : 0, 'error_type' => 'wp_error' , ) ); if ( ! empty ( $document_id ) && ! is_wp_error( $document_id ) ) { bp_document_update_meta( $document_id , 'file_name' , $file_name ); bp_document_update_meta( $document_id , 'extension' , '.' . $file_type [ 'ext' ] ); } if ( $document_id ) { $document_ids [] = $document_id ; } } } /** * Fires at the end of the execution of adding saving a document item, before returning the new document items in ajax response. * * @param array $document_ids document IDs. * @param array $documents Array of document from POST object or in function parameter. * * @since BuddyBoss 1.4.0 */ return apply_filters( 'bp_document_add_handler' , $document_ids , ( array ) $documents ); } |
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.