From e074a07f2508d6fa5baba644b69d43f89c00a9fb Mon Sep 17 00:00:00 2001 From: Denis Baranov Date: Fri, 20 Oct 2017 12:39:45 +0300 Subject: [PATCH 1/2] -fixed saving files to register a new user, if there are fields with files --- includes/core/um-actions-register.php | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/includes/core/um-actions-register.php b/includes/core/um-actions-register.php index 8d8bf0c3..d877311c 100644 --- a/includes/core/um-actions-register.php +++ b/includes/core/um-actions-register.php @@ -295,4 +295,41 @@ function um_add_register_fields($args){ echo UM()->fields()->display( 'register', $args ); + } + + + ** + * Saving files to register a new user, if there are fields with files + */ + add_action( 'um_registration_set_extra_data', 'um_registration_save_files', 10, 2 ); + function um_registration_save_files( $user_id, $args ) { + $files = array(); + + $fields = unserialize( $args['custom_fields'] ); + + // loop through fields + if ( isset( $fields ) && is_array( $fields ) ) { + + foreach ( $fields as $key => $array ) { + + if ( isset( $args['submitted'][$key] ) ) { + + if ( isset( $fields[$key]['type'] ) && in_array( $fields[$key]['type'], array( 'image', 'file' ) ) && + ( um_is_temp_upload( $args['submitted'][$key] ) || $args['submitted'][$key] == 'empty_file' ) + ) { + + $files[$key] = $args['submitted'][$key]; + + } + } + } + } + + $files = apply_filters( 'um_user_pre_updating_files_array', $files ); + + if ( !empty( $files ) ) { + do_action( 'um_before_user_upload', $user_id, $files ); + UM()->user()->update_files( $files ); + do_action( 'um_after_user_upload', $user_id, $files ); + } } \ No newline at end of file From 853ef046387761e25ca8307cc1521e3208a2ca8f Mon Sep 17 00:00:00 2001 From: Denis Baranov Date: Fri, 20 Oct 2017 12:58:25 +0300 Subject: [PATCH 2/2] - fixed saving files to register a new user, if there are fields with files #2 --- includes/core/um-actions-register.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/core/um-actions-register.php b/includes/core/um-actions-register.php index d877311c..f125f156 100644 --- a/includes/core/um-actions-register.php +++ b/includes/core/um-actions-register.php @@ -298,7 +298,7 @@ } - ** + /** * Saving files to register a new user, if there are fields with files */ add_action( 'um_registration_set_extra_data', 'um_registration_save_files', 10, 2 );