| @@ -32,9 +32,9 @@ | ||
| 32 | 32 | $created_count = $updated_row_counts['created']; |
| 33 | 33 | $updated_count = $updated_row_counts['updated']; |
| 34 | 34 | $skipped_count = $updated_row_counts['skipped']; |
| 35 | 35 | |
| 36 | - $data_array['role'] = trim($data_array['role']); | |
| 36 | + $data_array['role'] = trim(isset($data_array['role'])); | |
| 37 | 37 | if ( isset( $data_array['role'] ) && $data_array['role'] != '') { |
| 38 | 38 | $user_capability = ''; |
| 39 | 39 | if ( !is_numeric( $data_array['role'] ) ) { |
| 40 | 40 | $roles = $this->getRoles(); |
| @@ -64,9 +64,13 @@ | ||
| 64 | 64 | $data_array['role'] = 'subscriber'; #TODO: Add log message for assigning the default role |
| 65 | 65 | } |
| 66 | 66 | $user_email = $data_array['user_email']; |
| 67 | 67 | |
| 68 | + //filter to change user meta values before import | |
| 69 | + $data_array = apply_filters('smack_csv_modify_userdata_filter', $data_array); | |
| 70 | + | |
| 68 | 71 | if ( $mode == 'Insert' ) { |
| 72 | + $send_password = $data_array['user_pass'] ; | |
| 69 | 73 | if ( empty( $data_array['user_pass'] ) ) { |
| 70 | 74 | $data_array['user_pass'] = wp_generate_password( 12, false ); |
| 71 | 75 | $additional_meta_info = array( |
| 72 | 76 | 'user_login' => $data_array['user_login'], |
| @@ -75,9 +79,12 @@ | ||
| 75 | 79 | 'role' => $data_array['role'] |
| 76 | 80 | ); |
| 77 | 81 | $data_array['smack_uci_import'] = $additional_meta_info; |
| 78 | 82 | } |
| 79 | - else{ | |
| 83 | + else{ | |
| 84 | + if (strlen($data_array['user_pass'])!== 34 && $data_array['user_pass'][0]!=='$'){ | |
| 85 | + $data_array['user_pass']=wp_hash_password($data_array['user_pass']); | |
| 86 | + } | |
| 80 | 87 | $additional_meta_info = array( |
| 81 | 88 | 'user_login' => $data_array['user_login'], |
| 82 | 89 | 'user_pass' => $data_array['user_pass'], |
| 83 | 90 | 'user_email' => $data_array['user_email'], |
| @@ -85,8 +92,12 @@ | ||
| 85 | 92 | ); |
| 86 | 93 | $data_array['smack_uci_import'] = $additional_meta_info; |
| 87 | 94 | } |
| 88 | 95 | $retID = wp_insert_user($data_array); |
| 96 | + update_user_meta($retID, 'sendPassword', $send_password); | |
| 97 | + if ( !is_wp_error($retID) && !empty( $data_array['user_pass'] ) ) { | |
| 98 | + $wpdb->get_results("UPDATE {$wpdb->prefix}users SET user_pass = '{$data_array['user_pass']}' WHERE ID = $retID"); | |
| 99 | + } | |
| 89 | 100 | $mode_of_affect = 'Inserted'; |
| 90 | 101 | |
| 91 | 102 | if ( is_wp_error( $retID ) ) { |
| 92 | 103 | $core_instance->detailed_log[$line_number]['Message'] = "Skipped, Due to duplicate User found with same email!."; |
| @@ -151,14 +162,17 @@ | ||
| 151 | 162 | |
| 152 | 163 | if ( ! empty ( $metaData ) ) { |
| 153 | 164 | foreach ( $metaData as $meta_key => $meta_value ) { |
| 154 | 165 | update_user_meta( $retID, $meta_key, $meta_value ); |
| 166 | + | |
| 167 | + //filter for modifying user metadata after import | |
| 168 | + apply_filters('smack_csv_modify_metadata_filter', $retID, $meta_key, $meta_value); | |
| 155 | 169 | } |
| 156 | 170 | } |
| 157 | 171 | $core_instance->detailed_log[$line_number]['Email'] = $data_array['user_email']; |
| 158 | 172 | $core_instance->detailed_log[$line_number]['Role'] = $data_array['role']; |
| 159 | 173 | $ucisettings = get_option('sm_uci_pro_settings'); |
| 160 | - if($ucisettings['send_user_password'] == "true") { | |
| 174 | + if(isset($ucisettings['send_user_password']) && $ucisettings['send_user_password'] == "true") { | |
| 161 | 175 | $send_user_password = new SendPassword; |
| 162 | 176 | $send_user_password->send_login_credentials_to_users(); |
| 163 | 177 | } |
| 164 | 178 | $returnArr['ID'] = $retID; |