Thank you, your code works perfectly.
One more question, is it possible to remove not only the uploaded file, but also the file structure from the server after a email has been sent:
In the upload folder remains a folder of random name, with a css folder etc.
The code I’m using is:
if ( ! defined( 'ABSPATH' ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
return;
}
add_action( 'forminator_custom_form_mail_admin_sent', 'delete_upload_after_email', 99, 5 );
function delete_upload_after_email( $instance, $custom_form, $data, $entry, $recipients ) {
foreach ( $entry->meta_data as $field_name => $field ) {
if ( false !== strpos( $field_name, 'upload' ) ) {
foreach ( $field['value']['file'] as $key => $value ) {
if ( 'file_path' === $key && ! empty( $value ) ) {
if ( is_array( $value ) ) {
foreach ( $value as $path ) {
wp_delete_file( $path );
}
} else {
wp_delete_file( $value );
}
}
}
}
}
}