Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active February 22, 2019 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Shelob9/63642d00f1486d78408d3192448334c6 to your computer and use it in GitHub Desktop.
Save Shelob9/63642d00f1486d78408d3192448334c6 to your computer and use it in GitHub Desktop.
One way to prevent files, uploaded through Caldera Forms file fields, not set to be added to media library, from being deleted.
<?php
/** Wait until caldera_forms_core_init hook so we know all actions were added **/
add_action( 'caldera_forms_core_init', function() {
//File delete is attempted first here, but if an email should send, the file isn't deleted//
remove_action( 'caldera_forms_submit_complete', array( 'Caldera_Forms_Files', 'cleanup' ) );
//If email is set to be used, we wait until email is sent to delete on these hooks:
remove_action( 'caldera_forms_mailer_complete', array( 'Caldera_Forms_Files', 'delete_after_mail' ), 10, 3 );
remove_action( 'caldera_forms_mailer_failed', array( 'Caldera_Forms_Files', 'delete_after_mail' ), 10, 3 );
//Just in case of a never completed submission or some other issue, a CRON job is used to delete the file
remove_all_actions( Caldera_Forms_Files::CRON_ACTION );
}
@xrahat2011
Copy link

Shouldn't the code end with a ")"?

@st3phan76
Copy link

+1

line 14:
} );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment