PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.3.4
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.3.4
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 1.0.22 1.0.23 All 172 releases
userswp / includes / class-import-export.php

class-import-export.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.3.4, at includes/class-import-export.php

801 lines 26.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * UsersWP Notice display functions.
4 *
5 * All UsersWP notice display related functions can be found here.
6 *
7 * @since 1.0.0
8 * @author GeoDirectory Team <info@wpgeodirectory.com>
9 */
10 class UsersWP_Import_Export {
11 private $wp_filesystem;
12 private $export_dir;
13 private $export_url;
14 public $per_page;
15 public $meta_table_name;
16 public $path;
17 public $total_rows;
18 public $imp_step;
19 public $skipped;
20
21
22 public function __construct() {
23 global $wp_filesystem;
24
25 if ( empty( $wp_filesystem ) ) {
26 require_once( ABSPATH . '/wp-admin/includes/file.php' );
27 WP_Filesystem();
28 global $wp_filesystem;
29 }
30
31 $this->wp_filesystem = $wp_filesystem;
32 $this->export_dir = $this->export_location();
33 $this->export_url = $this->export_location( true );
34 $this->per_page = apply_filters('uwp_import_export_per_page', 20, $this);
35 $this->meta_table_name = get_usermeta_table_prefix() . 'uwp_usermeta';
36 $this->path = '';
37
38 add_action( 'admin_init', array($this, 'process_settings_export') );
39 add_action( 'admin_init', array($this, 'process_settings_import') );
40 add_action( 'wp_ajax_uwp_ajax_export_users', array( $this, 'process_users_export' ) );
41 add_action( 'wp_ajax_uwp_ajax_import_users', array( $this, 'process_users_import' ) );
42 add_action( 'wp_ajax_uwp_ie_upload_file', array( $this, 'ie_upload_file' ) );
43 add_action( 'wp_ajax_nopriv_uwp_ie_upload_file', array( $this, 'ie_upload_file' ) );
44 add_action( 'admin_notices', array($this, 'ie_admin_notice') );
45 add_filter( 'uwp_get_export_users_status', array( $this, 'get_export_users_status' ) );
46 add_filter( 'uwp_get_import_users_status', array( $this, 'get_import_users_status' ) );
47 }
48
49 /**
50 * Returns export file location
51 *
52 * @package userswp
53 *
54 * @param bool $relative
55 *
56 * @return string
57 *
58 */
59 public function export_location( $relative = false ) {
60 $upload_dir = wp_upload_dir();
61 $export_location = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache';
62 $export_location = apply_filters( 'uwp_export_location', $export_location, $relative );
63
64 return trailingslashit( $export_location );
65 }
66
67 /**
68 * Displays notice
69 */
70 public function ie_admin_notice(){
71 if(isset($_GET['imp-msg']) && 'success' == $_GET['imp-msg']){
72 ?>
73 <div class="notice notice-success is-dismissible">
74 <p><?php _e( 'Settings imported successfully!', 'userswp' ); ?></p>
75 </div>
76 <?php
77 }
78 }
79
80 /**
81 * Process a settings export that generates a .json file of the settings
82 */
83 public function process_settings_export() {
84 if( empty( $_POST['uwp_ie_action'] ) || 'export_settings' != $_POST['uwp_ie_action'] )
85 return;
86 if( ! wp_verify_nonce( $_POST['uwp_export_nonce'], 'uwp_export_nonce' ) )
87 return;
88 if( ! current_user_can( 'manage_options' ) )
89 return;
90 $settings = get_option( 'uwp_settings' );
91 ignore_user_abort( true );
92 nocache_headers();
93 header( 'Content-Type: application/json; charset=utf-8' );
94 header( 'Content-Disposition: attachment; filename=uwp-settings-export-' . date( 'm-d-Y' ) . '.json' );
95 header( "Expires: 0" );
96 echo json_encode( $settings );
97 exit;
98 }
99
100 /**
101 * Process a settings import from a json file
102 */
103 public function process_settings_import() {
104 if( empty( $_POST['uwp_ie_action'] ) || 'import_settings' != $_POST['uwp_ie_action'] )
105 return;
106 if( ! wp_verify_nonce( $_POST['uwp_import_nonce'], 'uwp_import_nonce' ) )
107 return;
108 if( ! current_user_can( 'manage_options' ) )
109 return;
110 $extension = explode( '.', $_FILES['import_file']['name'] );
111 $extension = end( $extension );
112 if( $extension != 'json' ) {
113 wp_die( sprintf(__( 'Please upload a valid .json file. %sGo Back%s' ), '<a href="'.admin_url( 'admin.php?page=userswp&tab=import-export&section=settings' ).'">', '</a>' ));
114 }
115 $import_file = $_FILES['import_file']['tmp_name'];
116 if( empty( $import_file ) ) {
117 wp_die( sprintf(__( 'Please upload a file to import. %sGo Back%s' ), '<a href="'.admin_url( 'admin.php?page=userswp&tab=import-export&section=settings' ).'">', '</a>' ));
118 }
119 // Retrieve the settings from the file and convert the json object to an array.
120 $settings = (array) json_decode( file_get_contents( $import_file ), true );
121 update_option( 'uwp_settings', $settings );
122 wp_safe_redirect( admin_url( 'admin.php?page=userswp&tab=import-export&section=settings&imp-msg=success' ) ); exit;
123 }
124
125 /**
126 * Processes users export
127 */
128 public function process_users_export(){
129
130 $response = array();
131 $response['success'] = false;
132 $response['msg'] = __( 'Invalid export request found.', 'userswp' );
133
134 if ( empty( $_POST['data'] ) || !current_user_can( 'manage_options' ) ) {
135 wp_send_json( $response );
136 }
137
138 parse_str( $_POST['data'], $data );
139
140 $data['step'] = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1;
141
142 $_REQUEST = (array)$data;
143 if ( !( !empty( $_REQUEST['uwp_export_users_nonce'] ) && wp_verify_nonce( $_REQUEST['uwp_export_users_nonce'], 'uwp_export_users_nonce' ) ) ) {
144 $response['msg'] = __( 'Security check failed.', 'userswp' );
145 wp_send_json( $response );
146 }
147
148 if ( ( $error = $this->check_export_location() ) !== true ) {
149 $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'userswp' );
150 wp_send_json( $response );
151 }
152
153 $this->set_export_params( $_REQUEST );
154
155 $return = $this->process_export_step();
156 $done = $this->get_export_status();
157
158 if ( $return ) {
159 $this->step += 1;
160
161 $response['success'] = true;
162 $response['msg'] = '';
163
164 if ( $done >= 100 ) {
165 $this->step = 'done';
166 $new_filename = 'uwp-users-export-' . date( 'y-m-d-H-i' ) . '.csv';
167 $new_file = $this->export_dir . $new_filename;
168
169 if ( file_exists( $this->file ) ) {
170 $this->wp_filesystem->move( $this->file, $new_file, true );
171 }
172
173 if ( file_exists( $new_file ) ) {
174 $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) );
175 }
176 }
177
178 $response['data']['step'] = $this->step;
179 $response['data']['done'] = $done;
180 } else {
181 $response['msg'] = __( 'No data found for export.', 'userswp' );
182 }
183
184 wp_send_json( $response );
185
186 }
187
188 /**
189 * Sets export params
190 *
191 * @package userswp
192 *
193 * @param array $request
194 *
195 */
196 public function set_export_params( $request ) {
197 $this->empty = false;
198 $this->step = !empty( $request['step'] ) ? absint( $request['step'] ) : 1;
199 $this->filename = 'uwp-users-export-temp.csv';
200 $this->file = $this->export_dir . $this->filename;
201 $chunk_per_page = !empty( $request['uwp_ie_chunk_size'] ) ? absint( $request['uwp_ie_chunk_size'] ) : 0;
202 $this->per_page = $chunk_per_page < 50 || $chunk_per_page > 100000 ? 5000 : $chunk_per_page;
203
204 do_action( 'uwp_export_users_set_params', $request );
205 }
206
207 /**
208 * Returns export file location
209 *
210 * @package userswp
211 *
212 * @return bool
213 *
214 */
215 public function check_export_location() {
216 try {
217 if ( empty( $this->wp_filesystem ) ) {
218 return __( 'Filesystem ERROR: Could not access filesystem.', 'userswp' );
219 }
220
221 if ( is_wp_error( $this->wp_filesystem ) ) {
222 return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'userswp' );
223 }
224
225 $is_dir = $this->wp_filesystem->is_dir( $this->export_dir );
226 $is_writeable = $is_dir && is_writeable( $this->export_dir );
227
228 if ( $is_dir && $is_writeable ) {
229
230 } else if ( $is_dir && !$is_writeable ) {
231 if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) {
232 return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'userswp' ), $this->export_dir );
233 }
234 } else {
235 if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) {
236 return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'userswp' ), $this->export_dir );
237 }
238 }
239
240 if(!$this->wp_filesystem->exists( $this->export_dir . '/index.php')){
241 $this->wp_filesystem->copy( USERSWP_PATH . 'assets/index.php', $this->export_dir . '/index.php' );
242 }
243
244 return true;
245 } catch ( Exception $e ) {
246 return $e->getMessage();
247 }
248 }
249
250 /**
251 * Processes export step
252 *
253 * @return bool
254 *
255 */
256 public function process_export_step() {
257 if ( $this->step < 2 ) {
258 @unlink( $this->file );
259 $this->print_columns();
260 }
261
262 $return = $this->print_rows();
263
264 if ( $return ) {
265 return true;
266 } else {
267 return false;
268 }
269 }
270
271 /**
272 * Prints columns
273 *
274 * @return array
275 *
276 */
277 public function print_columns() {
278 $column_data = '';
279 $columns = $this->get_columns();
280 $i = 1;
281 foreach( $columns as $key => $column ) {
282 $column_data .= '"' . addslashes( $column ) . '"';
283 $column_data .= $i == count( $columns ) ? '' : ',';
284 $i++;
285 }
286 $column_data .= "\r\n";
287
288 $this->attach_export_data( $column_data );
289
290 return $column_data;
291 }
292
293 /**
294 * Returns export columns
295 *
296 * @return array
297 *
298 */
299 public function get_columns() {
300 global $wpdb;
301 $columns = array();
302
303 foreach ( $wpdb->get_col( "DESC " . $this->meta_table_name, 0 ) as $column_name ) {
304 $columns[] = $column_name;
305 }
306
307 return apply_filters( 'uwp_export_users_get_columns', $columns );
308 }
309
310 /**
311 * Returns export data
312 *
313 * @package userswp
314 *
315 * @return array
316 *
317 */
318 public function get_export_data() {
319 global $wpdb;
320 if(!$this->step){
321 $page = 1;
322 } else {
323 $page = $this->step;
324 }
325
326 $page_start = absint( ( $page - 1 ) * $this->per_page );
327 $data = $wpdb->get_results( "SELECT * FROM $this->meta_table_name WHERE 1=1 LIMIT $page_start,". $this->per_page);
328 $i = 0;
329
330 foreach ($data as $u){
331 $user = get_userdata($u->user_id);
332 $data[$i]->username = $user->user_login;
333 $data[$i]->email = $user->user_email;
334 $data[$i]->bio = $user->description;
335 $i++;
336 }
337
338 return apply_filters( 'uwp_export_users_get_data', $data );
339 }
340
341 /**
342 * Returns export status
343 *
344 * @return int
345 *
346 */
347 public function get_export_status() {
348 $status = 100;
349 return apply_filters( 'uwp_get_export_users_status', $status );
350 }
351
352 /**
353 * Prints CSV rows
354 *
355 * @return string
356 *
357 */
358 public function print_rows() {
359 $row_data = '';
360 $data = $this->get_export_data();
361 $columns = $this->get_columns();
362
363 if ( is_array($data) && !empty($data) ) {
364 foreach ( $data as $row ) {
365 $i = 1;
366 foreach ( $row as $key => $column ) {
367 $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"';
368 $row_data .= $i == count( $columns ) ? '' : ',';
369 $i++;
370 }
371 $row_data .= "\r\n";
372 }
373
374 $this->attach_export_data( $row_data );
375
376 return $row_data;
377 }
378
379 return false;
380 }
381
382 /**
383 * Returns export file content
384 *
385 * @return string
386 *
387 */
388 protected function get_export_file() {
389 $file = '';
390
391 if ( $this->wp_filesystem->exists( $this->file ) ) {
392 $file = $this->wp_filesystem->get_contents( $this->file );
393 } else {
394 $this->wp_filesystem->put_contents( $this->file, '' );
395 }
396
397 return $file;
398 }
399
400 /**
401 * Adds export data to CSV file
402 *
403 * @package userswp
404 *
405 * @param string $data
406 *
407 */
408 protected function attach_export_data( $data = '' ) {
409 $filedata = $this->get_export_file();
410 $filedata .= $data;
411
412 $this->wp_filesystem->put_contents( $this->file, $filedata );
413
414 $rows = file( $this->file, FILE_SKIP_EMPTY_LINES );
415 $columns = $this->get_columns();
416 $columns = empty( $columns ) ? 0 : 1;
417
418 $this->empty = count( $rows ) == $columns ? true : false;
419 }
420
421 /**
422 * Returns export user status
423 *
424 * @return int
425 *
426 */
427 public function get_export_users_status() {
428 global $wpdb;
429 $data = $wpdb->get_results("SELECT user_id FROM $this->meta_table_name WHERE 1=1");
430 $total = !empty( $data ) ? count( $data ) : 0;
431 $status = 100;
432
433 if ( $this->per_page > $total ) {
434 $this->per_page = $total;
435 }
436
437 if ( $total > 0 ) {
438 $status = ( ( $this->per_page * $this->step ) / $total ) * 100;
439 }
440
441 if ( $status > 100 ) {
442 $status = 100;
443 }
444
445 return $status;
446 }
447
448 /**
449 * Uploaded file handling
450 *
451 * @return string
452 *
453 */
454 public function ie_upload_file(){
455
456 if ( !(!empty($_REQUEST['nonce']) && wp_verify_nonce( $_REQUEST['nonce'], 'uwp-ie-file-upload-nonce' )) ) {
457 echo 'error';return;
458 }
459
460 $upload_data = array(
461 'name' => $_FILES['import_file']['name'],
462 'type' => $_FILES['import_file']['type'],
463 'tmp_name' => $_FILES['import_file']['tmp_name'],
464 'error' => $_FILES['import_file']['error'],
465 'size' => $_FILES['import_file']['size']
466 );
467
468 header('Content-Type: text/html; charset=' . get_option('blog_charset'));
469
470 add_filter( 'upload_mimes', array( $this, 'allowed_upload_mimes' ) );
471 $uploaded_file = wp_handle_upload( $upload_data, array('test_form' => false) );
472 remove_filter( 'upload_mimes', array( $this, 'allowed_upload_mimes' ) );
473
474 if ( isset( $uploaded_file['url'] ) ) {
475 $file_loc = $uploaded_file['url'];
476 echo $file_loc;exit;
477 } else {
478 echo 'error';
479 }
480 exit;
481 }
482
483 /**
484 * Processes users import
485 *
486 */
487 public function process_users_import(){
488
489 $response = array();
490 $response['success'] = false;
491 $response['msg'] = __( 'Invalid import request found.', 'userswp' );
492
493 if ( empty( $_POST['data'] ) || !current_user_can( 'manage_options' ) ) {
494 wp_send_json( $response );
495 }
496
497 parse_str( $_POST['data'], $data );
498
499 $this->imp_step = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1;
500
501 $_REQUEST = (array)$data;
502 if ( !( !empty( $_REQUEST['uwp_import_users_nonce'] ) && wp_verify_nonce( $_REQUEST['uwp_import_users_nonce'], 'uwp_import_users_nonce' ) ) ) {
503 $response['msg'] = __( 'Security check failed.', 'userswp' );
504 wp_send_json( $response );
505 }
506
507 $allowed = array('csv');
508 $import_file = $data['uwp_import_users_file'];
509 $uploads = wp_upload_dir();
510 $csv_file_array = explode( '/', $import_file );
511 $csv_filename = end( $csv_file_array );
512 $this->path = $uploads['path'].'/'.$csv_filename;
513
514 $ext = pathinfo($csv_filename, PATHINFO_EXTENSION);
515 if (!in_array($ext, $allowed)) {
516 $response['msg'] = __( 'Invalid file type, please upload .csv file.', 'userswp' );
517 wp_send_json( $response );
518 }
519
520 $lc_all = setlocale( LC_ALL, 0 );
521 setlocale( LC_ALL, 'en_US.UTF-8' );
522 if ( ( $handle = fopen( $this->path, "r" ) ) !== false ) {
523 while ( ( $data = fgetcsv( $handle, 100000, "," ) ) !== false ) {
524 if ( ! empty( $data ) ) {
525 $file[] = $data;
526 }
527 }
528 fclose( $handle );
529 }
530 setlocale( LC_ALL, $lc_all );
531
532 $this->total_rows = ( ! empty( $file ) && count( $file ) > 1 ) ? count( $file ) - 1 : 0;
533
534 $return = $this->process_import_step();
535 $done = $this->get_import_status();
536
537 if ( $return['success'] ) {
538 $response['total']['msg'] = '';
539 if($this->total_rows > 0 && $this->imp_step == 1) {
540 $response['total']['msg'] = __( 'Total '.$this->total_rows. ' item(s) found.', 'userswp' );
541 }
542
543 $this->imp_step += 1;
544
545 $response['success'] = true;
546 $response['msg'] = '';
547
548 if ( $done >= 100 ) {
549 $this->imp_step = 'done';
550 $response['msg'] = __( 'Users import completed.', 'userswp' );
551 }
552
553 $response['data']['msg'] = $return['msg'];
554 $response['data']['step'] = $this->imp_step;
555 $response['data']['done'] = $done;
556 } else {
557 $response['msg'] = __( 'No valid data found for import.', 'userswp' );
558 }
559
560 wp_send_json( $response );
561
562 }
563
564 /**
565 * Processes import step
566 *
567 * @return array
568 *
569 */
570 public function process_import_step() {
571
572 $errors = new WP_Error();
573 if(is_null($this->path)){
574 $errors->add('no_csv_file', __('No csv file found.','userswp'));
575 }
576
577 set_time_limit(0);
578
579 $return = array('success' => false);
580
581 $rows = $this->get_csv_rows($this->imp_step, 1);
582
583 if ( ! empty( $rows ) ) {
584 foreach ( $rows as $row ) {
585 if( empty($row) ) {
586 $return['msg'] = sprintf(__('Row - %s Error: '. 'Skipped due to invalid/no data.','userswp'), $this->imp_step);
587 continue;
588 }
589
590 $username = isset($row['username']) ? $row['username'] : '';
591 $email = isset($row['email']) ? $row['email'] : '';
592 $first_name = isset($row['first_name']) ? $row['first_name'] : '';
593 $last_name = isset($row['last_name']) ? $row['last_name'] : '';
594 $bio = isset($row['bio']) ? $row['bio'] : '';
595 $display_name = isset($row['display_name']) ? $row['display_name'] : '';
596 $password = wp_generate_password();
597 $exclude = array('user_id');
598 $exclude = apply_filters('uwp_import_exclude_columns', $exclude, $row);
599
600 if(isset($row['username']) && username_exists($row['username'])){
601 $user = get_user_by('login', $row['username']);
602 $user_id = $user->ID;
603 $email = $row['email'];
604 if( !empty( $email ) && $update_existing = apply_filters('uwp_import_update_users', false, $row, $user_id) ) {
605 $args = array(
606 'ID' => $user_id,
607 'user_email' => $email,
608 'display_name' => $display_name,
609 'first_name' => $first_name,
610 'last_name' => $last_name,
611 'description' => $bio,
612 );
613 wp_update_user( $args );
614 }
615 } elseif(isset($row['email']) && email_exists($row['email'])){
616 $user = get_user_by('email', $row['email']);
617 $user_id = $user->ID;
618 } elseif((int)$row['user_id'] > 0){
619 $user = get_user_by('ID', $row['user_id']);
620 if(false === $user){
621 $userdata = array(
622 'user_login' => $row['username'],
623 'user_email' => $email,
624 'user_pass' => $password,
625 'first_name' => $first_name,
626 'last_name' => $last_name,
627 'description' => $bio,
628 'display_name'=> $display_name
629 );
630 $user_id = wp_insert_user( $userdata );
631 $notify = apply_filters('uwp_import_user_notify', 'user', $user_id);
632 wp_new_user_notification($user_id,null, $notify); //send password reset link
633 } else {
634 if( $user->user_login == $row['username'] ) { //check id passed in csv and existing username are same
635 $user_id = $row['user_id'];
636 if( !empty( $email ) && $email != $user->user_email && $update_existing = apply_filters('uwp_import_update_users', false, $row, $user_id)) {
637 $args = array(
638 'ID' => $user_id,
639 'user_email' => $email,
640 'first_name' => $first_name,
641 'last_name' => $last_name,
642 'description' => $bio,
643 'display_name' => $display_name
644 );
645 wp_update_user( $args );
646 }
647 } else {
648 $return['msg'] = sprintf(__('Row - %s Error: '. 'User could not be created.','userswp'), $this->imp_step);
649 continue;
650 }
651 }
652 } else {
653 $user_id = wp_create_user( $username, $password, $email );
654 if( !is_wp_error( $user_id ) ) {
655 $args = array(
656 'ID' => $user_id,
657 'first_name' => $first_name,
658 'last_name' => $last_name,
659 'description' => $bio,
660 'display_name' => $display_name
661 );
662 wp_update_user( $args );
663 }
664 }
665
666 if( !is_wp_error( $user_id ) ){
667 foreach ($row as $key => $value){
668 if(!in_array($key, $exclude)){
669 $value = maybe_unserialize($value);
670 uwp_update_usermeta($user_id, $key, $value);
671 }
672 }
673 } else {
674 $return['msg'] = sprintf(__('Row - %s Error: %s','userswp'), $this->imp_step, $user_id->get_error_message());
675 continue;
676 }
677 }
678 $return['success'] = true;
679 }
680
681 return $return;
682 }
683
684 /**
685 * Returns CSV row
686 *
687 * @package userswp
688 *
689 * @param int $row
690 * @param int $count
691 *
692 * @return mixed
693 *
694 */
695 public function get_csv_rows( $row = 0, $count = 1 ) {
696
697 $lc_all = setlocale( LC_ALL, 0 ); // Fix issue of fgetcsv ignores special characters when they are at the beginning of line
698 setlocale( LC_ALL, 'en_US.UTF-8' );
699 $l = $f =0;
700 $headers = $file = array();
701 $userdata_fields = $this->get_columns();
702 if ( ( $handle = fopen( $this->path, "r" ) ) !== false ) {
703 while ( ( $line = fgetcsv( $handle, 100000, "," ) ) !== false ) {
704 // If the first line is empty, abort
705 // If another line is empty, just skip it
706 if ( empty( $line ) ) {
707 if ( $l === 0 )
708 break;
709 else
710 continue;
711 }
712
713 // If we are on the first line, the columns are the headers
714 if ( $l === 0 ) {
715 $headers = $line;
716 $l ++;
717 continue;
718 }
719
720 // only get the rows needed
721 if ( $row && $count ) {
722
723 // if we have everything we need then break;
724 if ( $l == $row + $count ) {
725 break;
726
727 // if its less than the start row then continue;
728 } elseif ( $l && $l < $row ) {
729 $l ++;
730 continue;
731
732 // if we have the count we need then break;
733 } elseif ( $f > $count ) {
734 break;
735 }
736 }
737
738 // Separate user data from meta
739 $userdata = $usermeta = array();
740 foreach ( $line as $ckey => $column ) {
741 $column_name = $headers[$ckey];
742 $column = trim( $column );
743 if ( in_array( $column_name, $userdata_fields ) ) {
744 $userdata[$column_name] = $column;
745 } else {
746 $usermeta[$column_name] = $column;
747 }
748 }
749
750 // A plugin may need to filter the data and meta
751 $userdata = apply_filters( 'uwp_import_userdata', $userdata, $usermeta );
752
753 if ( ! empty( $userdata ) ) {
754 $file[] = $userdata;
755 $f ++;
756 $l ++;
757 }
758 }
759 fclose( $handle );
760 }
761 setlocale( LC_ALL, $lc_all );
762
763 return $file;
764
765 }
766
767 /**
768 * Returns import status
769 *
770 * @return int
771 *
772 */
773 public function get_import_status() {
774 $status = 100;
775 return apply_filters( 'uwp_get_import_users_status', $status );
776 }
777
778 /**
779 * Returns import user status
780 *
781 * @return int
782 *
783 */
784 public function get_import_users_status() {
785
786 if ( $this->imp_step >= $this->total_rows ) {
787 $status = 100;
788 } else {
789 $status = ( ( 1 * $this->imp_step ) / $this->total_rows ) * 100;
790 }
791
792 return $status;
793 }
794
795 public function allowed_upload_mimes($mimes = array()) {
796 $mimes['csv'] = "text/csv";
797 return $mimes;
798 }
799
800 }
801 new UsersWP_Import_Export();