Hello Blub69,
Try to put this code in your bp-custom.php or in your function.php
This function normally names the file with its extension. Useful for differentiating files. Only valid for new files, it does not rename old ones.
See you soon
if( function_exists ( 'buddydrive' ) ) {
remove_action( 'wp_ajax_buddydrive_upload', 'buddydrive_upload_file' );
function cust_buddydrive_upload_file() {
$is_html4 = false;
if ( ! empty( $_POST['html4' ] ) ) {
$is_html4 = true;
}
if ( empty( $_POST['bp_params'] ) && buddydrive_use_deprecated_ui() ) {
buddydrive_save_new_buddyfile();
return;
}
check_admin_referer( 'bp-uploader' );
$bp_params = (array) $_POST['bp_params' ];
if ( empty( $bp_params['item_id'] ) ) {
bp_attachments_json_response( false, $is_html4 );
}
if ( ! is_user_logged_in() || ( (int) bp_loggedin_user_id() !== (int) $bp_params['item_id'] && ! bp_current_user_can( 'bp_moderate' ) ) ) {
bp_attachments_json_response( false, $is_html4 );
}
$bd_file = buddydrive_upload_item( $_FILES, $bp_params['item_id'] );
if ( ! empty( $bd_file['error'] ) ) {
bp_attachments_json_response( false, $is_html4, array(
'type' => 'upload_error',
'message' => $bd_file['error'],
) );
}
$name_parts = pathinfo( $bd_file['file'] );
$url = $bd_file['url'];
$mime = $bd_file['type'];
$file = $bd_file['file'];
$title = $name_parts['basename'];
$privacy = buddydrive_get_default_privacy();
$groups = array();
$parent_folder_id = 0;
if ( ! empty( $bp_params['parent_folder_id'] ) ) {
$parent_folder_id = (int) $bp_params['parent_folder_id'];
}
if ( ! empty( $bp_params['privacy'] ) ) {
$privacy = $bp_params['privacy'];
if ( ! empty( $bp_params['privacy_item_id'] ) && 'groups' === $privacy ) {
$groups = (array) $bp_params['privacy_item_id'];
}
}
$buddyfile_id = buddydrive_add_item( array(
'user_id' => $bp_params['item_id'],
'type' => buddydrive_get_file_post_type(),
'guid' => $url,
'title' => $title,
'mime_type' => $mime,
'privacy' => $privacy,
'groups' => $groups,
'parent_folder_id' => $parent_folder_id,
) );
if ( empty( $buddyfile_id ) ) {
bp_attachments_json_response( false, $is_html4, array(
'type' => 'upload_error',
'message' => __( 'Error while creating the file, sorry.', 'buddydrive' ),
) );
} else {
if ( 'public' === $privacy ) {
buddydrive_set_thumbnail( $buddyfile_id, $bd_file );
}
}
$response = buddydrive_prepare_for_js( $buddyfile_id );
$response['buddydrive_id'] = $response['id'];
$response['url'] = $response['link'];
$response['uploaded'] = true;
unset( $response['id'] );
bp_attachments_json_response( true, $is_html4, $response );
}
add_action( 'wp_ajax_buddydrive_upload', 'cust_buddydrive_upload_file' );
}