import-users-from-csv.php
22.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
<?php
/*
Plugin Name: TZ Import Users from CSV
Description: Import Users data and metadata from a csv file.
Version: 10.0.1
Author: Andrew Lima
Author URI:
License: GPL2
Text Domain: import-users-from-csv
*/
/*
* Copyright 2011 Ulrich Sossou (https://github.com/sorich87)
* Copyright 2018 Andrew Lima (https://github.com/andrewlimaza/import-users-from-csv)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @package Import_Users_from_CSV
*/
load_plugin_textdomain( 'import-users-from-csv', false, basename( dirname( __FILE__ ) ) . '/languages' );
if ( ! defined( 'IS_IU_CSV_DELIMITER' ) ){
define ( 'IS_IU_CSV_DELIMITER', ',' );
}
/**
* Main plugin class
*
* @since 0.1
**/
class IS_IU_Import_Users {
private static $log_dir_path = '';
private static $log_dir_url = '';
/**
* Initialization
*
* @since 0.1
**/
public static function init() {
add_action( 'admin_menu', array( __CLASS__, 'add_admin_pages' ) );
add_action( 'init', array( __CLASS__, 'process_csv' ) );
$upload_dir = wp_upload_dir();
self::$log_dir_path = trailingslashit( $upload_dir['basedir'] );
self::$log_dir_url = trailingslashit( $upload_dir['baseurl'] );
do_action('is_iu_after_init');
}
/**
* Add administration menus
*
* @since 0.1
**/
public static function add_admin_pages() {
add_users_page( __( 'Import From CSV' , 'import-users-from-csv'), __( 'Import From CSV' , 'import-users-from-csv'), 'create_users', 'import-users-from-csv', array( __CLASS__, 'users_page' ) );
add_users_page( __( 'Add users to couses from CSV' , 'import-users-from-csv'), __( 'Import From CSV' , 'import-users-from-csv'), 'create_users', 'import-users-from-csv', array( __CLASS__, 'users_page_course' ) );
}
/**
* Process content of CSV file
*
* @since 0.1
**/
public static function process_csv() {
if ( isset( $_POST['_wpnonce-is-iu-import-users-users-page_import'] ) ) {
check_admin_referer( 'is-iu-import-users-users-page_import', '_wpnonce-is-iu-import-users-users-page_import' );
if ( !empty( $_FILES['users_csv']['tmp_name'] ) ) {
/* Setup settings variables */
$filename = sanitize_text_field( $_FILES['users_csv']['tmp_name'] );
$password_nag = isset( $_POST['password_nag'] ) ? sanitize_text_field( $_POST['password_nag'] ) : false;
$users_update = isset( $_POST['users_update'] ) ? sanitize_text_field( $_POST['users_update'] ) : false;
$new_user_notification = isset( $_POST['new_user_notification'] ) ? sanitize_text_field( $_POST['new_user_notification'] ) : false;
if($_POST['type'] == 'course'){
$results = self::import_course_csv( $filename, array() );
}else{
$results = self::import_csv( $filename, array(
'password_nag' => intval( $password_nag ),
'new_user_notification' => intval( $new_user_notification ),
'users_update' => intval( $users_update )
) );
}
if ( ! $results['user_ids'] ){
/* No users imported? */
wp_redirect( add_query_arg( 'import', 'fail', wp_get_referer() ) );
} else if ( $results['errors'] ){
/* Some users imported? */
wp_redirect( add_query_arg( 'import', 'errors', wp_get_referer() ) );
} else {
/* All users imported? :D */
wp_redirect( add_query_arg( 'import', 'success', wp_get_referer() ) );
}
exit;
}
wp_redirect( add_query_arg( 'import', 'file', wp_get_referer() ) );
exit;
}
}
/**
* Content of the settings page
*
* @since 0.1
**/
public static function users_page() {
if ( ! current_user_can( 'create_users' ) ){
wp_die( __( 'You do not have sufficient permissions to access this page.' , 'import-users-from-csv') );
}
?>
<div class="wrap">
<h2><?php _e( 'Import users from a CSV file' , 'import-users-from-csv'); ?></h2>
<?php
$error_log_file = self::$log_dir_path . 'is_iu_errors.html';
$error_log_url = self::$log_dir_url . 'is_iu_errors.html';
if ( ! file_exists( $error_log_file ) ) {
if ( ! @fopen( $error_log_file, 'x' ) ){
$message = sprintf( __( 'Notice: please make the directory %s writable so that you can see the error log.' , 'import-users-from-csv'), self::$log_dir_path );
self::render_notice('updated', $message);
}
}
$import = isset( $_GET['import'] ) ? sanitize_text_field( $_GET['import'] ) : false;
if ( $import ) {
$error_log_msg = '';
if ( file_exists( $error_log_file ) ){
$error_log_msg = sprintf( __( ", please <a href='%s' target='_blank'>check the error log</a>", 'import-users-from-csv'), esc_url( $error_log_url ) );
}
switch ( $import ) {
case 'file':
$message = __( 'Error during file upload.' , 'import-users-from-csv');
self::render_notice('error', $message);
break;
case 'data':
$message = __( 'Cannot extract data from uploaded file or no file was uploaded.' , 'import-users-from-csv');
self::render_notice('error', $message);
break;
case 'fail':
$message = sprintf( __( 'No user was successfully imported%s.' , 'import-users-from-csv'), $error_log_msg );
self::render_notice('error', $message);
break;
case 'errors':
$message = sprintf( __( 'Some users were successfully imported but some were not%s.' , 'import-users-from-csv'), $error_log_msg );
self::render_notice('update-nag', $message);
break;
case 'success':
$message = __( 'Users import was successful.' , 'import-users-from-csv');
self::render_notice('updated', $message);
break;
default:
break;
}
}
?>
<form method="post" action="" enctype="multipart/form-data">
<?php wp_nonce_field( 'is-iu-import-users-users-page_import', '_wpnonce-is-iu-import-users-users-page_import' ); ?>
<?php do_action('is_iu_import_page_before_table'); ?>
<table class="form-table widefat wp-list-table" style='padding: 5px;'>
<?php do_action('is_iu_import_page_inside_table_top'); ?>
<tr valign="top">
<td scope="row">
<strong>
<label for="users_csv"><?php _e( 'CSV file' , 'import-users-from-csv'); ?></label>
</strong>
</td>
<td>
<input type="file" id="users_csv" name="users_csv" value="" class="all-options" /><br />
<span class="description">
<?php
echo sprintf( __( 'You may want to see <a href="%s">the example of the CSV file</a>.' , 'import-users-from-csv'), esc_url( plugin_dir_url(__FILE__).'examples/import.csv' ) );
?>
</span>
</td>
</tr>
<tr valign="top">
<td scope="row">
<strong>
<?php _e( 'Notification' , 'import-users-from-csv'); ?>
</strong>
</td>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php _e( 'Notification' , 'import-users-from-csv'); ?></span></legend>
<label for="new_user_notification">
<input id="new_user_notification" name="new_user_notification" type="checkbox" value="1" />
<?php _e('Send to new users', 'import-users-from-csv'); ?>
</label>
</fieldset>
</td>
</tr>
<tr valign="top">
<td scope="row">
<strong>
<?php _e( 'Password nag' , 'import-users-from-csv'); ?>
</strong>
</td>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php _e( 'Password nag' , 'import-users-from-csv'); ?></span></legend>
<label for="password_nag">
<input id="password_nag" name="password_nag" type="checkbox" value="1" />
<?php _e('Show password nag on new users signon', 'import-users-from-csv') ?>
</label>
</fieldset>
</td>
</tr>
<tr valign="top">
<td scope="row"><strong><?php _e( 'Users update' , 'import-users-from-csv'); ?></strong></td>
<td>
<fieldset>
<legend class="screen-reader-text"><span><?php _e( 'Users update' , 'import-users-from-csv' ); ?></span></legend>
<label for="users_update">
<input id="users_update" name="users_update" type="checkbox" value="1" />
<?php _e( 'Update user when a username or email exists', 'import-users-from-csv' ) ;?>
</label>
</fieldset>
</td>
</tr>
<?php do_action('is_iu_import_page_inside_table_bottom'); ?>
</table>
<?php do_action('is_iu_import_page_after_table'); ?>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e( 'Import' , 'import-users-from-csv'); ?>" />
</p>
</form>
<?php
}
public static function users_page_course() {
if ( ! current_user_can( 'create_users' ) ){
wp_die( __( 'You do not have sufficient permissions to access this page.' , 'import-users-from-csv') );
}
?>
<div class="wrap">
<h2><?php _e( 'Add users to couses from CSV' , 'import-users-from-csv'); ?></h2>
<?php
$error_log_file = self::$log_dir_path . 'is_iu_errors.html';
$error_log_url = self::$log_dir_url . 'is_iu_errors.html';
if ( ! file_exists( $error_log_file ) ) {
if ( ! @fopen( $error_log_file, 'x' ) ){
$message = sprintf( __( 'Notice: please make the directory %s writable so that you can see the error log.' , 'import-users-from-csv'), self::$log_dir_path );
self::render_notice('updated', $message);
}
}
$import = isset( $_GET['import'] ) ? sanitize_text_field( $_GET['import'] ) : false;
if ( $import ) {
$error_log_msg = '';
if ( file_exists( $error_log_file ) ){
$error_log_msg = sprintf( __( ", please <a href='%s' target='_blank'>check the error log</a>", 'import-users-from-csv'), esc_url( $error_log_url ) );
}
switch ( $import ) {
case 'file':
$message = __( 'Error during file upload.' , 'import-users-from-csv');
self::render_notice('error', $message);
break;
case 'data':
$message = __( 'Cannot extract data from uploaded file or no file was uploaded.' , 'import-users-from-csv');
self::render_notice('error', $message);
break;
case 'fail':
$message = sprintf( __( 'No user was successfully imported%s.' , 'import-users-from-csv'), $error_log_msg );
self::render_notice('error', $message);
break;
case 'errors':
$message = sprintf( __( 'Some users were successfully imported but some were not%s.' , 'import-users-from-csv'), $error_log_msg );
self::render_notice('update-nag', $message);
break;
case 'success':
$message = __( 'Users import was successful.' , 'import-users-from-csv');
self::render_notice('updated', $message);
break;
default:
break;
}
}
?>
<form method="post" action="" enctype="multipart/form-data">
<?php wp_nonce_field( 'is-iu-import-users-users-page_import', '_wpnonce-is-iu-import-users-users-page_import' ); ?>
<?php do_action('is_iu_import_page_before_table'); ?>
<table class="form-table widefat wp-list-table" style='padding: 5px;'>
<?php do_action('is_iu_import_page_inside_table_top'); ?>
<tr valign="top">
<td scope="row">
<strong>
<label for="users_csv"><?php _e( 'CSV file' , 'import-users-from-csv'); ?></label>
</strong>
</td>
<td>
<input type="hidden" id="type" name="type" value="course" />
<input type="file" id="users_csv" name="users_csv" value="" class="all-options" /><br />
<span class="description">
<?php
echo sprintf( __( 'You may want to see <a href="%s">the example of the CSV file</a>.' , 'import-users-from-csv'), esc_url( plugin_dir_url(__FILE__).'examples/import_to_course.csv' ) );
?>
</span>
</td>
</tr>
<?php do_action('is_iu_import_page_inside_table_bottom'); ?>
</table>
<?php do_action('is_iu_import_page_after_table'); ?>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e( 'Import' , 'import-users-from-csv'); ?>" />
</p>
</form>
<?php
}
/**
* Import a csv file
*
* @since 0.5
*/
public static function import_csv( $filename, $args ) {
/* Stop timeouts */
@set_time_limit(0);
if ( ! class_exists( 'ReadCSV' ) ) {
include( plugin_dir_path( __FILE__ ) . 'class-readcsv.php' );
}
$errors = $user_ids = array();
$defaults = array(
'password_nag' => false,
'new_user_notification' => false,
'users_update' => false
);
extract( wp_parse_args( $args, $defaults ) );
/*
* User data field map, used to match datasets
*/
$userdata_fields = array(
'ID',
'user_login',
'user_pass',
'user_email',
'user_url',
'user_nicename',
'display_name',
'user_registered',
'first_name',
'last_name',
'nickname',
'description',
'rich_editing',
'comment_shortcuts',
'admin_color',
'use_ssl',
'show_admin_bar_front',
'show_admin_bar_admin',
'role'
);
/* Filter for the user field map */
apply_filters('is_iu_userdata_fields', $userdata_fields);
/* Loop through the file lines */
$file_handle = @fopen( $filename, 'r' );
if($file_handle) {
$csv_reader = new ReadCSV( $file_handle, IS_IU_CSV_DELIMITER, "\xEF\xBB\xBF" ); // Skip any UTF-8 byte order mark.
$first = true;
$rkey = 0;
while ( ( $line = $csv_reader->get_row() ) !== NULL ) {
if ( empty( $line ) ) {
if ( $first ){
/* If the first line is empty, abort */
break;
} else{
/* If another line is empty, just skip it */
continue;
}
}
if ( $first ) {
/* If we are on the first line, the columns are the headers */
$headers = $line;
$first = false;
continue;
}
/* Separate user data from meta */
$userdata = $usermeta = array();
foreach ( $line as $ckey => $column ) {
$column_name = $headers[$ckey];
$column = trim( $column );
if ( in_array( $column_name, $userdata_fields ) ) {
$userdata[$column_name] = $column;
} else {
/**
* Data cleanup:
*
* Let's do a loose match on the column name
* This is to allow for small typos like 'UsEr PaSS' to be converted to 'user_pass'
*
* Todo: Add support for all uppercase as well
*/
$formatted_column_name = strtolower($column_name);
$formatted_column_name = str_replace(' ', '_', $formatted_column_name);
$formatted_column_name = str_replace('-', '_', $formatted_column_name);
if( in_array( $formatted_column_name, $userdata_fields) ){
/**
* We have a formatted match
*/
$userdata[$formatted_column_name] = $column;
} else {
/*
* We still have no match
* let's assume this is a meta value
*/
$usermeta[$column_name] = $column;
}
}
}
/*
* Hooks to allow other plugins from filtering this data
*/
$userdata = apply_filters( 'is_iu_import_userdata', $userdata, $usermeta );
$usermeta = apply_filters( 'is_iu_import_usermeta', $usermeta, $userdata );
if ( empty( $userdata ) ){
/* If no user data, bailout! */
continue;
}
/* Hook to allow other plugins to execute additional code pre-import */
do_action( 'is_iu_pre_user_import', $userdata, $usermeta );
$user = $user_id = false;
if ( isset( $userdata['ID'] ) ){
$user = get_user_by( 'ID', $userdata['ID'] );
}
/**
* Find the user by some alternative fields
*
* Fields checked: user_login, user_email
*/
if ( ! $user && $users_update ) {
if ( isset( $userdata['user_login'] ) ){
$user = get_user_by( 'login', $userdata['user_login'] );
}
if ( ! $user && isset( $userdata['user_email'] ) ){
$user = get_user_by( 'email', $userdata['user_email'] );
}
}
$update = false;
if ( $user ) {
$userdata['ID'] = $user->ID;
$update = true;
}
if ( ! $update && empty( $userdata['user_pass'] ) ){
/* No password set for this user, let's generate one automatically */
$userdata['user_pass'] = wp_generate_password( 12, false );
}
if ( $update ){
$user_id = wp_update_user( $userdata );
} else {
$user_id = wp_insert_user( $userdata );
}
/* Is there an error o_O? */
if ( is_wp_error( $user_id ) ) {
$errors[$rkey] = $user_id;
} else {
/* If no error, let's update the user meta too! */
if ( $usermeta ) {
foreach ( $usermeta as $metakey => $metavalue ) {
$metavalue = maybe_unserialize( $metavalue );
update_user_meta( $user_id, $metakey, $metavalue );
}
}
/* If we created a new user, maybe set password nag and send new user notification? */
if ( ! $update ) {
if ( $password_nag ){
update_user_option( $user_id, 'default_password_nag', true, true );
}
if ( $new_user_notification ) {
wp_new_user_notification( $user_id, null, 'user' );
}
}
/* Hook to allow other plugins to run functionality post import */
do_action( 'is_iu_post_user_import', $user_id );
$user_ids[] = $user_id;
}
$rkey++;
}
fclose( $file_handle );
} else {
$errors[] = new WP_Error('file_read', 'Unable to open CSV file.');
}
/* One more thing to do after all imports? */
do_action( 'is_iu_post_users_import', $user_ids, $errors );
/* Let's log the errors */
self::log_errors( $errors );
return array(
'user_ids' => $user_ids,
'errors' => $errors
);
}
/**
* Import a csv file
*
* @since 0.5
*/
public static function import_course_csv( $filename, $args ) {
/* Stop timeouts */
@set_time_limit(0);
if ( ! class_exists( 'ReadCSV' ) ) {
include( plugin_dir_path( __FILE__ ) . 'class-readcsv.php' );
}
$errors = $user_ids = array();
$defaults = array(
'password_nag' => false,
'new_user_notification' => false,
'users_update' => false
);
extract( wp_parse_args( $args, $defaults ) );
/* Loop through the file lines */
$file_handle = @fopen( $filename, 'r' );
if($file_handle) {
$csv_reader = new ReadCSV( $file_handle, IS_IU_CSV_DELIMITER, "\xEF\xBB\xBF" ); // Skip any UTF-8 byte order mark.
$first = true;
$rkey = 0;
while ( ( $line = $csv_reader->get_row() ) !== NULL ) {
if ( empty( $line ) ) {
if ( $first ){
/* If the first line is empty, abort */
break;
} else{
/* If another line is empty, just skip it */
continue;
}
}
if ( $first ) {
/* If we are on the first line, the columns are the headers */
$headers = $line;
$first = false;
continue;
}
/* Separate user data from meta */
$userdata = $usermeta = array();
foreach ( $line as $ckey => $column ) {
$column_name = $headers[$ckey];
$column = trim( $column );
$userdata[$column_name] = $column;
$user = get_user_by( 'email', $userdata['user_email'] );
if($user)
{
$user_id = $user->ID;
if($column_name == 'group_id'){
if($userdata['group_id'] != ""){
ld_update_group_access( $user_id, $userdata['group_id'], false );
}
}
if($column_name == 'course_id'){
if($userdata['course_id'] != ""){
$course_id = $userdata['course_id'];
ld_update_course_access( $user_id, $userdata['course_id'], false );
learndash_process_mark_complete( $user_id, 45654 );
learndash_user_course_complete_all_steps( $user_id, $userdata['course_id']);
}
}
if($column_name == 'date_completed'){
if($userdata['date_completed'] != ""){
$date_completed = $userdata['date_completed'];
$d = DateTime::createFromFormat(
'm/d/Y 00:00:00',
$date_completed.' 00:00:00',
new DateTimeZone('UTC')
);
if ($d != false) {
update_user_meta($user_id, 'course_completed_'.$course_id , $d->getTimestamp() );
}
}
}
if($column_name == 'badge_id'){
if($userdata['badge_id'] != ""){
$custom_query = get_post($userdata['badge_id']);
global $wpdb;
$wpdb->insert($wpdb->prefix.'badgeos_achievements', array(
'ID' => $custom_query->ID,
'sub_nom_id' => 0,
'post_type' => 'badges',
'achievement_title' => get_the_title($custom_query->ID ),
'rec_type' => 0,
'points' => 0,
'point_type' => 0,
'user_id' => absint($user_id ),
'this_trigger' => '',
'image' => '',
'site_id' => 0,
'actual_date_earned' => badgeos_default_datetime( 'mysql_ranks' ),
'date_earned' => current_time( 'mysql' )
));
}
}
}else{
if($column_name == 'user_email'){
$errors[] = new WP_Error('Unknown user', $userdata['user_email'] );
}
}
$user_ids[] = $user_id;
}
$rkey++;
}
fclose( $file_handle );
} else {
$errors[] = new WP_Error('file_read', 'Unable to open CSV file.');
}
/* One more thing to do after all imports? */
do_action( 'is_iu_post_users_import', $user_ids, $errors );
/* Let's log the errors */
self::log_errors( $errors );
return array(
'user_ids' => $user_ids,
'errors' => $errors
);
}
/**
* Log errors to a file
*
* @since 0.2
**/
private static function log_errors( $errors ) {
if ( empty( $errors ) ){
return;
}
$log = @fopen( self::$log_dir_path . 'is_iu_errors.html', 'a' );
@fwrite( $log, sprintf( __( 'BEGIN %s' , 'import-users-from-csv'), date_i18n( 'Y-m-d H:i:s', time() ) ) . "<br>" );
foreach ( $errors as $key => $error ) {
$line = $key + 1;
$message = $error->get_error_message();
@fwrite( $log, sprintf( __( '[Line %1$s] %2$s' , 'import-users-from-csv'), $line, $message ) . "<br>" );
}
@fclose( $log );
}
/**
* Echo out a notice withs specific class.
*
* @param $class - class to add to div
* @param $message - The content of the notice. This should be escaped before being passed in to ensure proper escaping is done.
*
*
* @since 1.0.1
*/
private static function render_notice($class, $message){
$class = esc_attr($class);
echo "<div class='$class'><p><strong>$message</strong></p></div>";
}
}
IS_IU_Import_Users::init();