@@ -17,10 +17,10 @@ function wplf_ajax_submit_handler() {
1717 // @see: wplf-form-validation.php
1818 $ return = apply_filters ( 'wplf_validate_submission ' , $ return );
1919
20- if ( $ return ->ok ) {
21- // form existence has already been validated via filters
22- $ form = get_post ( intval ( $ _POST ['_form_id ' ] ) );
20+ // form existence has already been validated via filters
21+ $ form = get_post ( intval ( $ _POST ['_form_id ' ] ) );
2322
23+ if ( $ return ->ok ) {
2424 // form-specific validation
2525 $ return ->slug = $ form ->post_name ;
2626 $ return ->title = $ form ->post_title ;
@@ -93,10 +93,16 @@ function wplf_ajax_submit_handler() {
9393 add_post_meta ( $ post_id , $ key . '_attachment ' , $ attach_id );
9494 }
9595 } else {
96- $ name = 'lf_ ' . date ( 'ymdhs ' ) . '- ' . $ counter . '- ' . sanitize_file_name ( $ file ['name ' ] );
96+ $ file ['field_name ' ] = $ key ;
97+
98+ $ default_file_name = 'lf_ ' . date ( 'ymdhs ' ) . '- ' . $ counter . '- ' . $ file ['name ' ];
99+ $ file_name = sanitize_file_name ( apply_filters ( 'wplf_uploaded_file_name ' , $ default_file_name , $ file , $ post_id ) );
100+
101+ $ file_path = $ uploads_path ['path ' ] . '/ ' . $ file_name ;
102+ $ file_path = apply_filters ( 'wplf_uploaded_file_path ' , $ file_path , $ file , $ post_id );
97103
98- move_uploaded_file ( $ file ['tmp_name ' ], $ uploads_path [ ' path ' ] . ' / ' . $ name );
99- add_post_meta ( $ post_id , $ key . '_attachment ' , $ uploads_path [ ' url ' ] . ' / ' . $ name );
104+ move_uploaded_file ( $ file ['tmp_name ' ], $ file_path );
105+ add_post_meta ( $ post_id , $ key . '_attachment ' , $ file_path );
100106 $ counter ++;
101107 }
102108 }
0 commit comments