PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.48
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.48
1.2.74 1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 All 174 releases
← All changes | includes/class-import-export.php +266 -76 1.0.201.2.48 View file →
@@ -16,9 +16,14 @@
16 16 public $path;
17 17 public $total_rows;
18 18 public $imp_step;
19 19 public $skipped;
20 + private $empty;
21 + private $step;
22 + private $file;
23 + private $filename;
20 24
25 +
21 26 public function __construct() {
22 27 global $wp_filesystem;
23 28
24 29 if ( empty( $wp_filesystem ) ) {
@@ -33,45 +38,29 @@
33 38 $this->per_page = apply_filters('uwp_import_export_per_page', 20, $this);
34 39 $this->meta_table_name = get_usermeta_table_prefix() . 'uwp_usermeta';
35 40 $this->path = '';
36 41
37 - add_action( 'userswp_settings_import-export_tab_content', array($this, 'get_ie_content') );
38 - add_action( 'admin_init', array($this, 'uwp_process_settings_export') );
39 - add_action( 'admin_init', array($this, 'uwp_process_settings_import') );
40 - add_action( 'wp_ajax_uwp_ajax_export_users', array( $this, 'uwp_process_users_export' ) );
41 - add_action( 'wp_ajax_uwp_ajax_import_users', array( $this, 'uwp_process_users_import' ) );
42 - add_action( 'wp_ajax_uwp_ie_upload_file', array( $this, 'uwp_ie_upload_file' ) );
43 - add_action( 'wp_ajax_nopriv_uwp_ie_upload_file', array( $this, 'uwp_ie_upload_file' ) );
44 - add_action( 'admin_notices', array($this, 'uwp_ie_admin_notice') );
45 - add_filter( 'uwp_get_export_users_status', array( $this, 'uwp_get_export_users_status' ) );
46 - add_filter( 'uwp_get_import_users_status', array( $this, 'uwp_get_import_users_status' ) );
42 + add_action( 'admin_init', array($this, 'process_settings_export') );
43 + add_action( 'admin_init', array($this, 'process_settings_import') );
44 + add_action( 'wp_ajax_uwp_ajax_export_users', array( $this, 'process_users_export' ) );
45 + add_action( 'wp_ajax_uwp_ajax_import_users', array( $this, 'process_users_import' ) );
46 + add_action( 'wp_ajax_uwp_ie_upload_file', array( $this, 'ie_upload_file' ) );
47 + add_action( 'wp_ajax_nopriv_uwp_ie_upload_file', array( $this, 'ie_upload_file' ) );
48 + add_action( 'admin_notices', array($this, 'ie_admin_notice') );
49 + add_filter( 'uwp_get_export_users_status', array( $this, 'get_export_users_status' ) );
50 + add_filter( 'uwp_get_import_users_status', array( $this, 'get_import_users_status' ) );
47 51 }
48 52
49 - public function get_ie_content() {
50 - $subtab = 'ie-users';
51 -
52 - if (isset($_GET['subtab'])) {
53 - $subtab = $_GET['subtab'];
54 - }
55 - ?>
56 - <div class="item-list-sub-tabs">
57 - <ul class="item-list-sub-tabs-ul">
58 - <li class="<?php if ($subtab == 'ie-users') { echo "current selected"; } ?>">
59 - <a href="<?php echo add_query_arg(array('tab' => 'import-export', 'subtab' => 'ie-users')); ?>"><?php echo __( 'Users', 'userswp' ); ?></a>
60 - </li>
61 - <li class="<?php if ($subtab == 'ie-settings') { echo "current selected"; } ?>">
62 - <a href="<?php echo add_query_arg(array('tab' => 'import-export', 'subtab' => 'ie-settings')); ?>"><?php echo __( 'Settings', 'userswp' ); ?></a>
63 - </li>
64 - </ul>
65 - </div>
66 - <?php
67 - if ($subtab == 'ie-users') {
68 - include_once( USERSWP_PATH . '/admin/settings/admin-settings-ie-users.php' );
69 - } elseif ($subtab == 'ie-settings') {
70 - include_once( USERSWP_PATH . '/admin/settings/admin-settings-ie-settings.php' );
71 - }
72 - }
73 -
53 + /**
54 + * Returns export file location
55 + *
56 + * @package userswp
57 + *
58 + * @param bool $relative
59 + *
60 + * @return string
61 + *
62 + */
74 63 public function export_location( $relative = false ) {
75 64 $upload_dir = wp_upload_dir();
76 65 $export_location = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache';
77 66 $export_location = apply_filters( 'uwp_export_location', $export_location, $relative );
@@ -78,13 +67,16 @@
78 67
79 68 return trailingslashit( $export_location );
80 69 }
81 70
82 - public function uwp_ie_admin_notice(){
71 + /**
72 + * Displays notice
73 + */
74 + public function ie_admin_notice(){
83 75 if(isset($_GET['imp-msg']) && 'success' == $_GET['imp-msg']){
84 76 ?>
85 77 <div class="notice notice-success is-dismissible">
86 - <p><?php _e( 'Settings imported successfully!', 'userswp' ); ?></p>
78 + <p><?php esc_html_e( 'Settings imported successfully!', 'userswp' ); ?></p>
87 79 </div>
88 80 <?php
89 81 }
90 82 }
@@ -91,9 +83,9 @@
91 83
92 84 /**
93 85 * Process a settings export that generates a .json file of the settings
94 86 */
95 - public function uwp_process_settings_export() {
87 + public function process_settings_export() {
96 88 if( empty( $_POST['uwp_ie_action'] ) || 'export_settings' != $_POST['uwp_ie_action'] )
97 89 return;
98 90 if( ! wp_verify_nonce( $_POST['uwp_export_nonce'], 'uwp_export_nonce' ) )
99 91 return;
@@ -111,9 +103,9 @@
111 103
112 104 /**
113 105 * Process a settings import from a json file
114 106 */
115 - public function uwp_process_settings_import() {
107 + public function process_settings_import() {
116 108 if( empty( $_POST['uwp_ie_action'] ) || 'import_settings' != $_POST['uwp_ie_action'] )
117 109 return;
118 110 if( ! wp_verify_nonce( $_POST['uwp_import_nonce'], 'uwp_import_nonce' ) )
119 111 return;
@@ -118,23 +110,27 @@
118 110 if( ! wp_verify_nonce( $_POST['uwp_import_nonce'], 'uwp_import_nonce' ) )
119 111 return;
120 112 if( ! current_user_can( 'manage_options' ) )
121 113 return;
122 - $extension = end( explode( '.', $_FILES['import_file']['name'] ) );
114 + $extension = explode( '.', $_FILES['import_file']['name'] );
115 + $extension = end( $extension );
123 116 if( $extension != 'json' ) {
124 - wp_die( sprintf(__( 'Please upload a valid .json file. %sGo Back%s' ), '<a href="'.admin_url( 'admin.php?page=userswp&tab=import-export&subtab=ie-settings' ).'">', '</a>' ));
117 + wp_die( esc_html( wp_sprintf( __( 'Please upload a valid .json file. %sGo Back%s', 'userswp' ), '<a href="' . esc_url( admin_url( 'admin.php?page=userswp&tab=import-export&section=settings' ) ) . '">', '</a>' ) ) );
125 118 }
126 119 $import_file = $_FILES['import_file']['tmp_name'];
127 120 if( empty( $import_file ) ) {
128 - wp_die( sprintf(__( 'Please upload a file to import. %sGo Back%s' ), '<a href="'.admin_url( 'admin.php?page=userswp&tab=import-export&subtab=ie-settings' ).'">', '</a>' ));
121 + wp_die( esc_html( wp_sprintf( __( 'Please upload a file to import. %sGo Back%s', 'userswp' ), '<a href="' . esc_url( admin_url( 'admin.php?page=userswp&tab=import-export&section=settings' ) ) . '">', '</a>' ) ) );
129 122 }
130 123 // Retrieve the settings from the file and convert the json object to an array.
131 124 $settings = (array) json_decode( file_get_contents( $import_file ), true );
132 125 update_option( 'uwp_settings', $settings );
133 - wp_safe_redirect( admin_url( 'admin.php?page=userswp&tab=import-export&subtab=ie-settings&imp-msg=success' ) ); exit;
126 + wp_safe_redirect( admin_url( 'admin.php?page=userswp&tab=import-export&section=settings&imp-msg=success' ) ); exit;
134 127 }
135 128
136 - public function uwp_process_users_export(){
129 + /**
130 + * Processes users export
131 + */
132 + public function process_users_export(){
137 133
138 134 $response = array();
139 135 $response['success'] = false;
140 136 $response['msg'] = __( 'Invalid export request found.', 'userswp' );
@@ -170,9 +166,9 @@
170 166 $response['msg'] = '';
171 167
172 168 if ( $done >= 100 ) {
173 169 $this->step = 'done';
174 - $new_filename = 'uwp-users-export-' . date( 'y-m-d-H-i' ) . '.csv';
170 + $new_filename = 'uwp-users-export-' . date( 'y-m-d-H-i' ) . '-' . wp_generate_password(12, false ) . '.csv';
175 171 $new_file = $this->export_dir . $new_filename;
176 172
177 173 if ( file_exists( $this->file ) ) {
178 174 $this->wp_filesystem->move( $this->file, $new_file, true );
@@ -192,17 +188,35 @@
192 188 wp_send_json( $response );
193 189
194 190 }
195 191
192 + /**
193 + * Sets export params
194 + *
195 + * @package userswp
196 + *
197 + * @param array $request
198 + *
199 + */
196 200 public function set_export_params( $request ) {
197 201 $this->empty = false;
198 202 $this->step = !empty( $request['step'] ) ? absint( $request['step'] ) : 1;
199 203 $this->filename = 'uwp-users-export-temp.csv';
200 204 $this->file = $this->export_dir . $this->filename;
205 + $chunk_per_page = !empty( $request['uwp_ie_chunk_size'] ) ? absint( $request['uwp_ie_chunk_size'] ) : 0;
206 + $this->per_page = $chunk_per_page < 50 || $chunk_per_page > 100000 ? 5000 : $chunk_per_page;
201 207
202 208 do_action( 'uwp_export_users_set_params', $request );
203 209 }
204 210
211 + /**
212 + * Returns export file location
213 + *
214 + * @package userswp
215 + *
216 + * @return bool
217 + *
218 + */
205 219 public function check_export_location() {
206 220 try {
207 221 if ( empty( $this->wp_filesystem ) ) {
208 222 return __( 'Filesystem ERROR: Could not access filesystem.', 'userswp' );
@@ -215,27 +229,35 @@
215 229 $is_dir = $this->wp_filesystem->is_dir( $this->export_dir );
216 230 $is_writeable = $is_dir && is_writeable( $this->export_dir );
217 231
218 232 if ( $is_dir && $is_writeable ) {
219 - return true;
233 +
220 234 } else if ( $is_dir && !$is_writeable ) {
221 235 if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) {
222 236 return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'userswp' ), $this->export_dir );
223 237 }
224 -
225 - return true;
226 238 } else {
227 239 if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) {
228 240 return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'userswp' ), $this->export_dir );
229 241 }
242 + }
230 243
231 - return true;
232 - }
244 + if(!$this->wp_filesystem->exists( $this->export_dir . '/index.php')){
245 + $this->wp_filesystem->copy( USERSWP_PATH . 'assets/index.php', $this->export_dir . '/index.php' );
246 + }
247 +
248 + return true;
233 249 } catch ( Exception $e ) {
234 250 return $e->getMessage();
235 251 }
236 252 }
237 253
254 + /**
255 + * Processes export step
256 + *
257 + * @return bool
258 + *
259 + */
238 260 public function process_export_step() {
239 261 if ( $this->step < 2 ) {
240 262 @unlink( $this->file );
241 263 $this->print_columns();
@@ -249,8 +271,14 @@
249 271 return false;
250 272 }
251 273 }
252 274
275 + /**
276 + * Prints columns
277 + *
278 + * @return array
279 + *
280 + */
253 281 public function print_columns() {
254 282 $column_data = '';
255 283 $columns = $this->get_columns();
256 284 $i = 1;
@@ -265,13 +293,19 @@
265 293
266 294 return $column_data;
267 295 }
268 296
297 + /**
298 + * Returns export columns
299 + *
300 + * @return array
301 + *
302 + */
269 303 public function get_columns() {
270 304 global $wpdb;
271 305 $columns = array();
272 306
273 - foreach ( $wpdb->get_col( "DESC " . $this->meta_table_name, 0 ) as $column_name ) {
307 + foreach ( $wpdb->get_col( "DESC " . $this->meta_table_name, 0 ) as $column_name ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
274 308 $columns[] = $column_name;
275 309 }
276 310
277 311 return apply_filters( 'uwp_export_users_get_columns', $columns );
@@ -276,29 +310,66 @@
276 310
277 311 return apply_filters( 'uwp_export_users_get_columns', $columns );
278 312 }
279 313
314 + /**
315 + * Returns export data
316 + *
317 + * @package userswp
318 + *
319 + * @return array
320 + *
321 + */
280 322 public function get_export_data() {
281 323 global $wpdb;
282 - $data = $wpdb->get_results( "SELECT * FROM $this->meta_table_name WHERE 1=1 LIMIT 0,". $this->per_page);
324 + if(!$this->step){
325 + $page = 1;
326 + } else {
327 + $page = $this->step;
328 + }
283 329
330 + $page_start = absint( ( $page - 1 ) * $this->per_page );
331 + $data = $wpdb->get_results( "SELECT * FROM $this->meta_table_name WHERE 1=1 LIMIT $page_start,". $this->per_page); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
332 + $i = 0;
333 +
334 + foreach ($data as $u){
335 + $user = get_userdata($u->user_id);
336 + $data[$i]->username = $user->user_login;
337 + $data[$i]->email = $user->user_email;
338 + $data[$i]->bio = $user->description;
339 + $i++;
340 + }
341 +
284 342 return apply_filters( 'uwp_export_users_get_data', $data );
285 343 }
286 344
345 + /**
346 + * Returns export status
347 + *
348 + * @return int
349 + *
350 + */
287 351 public function get_export_status() {
288 352 $status = 100;
289 353 return apply_filters( 'uwp_get_export_users_status', $status );
290 354 }
291 355
356 + /**
357 + * Prints CSV rows
358 + *
359 + * @return string
360 + *
361 + */
292 362 public function print_rows() {
293 363 $row_data = '';
294 364 $data = $this->get_export_data();
295 365 $columns = $this->get_columns();
296 366
297 - if ( $data ) {
367 + if ( is_array($data) && !empty($data) ) {
298 368 foreach ( $data as $row ) {
299 369 $i = 1;
300 370 foreach ( $row as $key => $column ) {
371 + $column = $this->escape_data( $column );
301 372 $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"';
302 373 $row_data .= $i == count( $columns ) ? '' : ',';
303 374 $i++;
304 375 }
@@ -312,8 +383,14 @@
312 383
313 384 return false;
314 385 }
315 386
387 + /**
388 + * Returns export file content
389 + *
390 + * @return string
391 + *
392 + */
316 393 protected function get_export_file() {
317 394 $file = '';
318 395
319 396 if ( $this->wp_filesystem->exists( $this->file ) ) {
@@ -324,8 +401,16 @@
324 401
325 402 return $file;
326 403 }
327 404
405 + /**
406 + * Adds export data to CSV file
407 + *
408 + * @package userswp
409 + *
410 + * @param string $data
411 + *
412 + */
328 413 protected function attach_export_data( $data = '' ) {
329 414 $filedata = $this->get_export_file();
330 415 $filedata .= $data;
331 416
@@ -337,14 +422,24 @@
337 422
338 423 $this->empty = count( $rows ) == $columns ? true : false;
339 424 }
340 425
341 - public function uwp_get_export_users_status() {
426 + /**
427 + * Returns export user status
428 + *
429 + * @return int
430 + *
431 + */
432 + public function get_export_users_status() {
342 433 global $wpdb;
343 - $data = $wpdb->get_results("SELECT user_id FROM $this->meta_table_name WHERE 1=1");
434 + $data = $wpdb->get_results("SELECT user_id FROM $this->meta_table_name WHERE 1=1"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
344 435 $total = !empty( $data ) ? count( $data ) : 0;
345 436 $status = 100;
346 437
438 + if ( $this->per_page > $total ) {
439 + $this->per_page = $total;
440 + }
441 +
347 442 if ( $total > 0 ) {
348 443 $status = ( ( $this->per_page * $this->step ) / $total ) * 100;
349 444 }
350 445
@@ -354,9 +449,20 @@
354 449
355 450 return $status;
356 451 }
357 452
358 - public function uwp_ie_upload_file(){
453 + /**
454 + * Uploaded file handling
455 + *
456 + * @return string
457 + *
458 + */
459 + public function ie_upload_file(){
460 +
461 + if ( !(!empty($_REQUEST['nonce']) && wp_verify_nonce( $_REQUEST['nonce'], 'uwp-ie-file-upload-nonce' )) ) {
462 + echo 'error';return;
463 + }
464 +
359 465 $upload_data = array(
360 466 'name' => $_FILES['import_file']['name'],
361 467 'type' => $_FILES['import_file']['type'],
362 468 'tmp_name' => $_FILES['import_file']['tmp_name'],
@@ -365,12 +471,15 @@
365 471 );
366 472
367 473 header('Content-Type: text/html; charset=' . get_option('blog_charset'));
368 474
475 + add_filter( 'upload_mimes', array( $this, 'allowed_upload_mimes' ) );
369 476 $uploaded_file = wp_handle_upload( $upload_data, array('test_form' => false) );
477 + remove_filter( 'upload_mimes', array( $this, 'allowed_upload_mimes' ) );
478 +
370 479 if ( isset( $uploaded_file['url'] ) ) {
371 480 $file_loc = $uploaded_file['url'];
372 - echo $file_loc;
481 + echo esc_url( $file_loc );exit;
373 482 } else {
374 483 echo 'error';
375 484 }
376 485 exit;
@@ -375,9 +484,13 @@
375 484 }
376 485 exit;
377 486 }
378 487
379 - public function uwp_process_users_import(){
488 + /**
489 + * Processes users import
490 + *
491 + */
492 + public function process_users_import(){
380 493
381 494 $response = array();
382 495 $response['success'] = false;
383 496 $response['msg'] = __( 'Invalid import request found.', 'userswp' );
@@ -441,9 +554,9 @@
441 554 $this->imp_step = 'done';
442 555 $response['msg'] = __( 'Users import completed.', 'userswp' );
443 556 }
444 557
445 - $response['data']['msg'] = $return['msg'];
558 + $response['data']['msg'] = ! empty( $return['msg'] ) ? $return['msg'] : $response['msg'];
446 559 $response['data']['step'] = $this->imp_step;
447 560 $response['data']['done'] = $done;
448 561 } else {
449 562 $response['msg'] = __( 'No valid data found for import.', 'userswp' );
@@ -452,8 +565,14 @@
452 565 wp_send_json( $response );
453 566
454 567 }
455 568
569 + /**
570 + * Processes import step
571 + *
572 + * @return array
573 + *
574 + */
456 575 public function process_import_step() {
457 576
458 577 $errors = new WP_Error();
459 578 if(is_null($this->path)){
@@ -468,73 +587,97 @@
468 587
469 588 if ( ! empty( $rows ) ) {
470 589 foreach ( $rows as $row ) {
471 590 if( empty($row) ) {
472 - $return['msg'] = __('Row - ' .$this->imp_step. ' Error: '. 'Skipped due to invalid/no data.','userswp');
591 + $return['msg'] = sprintf(__('Row - %s Error: '. 'Skipped due to invalid/no data.','userswp'), $this->imp_step);
473 592 continue;
474 593 }
475 594
476 - $username = isset($row['uwp_account_username']) ? $row['uwp_account_username'] : '';
477 - $email = isset($row['uwp_account_email']) ? $row['uwp_account_email'] : '';
478 - $display_name = isset($row['uwp_account_display_name']) ? $row['uwp_account_display_name'] : '';
595 + $username = isset($row['username']) ? $row['username'] : '';
596 + $email = isset($row['email']) ? $row['email'] : '';
597 + $first_name = isset($row['first_name']) ? $row['first_name'] : '';
598 + $last_name = isset($row['last_name']) ? $row['last_name'] : '';
599 + $bio = isset($row['bio']) ? $row['bio'] : '';
600 + $display_name = isset($row['display_name']) ? $row['display_name'] : '';
479 601 $password = wp_generate_password();
480 602 $exclude = array('user_id');
481 603 $exclude = apply_filters('uwp_import_exclude_columns', $exclude, $row);
482 604
483 - if(isset($row['uwp_account_username']) && username_exists($row['uwp_account_username'])){
484 - $user = get_user_by('login', $row['uwp_account_username']);
605 + if(isset($row['username']) && username_exists($row['username'])){
606 + $user = get_user_by('login', $row['username']);
485 607 $user_id = $user->ID;
486 - $email = $row['uwp_account_email'];
608 + $email = $row['email'];
487 609 if( !empty( $email ) && $update_existing = apply_filters('uwp_import_update_users', false, $row, $user_id) ) {
488 610 $args = array(
489 611 'ID' => $user_id,
490 612 'user_email' => $email,
491 - 'display_name' => $display_name
613 + 'display_name' => $display_name,
614 + 'first_name' => $first_name,
615 + 'last_name' => $last_name,
616 + 'description' => $bio,
492 617 );
493 618 wp_update_user( $args );
494 619 }
495 - } elseif(isset($row['uwp_account_email']) && email_exists($row['uwp_account_email'])){
496 - $user = get_user_by('email', $row['uwp_account_email']);
620 + } elseif(isset($row['email']) && email_exists($row['email'])){
621 + $user = get_user_by('email', $row['email']);
497 622 $user_id = $user->ID;
498 623 } elseif((int)$row['user_id'] > 0){
499 624 $user = get_user_by('ID', $row['user_id']);
500 625 if(false === $user){
501 626 $userdata = array(
502 - 'user_login' => $row['uwp_account_username'],
627 + 'user_login' => $row['username'],
503 628 'user_email' => $email,
504 629 'user_pass' => $password,
630 + 'first_name' => $first_name,
631 + 'last_name' => $last_name,
632 + 'description' => $bio,
505 633 'display_name'=> $display_name
506 634 );
507 635 $user_id = wp_insert_user( $userdata );
636 + $notify = apply_filters('uwp_import_user_notify', 'user', $user_id);
637 + wp_new_user_notification($user_id,null, $notify); //send password reset link
508 638 } else {
509 - if( $user->user_login == $row['uwp_account_username'] ) { //check id passed in csv and existing username are same
639 + if( $user->user_login == $row['username'] ) { //check id passed in csv and existing username are same
510 640 $user_id = $row['user_id'];
511 641 if( !empty( $email ) && $email != $user->user_email && $update_existing = apply_filters('uwp_import_update_users', false, $row, $user_id)) {
512 642 $args = array(
513 643 'ID' => $user_id,
514 644 'user_email' => $email,
645 + 'first_name' => $first_name,
646 + 'last_name' => $last_name,
647 + 'description' => $bio,
515 648 'display_name' => $display_name
516 649 );
517 650 wp_update_user( $args );
518 651 }
519 652 } else {
520 - $return['msg'] = __('Row - ' .$this->imp_step. ' Error: '. 'User could not be created.','userswp');
653 + $return['msg'] = sprintf(__('Row - %s Error: '. 'User could not be created.','userswp'), $this->imp_step);
521 654 continue;
522 655 }
523 656 }
524 657 } else {
525 658 $user_id = wp_create_user( $username, $password, $email );
659 + if( !is_wp_error( $user_id ) ) {
660 + $args = array(
661 + 'ID' => $user_id,
662 + 'first_name' => $first_name,
663 + 'last_name' => $last_name,
664 + 'description' => $bio,
665 + 'display_name' => $display_name
666 + );
667 + wp_update_user( $args );
668 + }
526 669 }
527 670
528 671 if( !is_wp_error( $user_id ) ){
529 672 foreach ($row as $key => $value){
530 - if(!in_array($key, $exclude) && $update_existing = apply_filters('uwp_import_update_users', false, $row, $user_id)){
673 + if(!in_array($key, $exclude)){
531 674 $value = maybe_unserialize($value);
532 675 uwp_update_usermeta($user_id, $key, $value);
533 676 }
534 677 }
535 678 } else {
536 - $return['msg'] = __('Row - ' .$this->imp_step. ' Error: '. $user_id->get_error_message(),'userswp');
679 + $return['msg'] = sprintf(__('Row - %s Error: %s','userswp'), $this->imp_step, $user_id->get_error_message());
537 680 continue;
538 681 }
539 682 }
540 683 $return['success'] = true;
@@ -542,8 +685,19 @@
542 685
543 686 return $return;
544 687 }
545 688
689 + /**
690 + * Returns CSV row
691 + *
692 + * @package userswp
693 + *
694 + * @param int $row
695 + * @param int $count
696 + *
697 + * @return mixed
698 + *
699 + */
546 700 public function get_csv_rows( $row = 0, $count = 1 ) {
547 701
548 702 $lc_all = setlocale( LC_ALL, 0 ); // Fix issue of fgetcsv ignores special characters when they are at the beginning of line
549 703 setlocale( LC_ALL, 'en_US.UTF-8' );
@@ -599,9 +753,8 @@
599 753 }
600 754
601 755 // A plugin may need to filter the data and meta
602 756 $userdata = apply_filters( 'uwp_import_userdata', $userdata, $usermeta );
603 - $usermeta = apply_filters( 'uwp_import_usermeta', $usermeta, $userdata );
604 757
605 758 if ( ! empty( $userdata ) ) {
606 759 $file[] = $userdata;
607 760 $f ++;
@@ -615,14 +768,26 @@
615 768 return $file;
616 769
617 770 }
618 771
772 + /**
773 + * Returns import status
774 + *
775 + * @return int
776 + *
777 + */
619 778 public function get_import_status() {
620 779 $status = 100;
621 780 return apply_filters( 'uwp_get_import_users_status', $status );
622 781 }
623 782
624 - public function uwp_get_import_users_status() {
783 + /**
784 + * Returns import user status
785 + *
786 + * @return int
787 + *
788 + */
789 + public function get_import_users_status() {
625 790
626 791 if ( $this->imp_step >= $this->total_rows ) {
627 792 $status = 100;
628 793 } else {
@@ -630,7 +795,32 @@
630 795 }
631 796
632 797 return $status;
633 798 }
799 +
800 + public function allowed_upload_mimes($mimes = array()) {
801 + $mimes['csv'] = "text/csv";
802 + return $mimes;
803 + }
804 +
805 + /**
806 + * Escape a string to be used in a CSV export.
807 + *
808 + * @see https://hackerone.com/reports/72785
809 + *
810 + * @since 1.2.3.10
811 + *
812 + * @param string $data Data to escape.
813 + * @return string
814 + */
815 + public function escape_data( $data ) {
816 + $escape_chars = array( '=', '+', '-', '@' );
817 +
818 + if ( $data && in_array( substr( $data, 0, 1 ), $escape_chars, true ) ) {
819 + $data = " " . $data;
820 + }
821 +
822 + return $data;
823 + }
634 824
635 825 }
636 826 new UsersWP_Import_Export();