Created
May 3, 2020 18:54
-
-
Save vfontjr/199632e7e3d1447c4aeb0510e1b25dec to your computer and use it in GitHub Desktop.
Source code for https://victorfont.com/formidable-pro-rename-upload-file/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('sanitize_file_name', 'rename_image', 10, 2); | |
function rename_image($filename, $filename_raw) { | |
if ($_POST['form_id'] == '6') { | |
$firstname = $_POST['item_meta'][83] . '-'; | |
$lastname = $_POST['item_meta'][84] . '-'; | |
$category = $_POST['item_meta'][88] . '-'; | |
$imagename = $_POST['item_meta'][85] . '-'; | |
$assigned = $_POST['item_meta'][86] . '-'; | |
$print = $_POST['item_meta'][87]; | |
$info = pathinfo($filename); | |
$ext = empty($info['extension']) ? '' : '.' . $info['extension']; | |
$new = $firstname . $lastname . $category . $imagename . $assigned . $print . $ext; | |
if( $new != $filename_raw ) { | |
$new = sanitize_file_name( $new ); | |
} | |
return $new; | |
} else { | |
return $filename; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment