Change upload folder for multiple forms

By: Mohit Manderna | Asked: 07/11/2024
ForumsCategory: How-toChange upload folder for multiple forms
Mohit Manderna asked 4 months ago

I am using this hook to change the file upload folder:

add_filter( 'frm_upload_folder', 'frm_custom_upload', 10, 2 );
function frm_custom_upload( $folder, $atts ) {
if ( $atts['form_id'] == 2 ) { // change to your form id
global $current_user;
$folder = '/ms/' . $current_user->wpc_cf_client_file_cat;
}
return $folder;
}

 

Now, I want to keep this folder for other forms as well. For example, for both Form ID 2 and 35. How can I do this?

1 Answers
Best Answer
Bobby Clapp answered 4 months ago

Maybe put the form ids into an array and loop through using the dynamic value. Something like this:

add_filter( 'frm_upload_folder', 'frm_custom_upload', 10, 2 );
function frm_custom_upload( $folder, $atts ) {
$formids = [2,35];
foreach ($formids as $val) {
if ( $atts['form_id'] == $val ) {
global $current_user;
$folder = '/ms/' . $current_user->wpc_cf_client_file_cat;
}
return $folder;
}
}

Mohit Manderna replied 4 months ago

Thanks a lot.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right