bp_nouveau_ajax_document_upload()

Upload a document via a POST request.

Description

Source

File: bp-templates/bp-nouveau/includes/document/ajax.php

138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
function bp_nouveau_ajax_document_upload() {
    $response = array(
        'feedback' => __( 'There was a problem when trying to upload this file.', 'buddyboss' ),
    );
 
    // Bail if not a POST action.
    if ( ! bp_is_post_request() ) {
        wp_send_json_error( $response, 500 );
    }
 
    if ( empty( $_POST['_wpnonce'] ) ) {
        wp_send_json_error( $response, 500 );
    }
 
    // 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, 500 );
    }
 
    add_filter( 'upload_dir', 'bp_document_upload_dir' );
 
    // Upload file.
    $result = bp_document_upload();
 
    remove_filter( 'upload_dir', 'bp_document_upload_dir' );
 
    if ( is_wp_error( $result ) ) {
 
        if ( bp_current_user_can( 'bp_moderate' ) ) {
            $error_msg = $result->get_error_message();
            if ( 'Sorry, this file type is not permitted for security reasons.' === $error_msg ) {
                $response['feedback'] = __( 'Make sure you whitelisted extension and MIME TYPE in media settings and added correct MIME TYPE in extension entry.', 'buddyboss' );
            } else {
                $response['feedback'] = $result->get_error_message();
            }
        } else {
            $response['feedback'] = $result->get_error_message();
        }
        wp_send_json_error( $response, $result->get_error_code() );
    }
 
    wp_send_json_success( $result );
}

Changelog

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.