admin-import-user-part-import-users.php
13.3 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
<?php
if ( ! defined( 'WPINC' ) ) {
die;
}
$option_keys = array(
'uo_import_add_to_group',
'uo_import_enrol_in_courses',
array( 'uo_import_existing_user_data', 'update' ),
'uo_import_set_roles',
);
$options = array();
foreach ( $option_keys as $meta_key ) {
if ( is_array( $meta_key ) ) {
$option = get_option( $meta_key[0], $meta_key[1] );
} else {
$option = get_option( $meta_key );
}
// all meta value have comma separated values from an array implode except uo_import_existing_user_data
if ( is_array( $meta_key ) && $meta_key[0] === 'uo_import_existing_user_data' ) {
$options[ $meta_key[0] ] = $option;
} else {
$options[ $meta_key ] = explode( ',', $option );
}
}
// New user template variables
$uo_import_users_send_new_user_email = ( get_option( 'uo_import_users_send_new_user_email' ) === 'true' ) ?
__( 'New users WILL be sent an email.', 'uncanny-pro-toolkit' ) :
__( 'New users WILL NOT be sent an email.', 'uncanny-pro-toolkit' );
// Updated user template variables
$uo_import_users_send_updated_user_email = ( get_option( 'uo_import_users_send_updated_user_email' ) === 'true' ) ?
__( 'Updated users WILL be sent an email.', 'uncanny-pro-toolkit' ) :
__( 'Updated users WILL NOT be sent an email.', 'uncanny-pro-toolkit' );
$options_link = admin_url( 'users.php?page=learndash-toolkit-import-user&tab=options' );
$emails_link = admin_url( 'users.php?page=learndash-toolkit-import-user&tab=emails' );
$csv_sample_file_link = plugins_url( basename( dirname( UO_FILE ) ) ) . '/src/assets/legacy/backend/csv/import_user_sample.csv';
?>
<div id="import-users-upload">
<h2 class="options-header-container">
<?php esc_attr_e( 'Current Settings', 'uncanny-pro-toolkit' ); ?>
</h2>
<p>
<?php if ( \uncanny_pro_toolkit\ImportLearndashUsersFromCsv::is_learndash_active() ) { ?>
<?php esc_attr_e( 'Review your enrollment defaults and email options. Make any necessary changes before proceeding to Import LearnDash Users.', 'uncanny-pro-toolkit' ); ?>
<?php } else {
esc_attr_e( 'Review your defaults and email options. Make any necessary changes before proceeding to Import Users.', 'uncanny-pro-toolkit' );
} ?>
</p>
<?php if ( \uncanny_pro_toolkit\ImportLearndashUsersFromCsv::is_learndash_active() ) { ?>
<h2><?php esc_attr_e( 'Default Course(s)', 'uncanny-pro-toolkit' ); ?></h2>
<p><?php esc_attr_e( 'Users without valid course IDs in the CSV will be enrolled in the following courses:', 'uncanny-pro-toolkit' ); ?></p>
<ul class="import-user-list">
<?php
$args = array(
'post_type' => 'sfwd-courses',
'post_status' => 'publish',
'posts_per_page' => 1000,
);
// the query
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
$meta = get_post_meta( get_the_ID(), '_sfwd-courses', true );
if ( isset( $meta['sfwd-courses_course_price_type'] ) ) {
if ( 'open' == $meta['sfwd-courses_course_price_type'] ) {
echo '<li>' . get_the_title() . '<span style="color:green;"> ' . esc_attr__( '( Course is Open to all )', 'uncanny-pro-toolkit' ) . '</span></li>';
continue;
}
}
if ( in_array( get_the_ID(), $options['uo_import_enrol_in_courses'] ) ) {
echo '<li>' . get_the_title() . '</li>';
}
};
wp_reset_postdata();
} else {
echo esc_attr__( 'No Courses Published', 'uncanny-pro-toolkit' );
}
?>
</ul>
<a href="?page=learndash-toolkit-import-user&tab=options"
class="button button-secondary"><?php esc_attr_e( 'Edit Options', 'uncanny-pro-toolkit' ); ?></a>
<h2><?php esc_attr_e( 'Default Groups(s)', 'uncanny-pro-toolkit' ); ?></h2>
<p><?php esc_attr_e( 'Users without valid group IDs in the CSV will be added to the following groups:', 'uncanny-pro-toolkit' ); ?></p>
<ul class="import-user-list">
<?php
$args = array(
'post_type' => 'groups',
'post_status' => 'publish',
'posts_per_page' => 9999,
'orderby' => 'post_title',
'order' => 'ASC',
);
// the query
$groups_query = new WP_Query( $args );
if ( $groups_query->have_posts() ) {
while ( $groups_query->have_posts() ) {
$groups_query->the_post();
if ( in_array( get_the_ID(), $options['uo_import_add_to_group'] ) ) {
echo '<li>' . get_the_title() . '</li>';
}
}
wp_reset_postdata();
} else {
echo esc_attr__( 'No Groups Published' );
}
?>
</ul>
<a href="?page=learndash-toolkit-import-user&tab=options"
class="button button-secondary"><?php esc_attr_e( 'Edit Options', 'uncanny-pro-toolkit' ); ?></a>
<?php } ?>
<h2><?php esc_attr_e( 'Default Role(s)', 'uncanny-pro-toolkit' ); ?></h2>
<p><?php esc_attr_e( 'Users without a valid role in the CSV will be set to the following role:', 'uncanny-pro-toolkit' ); ?></p>
<ul class="import-user-list">
<?php
$editable_roles = get_editable_roles();
foreach ( $editable_roles as $role => $details ) {
if ( in_array( esc_attr( $role ), $options['uo_import_set_roles'] ) ) {
echo '<li>' . $details['name'] . '</li>';
}
}
?>
</ul>
<a href="?page=learndash-toolkit-import-user&tab=options"
class="button button-secondary"><?php esc_attr_e( 'Edit Options', 'uncanny-pro-toolkit' ); ?></a>
<h2><?php esc_attr_e( 'Email Options', 'uncanny-pro-toolkit' ); ?></h2>
<p><?php echo $uo_import_users_send_new_user_email; ?></p>
<p><?php echo $uo_import_users_send_updated_user_email; ?></p>
<a href="?page=learndash-toolkit-import-user&tab=emails"
class="button button-secondary"><?php esc_attr_e( 'Edit Email Settings', 'uncanny-pro-toolkit' ); ?></a>
<h2 class="options-header-container"><?php esc_attr_e( 'Import Users', 'uncanny-pro-toolkit' ); ?></h2>
<p><?php esc_attr_e( 'Upload the CSV file and review verification results.', 'uncanny-pro-toolkit' ); ?></p>
<form action="<?php echo admin_url( 'admin-ajax.php' ) ?>" id="file-upload" enctype="multipart/form-data">
<input type="file" name="csv" id="csv-file"/>
<br>
<input type="submit" class="button button-primary"
value="<?php esc_attr_e( 'Upload file and verify records', 'uncanny-pro-toolkit' ); ?>"/>
</form>
</div>
<div id="import-users-validation">
<h2 class="options-header-container"><?php esc_attr_e( 'Validation Results', 'uncanny-pro-toolkit' ); ?></h2>
<table class="wp-list-table widefat fixed striped posts">
<thead>
<tr>
<td><?php esc_attr_e( 'Type', 'uncanny-pro-toolkit' ); ?></td>
<td><?php esc_attr_e( 'Number', 'uncanny-pro-toolkit' ); ?></td>
</tr>
</thead>
<tbody>
<tr>
<td><?php esc_attr_e( 'Total number of users found in CSV', 'uncanny-pro-toolkit' ); ?></td>
<td id="total-rows"></td>
</tr>
<tr>
<td><?php esc_attr_e( 'New users that will be created', 'uncanny-pro-toolkit' ); ?></td>
<td id="new-emails"></td>
</tr>
<tr>
<td>
<?php
if ( 'update' === $options['uo_import_existing_user_data'] ) {
_e( 'Existing users that WILL be updated', 'uncanny-pro-toolkit' );
} else {
_e( 'Existing users that WILL NOT be updated', 'uncanny-pro-toolkit' );
}
?>
</td>
<td id="existing-emails"></td>
</tr>
<tr>
<td><?php esc_attr_e( 'Users with malformed email addresses', 'uncanny-pro-toolkit' ); ?></td>
<td id="malformed-emails"></td>
</tr>
<?php if ( \uncanny_pro_toolkit\ImportLearndashUsersFromCsv::is_learndash_active() ) { ?>
<tr>
<td><?php esc_attr_e( 'Users with invalid course IDs', 'uncanny-pro-toolkit' ); ?></td>
<td id="invalid-courses"></td>
</tr>
<tr>
<td><?php esc_attr_e( 'Users with invalid group IDs', 'uncanny-pro-toolkit' ); ?></td>
<td id="invalid-groups"></td>
</tr>
<tr>
<td><?php esc_attr_e( 'Users with invalid group IDs for the Group Leader', 'uncanny-pro-toolkit' ); ?></td>
<td id="invalid-groupleaders"></td>
</tr>
<?php } ?>
</tbody>
</table>
<h2 class="options-header-container"><?php esc_attr_e( 'Skipped Users with Existing Emails', 'uncanny-pro-toolkit' ); ?></h2>
<p>
<?php esc_attr_e( 'The emails listed below were found in the CSV, but are assigned to users that already exist in WordPress. WordPress requires that each email be unique.', 'uncanny-pro-toolkit' ); ?>
</p>
<h4><?php esc_attr_e( 'These records will be ignored.', 'uncanny-pro-toolkit' ); ?></h4>
<table id="existing-user-email-table" class="wp-list-table widefat fixed striped posts">
<thead>
<tr>
<td><?php esc_attr_e( 'CSV Row', 'uncanny-pro-toolkit' ); ?></td>
<td><?php esc_attr_e( 'Email', 'uncanny-pro-toolkit' ); ?></td>
<td><?php esc_attr_e( 'Conflicting User', 'uncanny-pro-toolkit' ); ?></td>
</tr>
</thead>
<tbody>
</tbody>
</table>
<?php if ( \uncanny_pro_toolkit\ImportLearndashUsersFromCsv::is_learndash_active() ) { ?>
<h2 class="options-header-container"><?php esc_attr_e( 'Invalid Course IDs', 'uncanny-pro-toolkit' ); ?></h2>
<p>
<?php esc_attr_e( 'The course IDs below were found in the CSV but do not correspond to an existing LearnDash course. If you proceed, they will be ignored.', 'uncanny-pro-toolkit' ); ?>
</p>
<h4><?php esc_attr_e( 'These course IDs will be ignored.', 'uncanny-pro-toolkit' ); ?></h4>
<table id="invalid-courses-table" class="wp-list-table widefat fixed striped posts">
<thead>
<tr>
<td><?php esc_attr_e( 'CSV Row', 'uncanny-pro-toolkit' ); ?></td>
<td><?php esc_attr_e( 'Invalid Course IDs', 'uncanny-pro-toolkit' ); ?></td>
</tr>
</thead>
<tbody>
</tbody>
</table>
<h2 class="options-header-container"><?php esc_attr_e( 'Invalid Group IDs', 'uncanny-pro-toolkit' ); ?></h2>
<p>
<?php esc_attr_e( 'The group IDs below were found in the CSV but do not correspond to an existing LearnDash group. If you proceed, they will be ignored.', 'uncanny-pro-toolkit' ); ?>
</p>
<h4><?php esc_attr_e( 'These group IDs will be ignored.', 'uncanny-pro-toolkit' ); ?></h4>
<table id="invalid-groups-table" class="wp-list-table widefat fixed striped posts">
<thead>
<tr>
<td><?php esc_attr_e( 'CSV Row', 'uncanny-pro-toolkit' ); ?></td>
<td><?php esc_attr_e( 'Invalid Group IDs', 'uncanny-pro-toolkit' ); ?></td>
</tr>
</thead>
<tbody>
</tbody>
</table>
<h4><?php esc_attr_e( 'These group IDs will be ignored when adding the user as a Group Leader.', 'uncanny-pro-toolkit' ); ?></h4>
<table id="invalid-groupleaders-table" class="wp-list-table widefat fixed striped posts">
<thead>
<tr>
<td><?php esc_attr_e( 'CSV Row', 'uncanny-pro-toolkit' ); ?></td>
<td><?php esc_attr_e( 'Invalid Group IDs', 'uncanny-pro-toolkit' ); ?></td>
</tr>
</thead>
<tbody>
</tbody>
</table>
<?php } ?>
<h2 class="options-header-container"><?php esc_attr_e( "Let's Add Some Users!", 'uncanny-pro-toolkit' ); ?></h2>
<div class="perform-import-users">
<button class="button button-large"
id="abort-import-users"><?php esc_attr_e( 'Abort Import Process', 'uncanny-pro-toolkit' ); ?></button>
<button class="button button-primary button-large"
id="perform-import-users"><?php esc_attr_e( 'Perform Import', 'uncanny-pro-toolkit' ); ?></button>
<h3 id="perform-import-users-text">
<?php esc_attr_e( 'It is not possible to cancel the import process once it has begun.', 'uncanny-pro-toolkit' ); ?>
</h3>
<button id="perform-import-users-review" class="button button-large">
<?php esc_attr_e( 'Let me review the validation results again', 'uncanny-pro-toolkit' ); ?>
</button>
<button id="perform-import-users-ready" class="button button-primary button-large">
<?php esc_attr_e( 'I\'m ready to import', 'uncanny-pro-toolkit' ); ?>
</button>
</div>
</div>
<div id="import-users-progress">
<h2 class="options-header-container"><?php esc_attr_e( 'Import Progress', 'uncanny-pro-toolkit' ); ?></h2>
<div class="import-progress-bar">
<img src="<?php echo site_url(); ?>/wp-includes/js/thickbox/loadingAnimation.gif"
data-lazy-src="<?php echo site_url(); ?>/wp-includes/js/thickbox/loadingAnimation.gif" class="lazyloaded"
scale="0">
<div class="import-progress-bar-overlay"></div>
</div>
<h3><?php esc_attr_e( 'Do not reload this page while import is in progress', 'uncanny-pro-toolkit' ); ?></h3>
<div id="import-users-results">
<h2 class="options-header-container"><?php esc_attr_e( 'Import Results', 'uncanny-pro-toolkit' ); ?></h2>
<table id="import-users-results-table" class="wp-list-table widefat fixed striped posts">
<tbody>
<tr>
<td><?php esc_attr_e( 'New Users Created', 'uncanny-pro-toolkit' ); ?></td>
<td id="import-users-results-new-users"></td>
</tr>
<tr>
<td><?php esc_attr_e( 'Existing Users Updated', 'uncanny-pro-toolkit' ); ?></td>
<td id="import-users-results-updated-users"></td>
</tr>
<tr>
<td><?php esc_attr_e( 'Emails Sent', 'uncanny-pro-toolkit' ); ?></td>
<td id="import-users-results-emails-sent"></td>
</tr>
<tr>
<td><?php esc_attr_e( 'Rows Ignored', 'uncanny-pro-toolkit' ); ?></td>
<td id="import-users-results-rows-ignored"></td>
</tr>
</tbody>
</table>
<h2 class="options-header-container"><?php esc_attr_e( 'The following rows in the CSV were skipped:', 'uncanny-pro-toolkit' ); ?></h2>
<table id="import-users-ignored-table" class="wp-list-table widefat fixed striped posts">
<thead>
<tr>
<td><?php esc_attr_e( 'CSV Row', 'uncanny-pro-toolkit' ); ?></td>
<td><?php esc_attr_e( 'Issue', 'uncanny-pro-toolkit' ); ?></td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>