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