bp_nouveau_ajax_document_document_save()
Save document
Description
Source
File: bp-templates/bp-nouveau/includes/document/ajax.php
function bp_nouveau_ajax_document_document_save() {
$response = array(
'feedback' => sprintf(
'<div class="bp-feedback error bp-ajax-message"><span class="bp-icon" aria-hidden="true"></span><p>%s</p></div>',
esc_html__( 'There was a problem performing this action. Please try again.', 'buddyboss' )
),
);
// Bail if not a POST action.
if ( ! bp_is_post_request() ) {
wp_send_json_error( $response );
}
if ( empty( $_POST['_wpnonce'] ) ) {
wp_send_json_error( $response );
}
// Use default nonce.
$nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
$check = 'bp_nouveau_media';
// Nonce check!
if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, $check ) ) {
wp_send_json_error( $response );
}
if ( empty( $_POST['documents'] ) ) {
$response['feedback'] = sprintf(
'<div class="bp-feedback error"><span class="bp-icon" aria-hidden="true"></span><p>%s</p></div>',
esc_html__( 'Please upload a document before saving.', 'buddyboss' )
);
wp_send_json_error( $response );
}
if ( ! is_user_logged_in() ) {
$response['feedback'] = sprintf(
'<div class="bp-feedback error"><span class="bp-icon" aria-hidden="true"></span><p>%s</p></div>',
esc_html__( 'Please login to upload a document.', 'buddyboss' )
);
wp_send_json_error( $response );
}
if ( isset( $_POST['documents'] ) && ! empty( $_POST['documents'] ) && isset( $_POST['folder_id'] ) && (int) $_POST['folder_id'] > 0 ) {
$documents = $_POST['documents'];
$folder_id = (int) $_POST['folder_id'];
if ( ! empty( $documents ) && is_array( $documents ) ) {
// set folder id for document.
foreach ( $documents as $key => $document ) {
if ( 0 === (int) $document['folder_id'] ) {
$_POST['documents'][ $key ]['folder_id'] = $folder_id;
}
}
}
}
// handle media uploaded.
$document_ids = bp_document_add_handler( $_POST['documents'] );
$document = '';
if ( ! empty( $document_ids ) ) {
ob_start();
if ( bp_has_document( array( 'include' => implode( ',', $document_ids ) ) ) ) {
while ( bp_document() ) {
bp_the_document();
bp_get_template_part( 'document/document-entry' );
}
}
$document = ob_get_contents();
ob_end_clean();
}
wp_send_json_success( array( 'document' => $document ) );
}
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.