Formidable Pro Rename Upload File-public domain image from pixabay.com

Formidable Pro Rename Upload File

Formidable Pro Rename Upload File-public domain image from pixabay.com
As of the release of Formidable Pro V2.02, the process described in this article will no longer work. The Formidable Pro developers abandoned the standard WordPress upload functions in favor of a drag and drop jQuery Ajax uploader. While this is more efficient, it offers significant challenges because the files are uploaded before the form is submitted. When time permits, I’ll look into a method for renaming files with this new process. In the meantime, the original article is below and will work with Formidable Pro versions released prior to V2.02.

When Michael Jenson needed help customizing the name of image uploads through a Formidable Pro form, Stephanie Wells of Strategy 11, the author of Formidable Pro, recommended that he contact us for assistance. We do a lot of custom Formidable Pro work and know the product well. Michael’s form is located at http://cameraclub.photos/exhibition-upload/. His request:

What I’m looking for is to take all of the fields from this form (except email address) and use them to rename a jpeg image file upon upload. I have several clients who are camera clubs and they are requesting this functionality.

This is a screen print of Michael’s form:

Exhibition Upload Form

To clarify the requirement, I responded:

So let’s say I upload an image in category aa, you want the image name to be: victor-font-aa-imagename-open-digital.jpg. Is that correct?

Michael confirmed his requirement and shortly thereafter, I sent the following code to him for testing with instructions to copy it into his child theme’s functions.php file.

rename_imagehttps://gist.github.com/vfontjr/199632e7e3d1447c4aeb0510e1b25dec#file-rename_image-php

Michael’s response:

This worked awesome!

This Can Work With Most Any Form

The beauty of this code is that with a little modification it could work with any form that uses the WordPress upload process as Formidable Pro does. You would have to determine how your form tool identifies its forms and the naming convention for the fields. The code intercepts and sanitizes the filename just before WordPress saves it. If you need help, you can always reach out to us.

To learn more about PHP’s pathinfo() function visit: http://www.w3schools.com/php/func_filesystem_pathinfo.asp
To learn more about the sanitize_file_name filter visit: https://codex.wordpress.org/Function_Reference/sanitize_file_name