bp_document_upload_handler( string $file_id = 'file' )
document upload handler
Description
Parameters
- $file_id
-
(Optional)
Default value: 'file'
Return
(array|int|null|WP_Error|WP_Post)
Source
File: bp-document/bp-document-functions.php
1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 | function bp_document_upload_handler( $file_id = 'file' ) { /** * Include required files. */ if ( ! function_exists( 'wp_generate_attachment_metadata' ) ) { require_once ABSPATH . 'wp-admin' . '/includes/image.php' ; require_once ABSPATH . 'wp-admin' . '/includes/file.php' ; require_once ABSPATH . 'wp-admin' . '/includes/media.php' ; } if ( ! function_exists( 'media_handle_upload' ) ) { require_once ABSPATH . 'wp-admin/includes/admin.php' ; } add_filter( 'upload_mimes' , 'bp_document_allowed_mimes' , 9999999, 1 ); $aid = media_handle_upload( $file_id , 0, array (), array ( 'test_form' => false, 'upload_error_strings' => array ( false, __( 'The uploaded file exceeds ' , 'buddyboss' ) . bp_document_file_upload_max_size( true ), __( 'The uploaded file exceeds ' , 'buddyboss' ) . bp_document_file_upload_max_size( true ), __( 'The uploaded file was only partially uploaded.' , 'buddyboss' ), __( 'No file was uploaded.' , 'buddyboss' ), '' , __( 'Missing a temporary folder.' , 'buddyboss' ), __( 'Failed to write file to disk.' , 'buddyboss' ), __( 'File upload stopped by extension.' , 'buddyboss' ), ), ) ); // if has wp error then throw it. if ( is_wp_error( $aid ) ) { return $aid ; } $attachment = get_post( $aid ); if ( ! empty ( $attachment ) ) { update_post_meta( $attachment ->ID, 'bp_document_upload' , true ); update_post_meta( $attachment ->ID, 'bp_document_saved' , '0' ); return $attachment ; } return new WP_Error( 'error_uploading' , __( 'Error while uploading document.' , 'buddyboss' ), array ( 'status' => 500 ) ); } |
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.