Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hi?@maybeyesmaybeno

    I hope you are doing well.

    I pinged our developers to verify which is the best solution to accomplish this, we will reply once they provide an update.

    Best Regards

    Luis

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @maybeyesmaybeno ,

    Please try the following code snippet as mu-plugin https://premium.wpmudev.org/docs/getting-started/download-wpmu-dev-plugins-themes/#installing-mu-plugins

    add_filter( 'forminator_custom_form_after_render_value', function( $value, $custom_form, $field_slug ){
    	if ( false !== strpos( $field_slug, 'upload-') ) {
    		$value = '';
    	}
    	return $value;
    },10, 3);
    
    add_filter( 'forminator_custom_form_mail_admin_message', function( $message, $custom_form, $data, $entry, $cls ) {
        $form_fields   = $custom_form ? $custom_form->get_fields() : array();
    	foreach ( $form_fields as $field ) {
    		$field_array    = $field->to_formatted_array();
    		if ( false !== strpos( $field_array['element_id'], 'upload-') ) {
                $message = str_replace('<li><b>'.$field_array['field_label'].'</b><br/></li>', '', $message);
            }
        }
        return $message;
    },10, 5);

    kind regards,
    Kasia

    Thread Starter MaybeYesMaybeNo

    (@maybeyesmaybeno)

    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 );
    
    }
    
    }
    
    }
    
    }
    
    }
    
    }



    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @maybeyesmaybeno,

    We have pinged our developers to check if the code could be further improved to remove the file structure as well and we’ll update you here once we have more feedback on this as soon as possible.

    Kind Regards,
    Nebu John

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @maybeyesmaybeno,

    Sorry for the delay regarding this. We got further feedback and I’m afraid there isn’t an easy workaround to remove the file structure/uploaded file and won’t recommend performing such actions because the form style loads from the CSS folder and changes can affect how the form functions.

    Kind Regards,

    Nithin

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @maybeyesmaybeno ,

    We haven’t heard from you for over a week now, so it looks like you don’t have further questions.

    Kind regards
    Kasia

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Delete attached files’ is closed to new replies.