I'm facing difficulties in customizing the image upload path in JetFormBuilder and would like to request community assistance in resolving this issue.
I have created the following functions to handle image uploads and direct them to specific folders based on the post type:
// Function to handle image uploads
function custom_handle_upload($args) {
$post_id = isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : '';
$post_type = get_post_type($post_id);
if ($post_type !== 'banners') {
$filename = $args['file'];
$filename = convert_to_webp($filename);
$args['file'] = $filename;
}
return $args;
}
// Function to define the upload directory for images
function custom_upload_directory($args) {
$post_id = isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : '';
$post_type = get_post_type($post_id);
if ($post_type === 'post') {
$newdir = '/noticias';
} elseif ($post_type === 'banners') {
$newdir = '/banners';
} elseif ($post_type === 'eventos') {
$newdir = '/eventos';
} else {
return $args;
}
$args['path'] = $args['basedir'] . $newdir;
$args['url'] = $args['baseurl'] . $newdir;
return $args;
}
However, despite implementing these functions, the images continue to be sent to the JetFormBuilder's default folder instead of being directed to the specific folders I defined in the code.
I have checked the function priority order, folder permissions, and compatibility with the latest versions of JetFormBuilder and WordPress, but still haven't been able to resolve the issue.
I would like to request suggestions and guidance on how I can fix this problem and ensure that the images are directed to the correct folders after upload.
I appreciate your help and suggestions in advance!
Hello JetFormBuilder team and community members,
I'm facing difficulties in customizing the image upload path in JetFormBuilder and would like to request community assistance in resolving this issue.
I have created the following functions to handle image uploads and direct them to specific folders based on the post type:
// Function to handle image uploads function custom_handle_upload($args) { $post_id = isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : ''; $post_type = get_post_type($post_id); if ($post_type !== 'banners') { $filename = $args['file']; $filename = convert_to_webp($filename); $args['file'] = $filename; } return $args; }
// Function to define the upload directory for images function custom_upload_directory($args) { $post_id = isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : ''; $post_type = get_post_type($post_id); if ($post_type === 'post') { $newdir = '/noticias'; } elseif ($post_type === 'banners') { $newdir = '/banners'; } elseif ($post_type === 'eventos') { $newdir = '/eventos'; } else { return $args; } $args['path'] = $args['basedir'] . $newdir; $args['url'] = $args['baseurl'] . $newdir; return $args; } However, despite implementing these functions, the images continue to be sent to the JetFormBuilder's default folder instead of being directed to the specific folders I defined in the code.
I have checked the function priority order, folder permissions, and compatibility with the latest versions of JetFormBuilder and WordPress, but still haven't been able to resolve the issue.
I would like to request suggestions and guidance on how I can fix this problem and ensure that the images are directed to the correct folders after upload.
I appreciate your help and suggestions in advance!
Best regards, Alan