PluginProbe
Import Users & Customers with Meta | WP Ultimate CSV Importer Add-on / 1.2
Import Users & Customers with Meta | WP Ultimate CSV Importer Add-on v1.2
2.0 1.7.1 1.2.9 1.3 1.4 1.4.1 1.4.2 1.4.3 1.5 1.6 1.7 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8
← All changes | importExtensions/UsersImport.php +11 -34 1.51.2 View file →
@@ -1,10 +1,11 @@
1 1 <?php
2 -/**
3 - * Import Users plugin file.
4 - *
5 - * Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
6 - */
2 +/******************************************************************************************
3 + * Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
4 + * Unauthorized copying of this file, via any medium is strictly prohibited
5 + * Proprietary and confidential
6 + * You can contact Smackcoders at email address info@smackcoders.com.
7 + *******************************************************************************************/
7 8
8 9 namespace Smackcoders\SMUSERS;
9 10
10 11 if ( ! defined( 'ABSPATH' ) )
@@ -11,9 +12,9 @@
11 12 exit; // Exit if accessed directly
12 13
13 14 class UsersImport{
14 15 private static $users_instance = null,$send_user_password;
15 - public $plugin;
16 +
16 17 public static function getInstance() {
17 18 if (UsersImport::$users_instance == null) {
18 19 UsersImport::$users_instance = new UsersImport;
19 20 return UsersImport::$users_instance;
@@ -32,9 +33,9 @@
32 33 $created_count = $updated_row_counts['created'];
33 34 $updated_count = $updated_row_counts['updated'];
34 35 $skipped_count = $updated_row_counts['skipped'];
35 36
36 - $data_array['role'] = trim(isset($data_array['role']));
37 + $data_array['role'] = trim($data_array['role']);
37 38 if ( isset( $data_array['role'] ) && $data_array['role'] != '') {
38 39 $user_capability = '';
39 40 if ( !is_numeric( $data_array['role'] ) ) {
40 41 $roles = $this->getRoles();
@@ -64,13 +65,9 @@
64 65 $data_array['role'] = 'subscriber'; #TODO: Add log message for assigning the default role
65 66 }
66 67 $user_email = $data_array['user_email'];
67 68
68 - //filter to change user meta values before import
69 - $data_array = apply_filters('smack_csv_modify_userdata_filter', $data_array);
70 -
71 69 if ( $mode == 'Insert' ) {
72 - $send_password = isset($data_array['user_pass']) ? $data_array['user_pass'] : '';
73 70 if ( empty( $data_array['user_pass'] ) ) {
74 71 $data_array['user_pass'] = wp_generate_password( 12, false );
75 72 $additional_meta_info = array(
76 73 'user_login' => $data_array['user_login'],
@@ -79,12 +76,9 @@
79 76 'role' => $data_array['role']
80 77 );
81 78 $data_array['smack_uci_import'] = $additional_meta_info;
82 79 }
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 + else{
87 81 $additional_meta_info = array(
88 82 'user_login' => $data_array['user_login'],
89 83 'user_pass' => $data_array['user_pass'],
90 84 'user_email' => $data_array['user_email'],
@@ -92,28 +86,21 @@
92 86 );
93 87 $data_array['smack_uci_import'] = $additional_meta_info;
94 88 }
95 89 $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 - }
100 90 $mode_of_affect = 'Inserted';
101 91
102 92 if ( is_wp_error( $retID ) ) {
103 93 $core_instance->detailed_log[$line_number]['Message'] = "Skipped, Due to duplicate User found with same email!.";
104 - $core_instance->detailed_log[$line_number]['state'] = 'Skipped';
105 94 $fields = $wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE hash_key = '$hash_key'");
106 95 return array('MODE' => $mode);
107 96 }
108 97 $core_instance->detailed_log[$line_number]['Message'] = 'Inserted User ID: ' . $retID;
109 - $core_instance->detailed_log[$line_number]['state'] = 'Inserted';
110 - $core_instance->detailed_log[$line_number]['id'] = $retID;
111 98 $fields = $wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE hash_key = '$hash_key'");
112 99
113 100 } else {
114 101 if ( $mode == 'Update') {
115 - $user_email = isset($data_array['user_email']) ? $data_array['user_email'] : '';
102 +
116 103 $update_query = $wpdb->prepare( "select ID from {$wpdb->prefix}users where user_email = %s order by ID DESC", $user_email );
117 104 $ID_result = $wpdb->get_results( $update_query );
118 105 if ( is_array( $ID_result ) && ! empty( $ID_result ) ) {
119 106 $retID = $ID_result[0]->ID;
@@ -121,10 +108,8 @@
121 108 wp_update_user( $data_array );
122 109 $mode_of_affect = 'Updated';
123 110
124 111 $core_instance->detailed_log[$line_number]['Message'] = 'Updated User ID: ' . $retID;
125 - $core_instance->detailed_log[$line_number]['state'] = 'Updated';
126 - $core_instance->detailed_log[$line_number]['id'] = $retID;
127 112 $fields = $wpdb->get_results("UPDATE $log_table_name SET updated = $updated_count WHERE hash_key = '$hash_key'");
128 113
129 114 }else{
130 115 $retID = wp_insert_user($data_array);
@@ -136,10 +121,8 @@
136 121 $fields = $wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE hash_key = '$hash_key'");
137 122 return array('MODE' => $mode);
138 123 }
139 124 $core_instance->detailed_log[$line_number]['Message'] = 'Inserted User ID: ' . $retID;
140 - $core_instance->detailed_log[$line_number]['state'] = 'Inserted';
141 - $core_instance->detailed_log[$line_number]['id'] = $retID;
142 125 $fields = $wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE hash_key = '$hash_key'");
143 126 }
144 127 }
145 128 }
@@ -169,20 +152,14 @@
169 152
170 153 if ( ! empty ( $metaData ) ) {
171 154 foreach ( $metaData as $meta_key => $meta_value ) {
172 155 update_user_meta( $retID, $meta_key, $meta_value );
173 -
174 - //filter for modifying user metadata after import
175 - apply_filters('smack_csv_modify_metadata_filter', $retID, $meta_key, $meta_value);
176 156 }
177 157 }
178 - $user_data = get_userdata($retID);
179 - $user_title = isset($user_data) ? $user_data->display_name : '';
180 - $core_instance->detailed_log[$line_number]['user_title'] = $user_title;
181 158 $core_instance->detailed_log[$line_number]['Email'] = $data_array['user_email'];
182 159 $core_instance->detailed_log[$line_number]['Role'] = $data_array['role'];
183 160 $ucisettings = get_option('sm_uci_pro_settings');
184 - if(isset($ucisettings['send_user_password']) && $ucisettings['send_user_password'] == "true") {
161 + if($ucisettings['send_user_password'] == "true") {
185 162 $send_user_password = new SendPassword;
186 163 $send_user_password->send_login_credentials_to_users();
187 164 }
188 165 $returnArr['ID'] = $retID;