Created
December 17, 2025 14:13
-
-
Save dexit/e5d799774908208a3a15b0be15d84b8f to your computer and use it in GitHub Desktop.
elementor-pro-form-file-upload-folder-by-formid.php
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 | |
| /** | |
| * Change upload folder based on Elementor Form ID | |
| * | |
| * @param $path | |
| * @return string | |
| */ | |
| function zpd_change_elementor_form_upload_path_multi_form( $path ){ | |
| if( $_POST[ 'action'] === 'elementor_pro_forms_send_form'){ | |
| //The folder name | |
| $folder = 'elementor-file-uploads-form-id-' . $_POST[ 'form_id' ]; | |
| } | |
| else { | |
| $folder = 'elementor-file-uploads'; | |
| } | |
| // Get the WordPress uploads folder | |
| $wp_upload_dir = wp_upload_dir(); | |
| // This is the new path where we want to store the Form file uploads | |
| $path = $wp_upload_dir['basedir'] . '/' . $folder; | |
| /** | |
| * Check to see if the folder already exists, create if not. | |
| */ | |
| if ( !file_exists( $path ) ) { | |
| mkdir( $path, 0755, true); | |
| } | |
| return $path; | |
| } | |
| add_filter( 'elementor_pro/forms/upload_path', 'zpd_change_elementor_form_upload_path_multi_form', 10, 1 ); | |
| /** | |
| * Change default location of Elementor's form file uploads URL | |
| * | |
| * @param $file_name | |
| * @return string | |
| */ | |
| function zpd_change_elementor_form_upload_file_url_multi_form( $file_name ){ | |
| error_log( print_r( $_POST, true )); | |
| if( $_POST[ 'action'] === 'elementor_pro_forms_send_form'){ | |
| //The folder name | |
| $folder = 'elementor-file-uploads-form-id-' . $_POST[ 'form_id' ]; | |
| } | |
| else { | |
| $folder = 'elementor-file-uploads'; | |
| } | |
| // Get the WordPress uploads folder | |
| $wp_upload_dir = wp_upload_dir(); | |
| // This is the new file URL path | |
| $filename_arr = explode( '/', $file_name ); | |
| $url = $wp_upload_dir['baseurl'] . '/' . $folder . '/' . end( $filename_arr ); | |
| return $url; | |
| } | |
| add_filter( 'elementor_pro/forms/upload_url', 'zpd_change_elementor_form_upload_file_url_multi_form', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment