Version Description
- Code is being rewritten to make it easy to update
Download this release
Release Info
Developer | carazo |
Plugin | Import users from CSV with meta |
Version | 1.16 |
Comparing to | |
See all releases |
Code changes from version 1.15.9.2 to 1.16
- classes/export.php +1 -1
- classes/frontend.php +1 -1
- classes/homepage.php +9 -1
- classes/rest-api.php +1 -1
- import-users-from-csv-with-meta.php +222 -495
- importer.php +257 -1
- readme.txt +4 -1
classes/export.php
CHANGED
@@ -127,7 +127,7 @@ class ACUI_Exporter{
|
|
127 |
function export_users_csv(){
|
128 |
check_ajax_referer( 'codection-security', 'security' );
|
129 |
|
130 |
-
if( !current_user_can( 'create_users' ) )
|
131 |
wp_die( __( 'Only users who are able to create users can export them.', 'import-users-from-csv-with-meta' ) );
|
132 |
|
133 |
$role = sanitize_text_field( $_POST['role'] );
|
127 |
function export_users_csv(){
|
128 |
check_ajax_referer( 'codection-security', 'security' );
|
129 |
|
130 |
+
if( !current_user_can( apply_filters( 'acui_capability', 'create_users' ) ) )
|
131 |
wp_die( __( 'Only users who are able to create users can export them.', 'import-users-from-csv-with-meta' ) );
|
132 |
|
133 |
$role = sanitize_text_field( $_POST['role'] );
|
classes/frontend.php
CHANGED
@@ -247,7 +247,7 @@ class ACUI_Frontend{
|
|
247 |
|
248 |
ob_start();
|
249 |
|
250 |
-
if( !current_user_can( 'create_users' ) )
|
251 |
wp_die( __( 'Only users who are able to create users can manage this form.', 'import-users-from-csv-with-meta' ) );
|
252 |
|
253 |
if ( $_FILES && !empty( $_POST ) ):
|
247 |
|
248 |
ob_start();
|
249 |
|
250 |
+
if( !current_user_can( apply_filters( 'acui_capability', 'create_users' ) ) )
|
251 |
wp_die( __( 'Only users who are able to create users can manage this form.', 'import-users-from-csv-with-meta' ) );
|
252 |
|
253 |
if ( $_FILES && !empty( $_POST ) ):
|
classes/homepage.php
CHANGED
@@ -6,7 +6,7 @@ class ACUI_Homepage{
|
|
6 |
public static function admin_gui(){
|
7 |
$last_roles_used = empty( get_option( 'acui_last_roles_used' ) ) ? array( 'subscriber' ) : get_option( 'acui_last_roles_used' );
|
8 |
|
9 |
-
|
10 |
?>
|
11 |
<div class="wrap acui">
|
12 |
|
@@ -312,4 +312,12 @@ class ACUI_Homepage{
|
|
312 |
</div>
|
313 |
<?php endif;
|
314 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
}
|
6 |
public static function admin_gui(){
|
7 |
$last_roles_used = empty( get_option( 'acui_last_roles_used' ) ) ? array( 'subscriber' ) : get_option( 'acui_last_roles_used' );
|
8 |
|
9 |
+
self::check_options();
|
10 |
?>
|
11 |
<div class="wrap acui">
|
12 |
|
312 |
</div>
|
313 |
<?php endif;
|
314 |
}
|
315 |
+
|
316 |
+
public static function check_options(){
|
317 |
+
if( get_option( "acui_mail_body" ) == "" )
|
318 |
+
update_option( "acui_mail_body", __( 'Welcome,', 'import-users-from-csv-with-meta' ) . '<br/>' . __( 'Your data to login in this site is:', 'import-users-from-csv-with-meta' ) . '<br/><ul><li>' . __( 'URL to login', 'import-users-from-csv-with-meta' ) . ': **loginurl**</li><li>' . __( 'Username', 'import-users-from-csv-with-meta' ) . ' = **username**</li><li>' . __( 'Password', 'import-users-from-csv-with-meta' ) . ' = **password**</li></ul>' );
|
319 |
+
|
320 |
+
if( get_option( "acui_mail_subject" ) == "" )
|
321 |
+
update_option( "acui_mail_subject", __('Welcome to','import-users-from-csv-with-meta') . ' ' . get_bloginfo("name") );
|
322 |
+
}
|
323 |
}
|
classes/rest-api.php
CHANGED
@@ -12,7 +12,7 @@ class ACUI_REST_API{
|
|
12 |
'methods' => 'GET',
|
13 |
'callback' => array( $this, 'fire_cron' ),
|
14 |
'permission_callback' => function () {
|
15 |
-
return current_user_can( 'create_users' );
|
16 |
}
|
17 |
) );
|
18 |
}
|
12 |
'methods' => 'GET',
|
13 |
'callback' => array( $this, 'fire_cron' ),
|
14 |
'permission_callback' => function () {
|
15 |
+
return current_user_can( apply_filters( 'acui_capability', 'create_users' ) );
|
16 |
}
|
17 |
) );
|
18 |
}
|
import-users-from-csv-with-meta.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Import and export users and customers
|
4 |
Plugin URI: https://www.codection.com
|
5 |
Description: Using this plugin you will be able to import and export users or customers choosing many options and interacting with lots of other plugins
|
6 |
-
Version: 1.
|
7 |
Author: codection
|
8 |
Author URI: https://codection.com
|
9 |
License: GPL2
|
@@ -14,535 +14,262 @@ Domain Path: /languages
|
|
14 |
if ( ! defined( 'ABSPATH' ) )
|
15 |
exit;
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
if( is_plugin_active( 'buddypress/bp-loader.php' ) || function_exists( 'bp_is_active' ) ){
|
20 |
-
if ( defined( 'BP_VERSION' ) )
|
21 |
-
acui_loader();
|
22 |
-
else
|
23 |
-
add_action( 'bp_init', 'acui_loader' );
|
24 |
-
}
|
25 |
-
else
|
26 |
-
acui_loader();
|
27 |
-
|
28 |
-
function acui_loader(){
|
29 |
-
register_activation_hook( __FILE__,'acui_init' );
|
30 |
-
register_deactivation_hook( __FILE__, 'acui_deactivate' );
|
31 |
-
add_action( "plugins_loaded", "acui_init" );
|
32 |
-
add_action( "admin_menu", "acui_menu" );
|
33 |
-
add_action( 'admin_enqueue_scripts', 'acui_admin_enqueue_scripts' );
|
34 |
-
add_filter( 'plugin_row_meta', 'acui_plugin_row_meta', 10, 2 );
|
35 |
-
add_action( 'wp_ajax_acui_delete_attachment', 'acui_delete_attachment' );
|
36 |
-
add_action( 'wp_ajax_acui_bulk_delete_attachment', 'acui_bulk_delete_attachment' );
|
37 |
-
add_filter( 'wp_check_filetype_and_ext', 'acui_wp_check_filetype_and_ext', PHP_INT_MAX, 4 );
|
38 |
-
|
39 |
-
if( is_plugin_active( 'buddypress/bp-loader.php' ) && file_exists( plugin_dir_path( __DIR__ ) . 'buddypress/bp-xprofile/classes/class-bp-xprofile-group.php' ) ){
|
40 |
-
require_once( plugin_dir_path( __DIR__ ) . 'buddypress/bp-xprofile/classes/class-bp-xprofile-group.php' );
|
41 |
}
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
}
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
include_once( $file );
|
53 |
-
}
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
|
61 |
-
foreach ( glob( plugin_dir_path( __FILE__ ) . "addons/*.php" ) as $file ) {
|
62 |
-
include_once( $file );
|
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 |
-
// frontend
|
99 |
-
'acui_frontend_send_mail'=> false,
|
100 |
-
'acui_frontend_send_mail_updated' => false,
|
101 |
-
'acui_frontend_mail_admin' => false,
|
102 |
-
'acui_frontend_delete_users' => false,
|
103 |
-
'acui_frontend_delete_users_assign_posts' => 0,
|
104 |
-
'acui_frontend_change_role_not_present' => false,
|
105 |
-
'acui_frontend_change_role_not_present_role' => 0,
|
106 |
-
'acui_frontend_role' => '',
|
107 |
-
'acui_frontend_update_existing_users' => false,
|
108 |
-
'acui_frontend_update_roles_existing_users' => false,
|
109 |
-
// emials
|
110 |
-
'acui_manually_send_mail' => false,
|
111 |
-
'acui_manually_send_mail_updated' => false,
|
112 |
-
'acui_automatic_wordpress_email' => false,
|
113 |
-
'acui_automatic_created_edited_wordpress_email' => false,
|
114 |
-
// profile fields
|
115 |
-
'acui_show_profile_fields' => false
|
116 |
-
);
|
117 |
-
}
|
118 |
-
|
119 |
-
function acui_activate(){
|
120 |
-
$acui_default_options_list = acui_get_default_options_list();
|
121 |
|
122 |
-
|
123 |
-
add_option( $key, $value, '', false );
|
124 |
}
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
wp_enqueue_style( 'acui_css', plugins_url( 'assets/style.css', __FILE__ ), false, '1.0.0' );
|
133 |
-
}
|
134 |
-
|
135 |
-
function acui_delete_options(){
|
136 |
-
$acui_smtp_options = array (
|
137 |
-
'acui_settings' => 'wordpress',
|
138 |
-
'acui_mailer' => 'smtp',
|
139 |
-
'acui_mail_set_return_path' => 'false',
|
140 |
-
'acui_smtp_host' => 'localhost',
|
141 |
-
'acui_smtp_port' => '25',
|
142 |
-
'acui_smtp_ssl' => 'none',
|
143 |
-
'acui_smtp_auth' => false,
|
144 |
-
'acui_smtp_user' => '',
|
145 |
-
'acui_smtp_pass' => ''
|
146 |
-
);
|
147 |
-
|
148 |
-
$acui_default_options_list = array_merge( acui_get_default_options_list(), $acui_smtp_options );
|
149 |
-
|
150 |
-
foreach ( $acui_default_options_list as $key => $value) {
|
151 |
-
delete_option( $key );
|
152 |
}
|
153 |
-
}
|
154 |
|
155 |
-
function
|
156 |
-
|
157 |
-
}
|
158 |
|
159 |
-
function
|
160 |
-
|
161 |
-
|
162 |
-
$acui_restricted_fields = array_merge( $wp_users_fields, $wp_min_fields );
|
163 |
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
function acui_get_not_meta_fields(){
|
168 |
-
return apply_filters( 'acui_not_meta_fields', array() );
|
169 |
-
}
|
170 |
-
|
171 |
-
function acui_menu() {
|
172 |
-
add_submenu_page( 'tools.php', __( 'Import and export users and customers', 'import-users-from-csv-with-meta' ), __( 'Import and export users and customers', 'import-users-from-csv-with-meta' ), 'create_users', 'acui', 'acui_options' );
|
173 |
-
}
|
174 |
|
175 |
-
function
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
|
|
|
|
|
|
182 |
|
183 |
-
|
184 |
}
|
185 |
-
|
186 |
-
return $links;
|
187 |
-
}
|
188 |
-
|
189 |
-
function acui_detect_delimiter( $file ) {
|
190 |
-
$delimiters = array(
|
191 |
-
';' => 0,
|
192 |
-
',' => 0,
|
193 |
-
"\t" => 0,
|
194 |
-
"|" => 0
|
195 |
-
);
|
196 |
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
return utf8_encode($string);
|
218 |
-
}
|
219 |
-
else
|
220 |
-
return $string;
|
221 |
-
}
|
222 |
-
|
223 |
-
function acui_user_id_exists( $user_id ){
|
224 |
-
if ( get_userdata( $user_id ) === false )
|
225 |
-
return false;
|
226 |
-
else
|
227 |
-
return true;
|
228 |
-
}
|
229 |
-
|
230 |
-
function acui_get_roles( $user_id ){
|
231 |
-
$roles = array();
|
232 |
-
$user = new WP_User( $user_id );
|
233 |
-
|
234 |
-
if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
|
235 |
-
foreach ( $user->roles as $role )
|
236 |
-
$roles[] = $role;
|
237 |
}
|
238 |
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
function acui_get_editable_roles() {
|
243 |
-
global $wp_roles;
|
244 |
-
|
245 |
-
$all_roles = $wp_roles->roles;
|
246 |
-
$editable_roles = apply_filters('editable_roles', $all_roles);
|
247 |
-
$list_editable_roles = array();
|
248 |
-
|
249 |
-
foreach ($editable_roles as $key => $editable_role)
|
250 |
-
$list_editable_roles[$key] = $editable_role["name"];
|
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 |
-
'help' => __( 'Hire an expert', 'import-users-from-csv-with-meta' ),
|
276 |
-
'new_features' => __( 'New features', 'import-users-from-csv-with-meta' )
|
277 |
-
);
|
278 |
-
|
279 |
-
$tabs = apply_filters( 'acui_tabs', $tabs );
|
280 |
-
|
281 |
-
echo '<div id="icon-themes" class="icon32"><br></div>';
|
282 |
-
echo '<h2 class="nav-tab-wrapper">';
|
283 |
-
foreach( $tabs as $tab => $name ){
|
284 |
-
$class = ( $tab == $current ) ? ' nav-tab-active' : '';
|
285 |
-
|
286 |
-
if( $tab == "shop" ){
|
287 |
-
$href = "https://codection.com/tienda/";
|
288 |
-
$target = "_blank";
|
289 |
-
}
|
290 |
-
else{
|
291 |
-
$href = "?page=acui&tab=$tab";
|
292 |
-
$target = "_self";
|
293 |
-
}
|
294 |
-
|
295 |
-
echo "<a class='nav-tab$class' href='$href' target='$target'>$name</a>";
|
296 |
-
|
297 |
-
}
|
298 |
-
echo '</h2>';
|
299 |
-
}
|
300 |
-
|
301 |
-
function acui_fileupload_process( $form_data, $is_cron = false, $is_frontend = false ) {
|
302 |
-
if ( !defined( 'DOING_CRON' ) && ( !isset( $form_data['security'] ) || !wp_verify_nonce( $form_data['security'], 'codection-security' ) ) ){
|
303 |
-
wp_die( __( 'Nonce check failed', 'import-users-from-csv-with-meta' ) );
|
304 |
}
|
305 |
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
acui_import_users( $path_to_file, $form_data, 0, $is_cron, $is_frontend );
|
318 |
-
else:
|
319 |
-
$uploadfile = wp_handle_upload( $_FILES['uploadfile'], array( 'test_form' => false, 'mimes' => array('csv' => 'text/csv') ) );
|
320 |
-
|
321 |
-
if ( !$uploadfile || isset( $uploadfile['error'] ) ) {
|
322 |
-
wp_die( __( 'Problem uploading file to import. Error details: ' . var_export( $uploadfile['error'], true ), 'import-users-from-csv-with-meta' ));
|
323 |
} else {
|
324 |
-
|
|
|
|
|
|
|
|
|
325 |
}
|
326 |
-
|
327 |
-
}
|
328 |
-
|
329 |
-
function acui_manage_extra_profile_fields( $form_data ){
|
330 |
-
if ( !isset( $form_data['security'] ) || !wp_verify_nonce( $form_data['security'], 'codection-security' ) ) {
|
331 |
-
wp_die( __( 'Nonce check failed', 'import-users-from-csv-with-meta' ) );
|
332 |
-
}
|
333 |
-
|
334 |
-
if( isset( $form_data['show-profile-fields-action'] ) && $form_data['show-profile-fields-action'] == 'update' )
|
335 |
-
update_option( "acui_show_profile_fields", isset( $form_data["show-profile-fields"] ) && $form_data["show-profile-fields"] == "yes" );
|
336 |
-
|
337 |
-
if( isset( $form_data['reset-profile-fields-action'] ) && $form_data['reset-profile-fields-action'] == 'reset' )
|
338 |
-
update_option( "acui_columns", array() );
|
339 |
-
}
|
340 |
-
|
341 |
-
function acui_save_mail_template( $form_data ){
|
342 |
-
if ( !isset( $form_data['security'] ) || !wp_verify_nonce( $form_data['security'], 'codection-security' ) ) {
|
343 |
-
wp_die( __( 'Nonce check failed', 'import-users-from-csv-with-meta' ) );
|
344 |
-
}
|
345 |
-
|
346 |
-
$automatic_wordpress_email = sanitize_text_field( $form_data["automatic_wordpress_email"] );
|
347 |
-
$automatic_created_edited_wordpress_email = sanitize_text_field( $form_data["automatic_created_edited_wordpress_email"] );
|
348 |
-
$subject_mail = sanitize_text_field( stripslashes_deep( $form_data["subject_mail"] ) );
|
349 |
-
$body_mail = wp_kses_post( stripslashes( $form_data["body_mail"] ) );
|
350 |
-
$template_id = intval( $form_data["template_id"] );
|
351 |
-
$email_template_attachment_id = intval( $form_data["email_template_attachment_id"] );
|
352 |
-
|
353 |
-
update_option( "acui_automatic_wordpress_email", $automatic_wordpress_email );
|
354 |
-
update_option( "acui_automatic_created_edited_wordpress_email", $automatic_created_edited_wordpress_email );
|
355 |
-
update_option( "acui_mail_subject", $subject_mail );
|
356 |
-
update_option( "acui_mail_body", $body_mail );
|
357 |
-
update_option( "acui_mail_template_id", $template_id );
|
358 |
-
update_option( "acui_mail_attachment_id", $email_template_attachment_id );
|
359 |
-
|
360 |
-
$template_id = absint( $form_data["template_id"] );
|
361 |
-
|
362 |
-
if( !empty( $template_id ) ){
|
363 |
-
wp_update_post( array(
|
364 |
-
'ID' => $template_id,
|
365 |
-
'post_title' => $subject_mail,
|
366 |
-
'post_content' => $body_mail,
|
367 |
-
) );
|
368 |
-
|
369 |
-
update_post_meta( $template_id, 'email_template_attachment_id', $email_template_attachment_id );
|
370 |
}
|
371 |
-
?>
|
372 |
-
<div class="updated">
|
373 |
-
<p><?php _e( 'Mail template and options updated correctly', 'import-users-from-csv-with-meta' )?></p>
|
374 |
-
</div>
|
375 |
-
<?php
|
376 |
-
}
|
377 |
-
|
378 |
-
function acui_extra_user_profile_fields( $user ) {
|
379 |
-
$acui_restricted_fields = acui_get_restricted_fields();
|
380 |
-
$headers = get_option("acui_columns");
|
381 |
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
|
386 |
-
|
387 |
-
foreach ( $headers as $column ):
|
388 |
-
if( in_array( $column, $acui_restricted_fields ) )
|
389 |
-
continue;
|
390 |
-
?>
|
391 |
-
<tr>
|
392 |
-
<th><label for="<?php echo $column; ?>"><?php echo $column; ?></label></th>
|
393 |
-
<td><input type="text" name="<?php echo $column; ?>" id="<?php echo $column; ?>" value="<?php echo esc_attr(get_the_author_meta($column, $user->ID )); ?>" class="regular-text" /></td>
|
394 |
-
</tr>
|
395 |
-
<?php
|
396 |
-
endforeach;
|
397 |
?>
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
function acui_save_extra_user_profile_fields( $user_id ){
|
403 |
-
$headers = get_option("acui_columns");
|
404 |
-
$acui_restricted_fields = acui_get_restricted_fields();
|
405 |
-
|
406 |
-
$post_filtered = filter_input_array( INPUT_POST );
|
407 |
-
|
408 |
-
if( is_array( $headers ) && count( $headers ) > 0 ):
|
409 |
-
foreach ( $headers as $column ){
|
410 |
if( in_array( $column, $acui_restricted_fields ) )
|
411 |
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
412 |
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
endif;
|
417 |
-
}
|
418 |
-
|
419 |
-
function acui_delete_attachment() {
|
420 |
-
check_ajax_referer( 'codection-security', 'security' );
|
421 |
-
|
422 |
-
if( ! current_user_can( 'manage_options' ) )
|
423 |
-
wp_die( __('You are not an adminstrator', 'import-users-from-csv-with-meta' ) );
|
424 |
-
|
425 |
-
$attach_id = absint( $_POST['attach_id'] );
|
426 |
-
$mime_type = (string) get_post_mime_type( $attach_id );
|
427 |
-
|
428 |
-
if( $mime_type != 'text/csv' )
|
429 |
-
_e('This plugin only can delete the type of file it manages, CSV files.', 'import-users-from-csv-with-meta' );
|
430 |
-
|
431 |
-
$result = wp_delete_attachment( $attach_id, true );
|
432 |
-
|
433 |
-
if( $result === false )
|
434 |
-
_e( 'There were problems deleting the file, please check file permissions', 'import-users-from-csv-with-meta' );
|
435 |
-
else
|
436 |
-
echo 1;
|
437 |
-
|
438 |
-
wp_die();
|
439 |
-
}
|
440 |
-
|
441 |
-
function acui_bulk_delete_attachment(){
|
442 |
-
check_ajax_referer( 'codection-security', 'security' );
|
443 |
-
|
444 |
-
if( ! current_user_can( 'manage_options' ) )
|
445 |
-
wp_die( __('You are not an adminstrator', 'import-users-from-csv-with-meta' ) );
|
446 |
-
|
447 |
-
$args_old_csv = array( 'post_type'=> 'attachment', 'post_mime_type' => 'text/csv', 'post_status' => 'inherit', 'posts_per_page' => -1 );
|
448 |
-
$old_csv_files = new WP_Query( $args_old_csv );
|
449 |
-
$result = 1;
|
450 |
-
|
451 |
-
while($old_csv_files->have_posts()) :
|
452 |
-
$old_csv_files->the_post();
|
453 |
-
|
454 |
-
$mime_type = (string) get_post_mime_type( get_the_ID() );
|
455 |
-
if( $mime_type != 'text/csv' )
|
456 |
-
wp_die( __('This plugin only can delete the type of file it manages, CSV files.', 'import-users-from-csv-with-meta' ) );
|
457 |
-
|
458 |
-
if( wp_delete_attachment( get_the_ID(), true ) === false )
|
459 |
-
$result = 0;
|
460 |
-
endwhile;
|
461 |
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
// text/csv by trusting the file extension.
|
474 |
-
$finfo = finfo_open( FILEINFO_MIME_TYPE );
|
475 |
-
$real_mime = finfo_file( $finfo, $file );
|
476 |
-
finfo_close( $finfo );
|
477 |
-
if ( $real_mime === 'text/plain' && preg_match( '/\.(csv)$/i', $filename ) ) {
|
478 |
-
$values['ext'] = 'csv';
|
479 |
-
$values['type'] = 'text/csv';
|
480 |
-
}
|
481 |
-
} else {
|
482 |
-
// without the php-extension, we probably don't have the issue at all, but just to be sure...
|
483 |
-
if ( preg_match( '/\.(csv)$/i', $filename ) ) {
|
484 |
-
$values['ext'] = 'csv';
|
485 |
-
$values['type'] = 'text/csv';
|
486 |
-
}
|
487 |
}
|
488 |
-
|
489 |
}
|
490 |
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
$is_change = ($add && ! $has_cap) || (!$add && $has_cap);
|
495 |
-
if ( $is_change ) {
|
496 |
-
if ( $add ) {
|
497 |
-
$user->add_cap( $capability , true );
|
498 |
-
do_action( 'wpaa_grant_access' , $user , $capability );
|
499 |
-
do_action( "wpaa_grant_{$capability}" , $user );
|
500 |
-
} else if ( ! $add ) {
|
501 |
-
$user->remove_cap( $capability );
|
502 |
-
do_action( 'wpaa_revoke_access' , $user , $capability );
|
503 |
-
do_action( "wpaa_revoke_{$capability}" , $user );
|
504 |
-
}
|
505 |
-
}
|
506 |
}
|
|
|
507 |
|
508 |
-
|
509 |
-
|
510 |
-
$wp_upload_dir = wp_upload_dir();
|
511 |
-
// Strip out protocols, so it doesn't fail because searching for http: in https: dir.
|
512 |
-
$dir = set_url_scheme( trailingslashit( $wp_upload_dir['baseurl'] ), 'relative' );
|
513 |
-
|
514 |
-
// Is URL in uploads directory?
|
515 |
-
if ( false !== strpos( $url, $dir ) ) {
|
516 |
-
|
517 |
-
$file = basename( $url );
|
518 |
-
|
519 |
-
$query_args = array(
|
520 |
-
'post_type' => 'attachment',
|
521 |
-
'post_status' => 'inherit',
|
522 |
-
'fields' => 'ids',
|
523 |
-
'meta_query' => array(
|
524 |
-
array(
|
525 |
-
'key' => '_wp_attachment_metadata',
|
526 |
-
'compare' => 'LIKE',
|
527 |
-
'value' => $file,
|
528 |
-
),
|
529 |
-
),
|
530 |
-
);
|
531 |
-
|
532 |
-
$query = new WP_Query( $query_args );
|
533 |
-
|
534 |
-
if ( $query->have_posts() ) {
|
535 |
-
foreach ( $query->posts as $attachment_id ) {
|
536 |
-
$meta = wp_get_attachment_metadata( $attachment_id );
|
537 |
-
$original_file = basename( $meta['file'] );
|
538 |
-
$cropped_files = wp_list_pluck( $meta['sizes'], 'file' );
|
539 |
-
|
540 |
-
if ( $original_file === $file || in_array( $file, $cropped_files ) ) {
|
541 |
-
return (int) $attachment_id;
|
542 |
-
}
|
543 |
-
}
|
544 |
-
}
|
545 |
-
}
|
546 |
-
|
547 |
-
return false;
|
548 |
-
}
|
3 |
Plugin Name: Import and export users and customers
|
4 |
Plugin URI: https://www.codection.com
|
5 |
Description: Using this plugin you will be able to import and export users or customers choosing many options and interacting with lots of other plugins
|
6 |
+
Version: 1.16
|
7 |
Author: codection
|
8 |
Author URI: https://codection.com
|
9 |
License: GPL2
|
14 |
if ( ! defined( 'ABSPATH' ) )
|
15 |
exit;
|
16 |
|
17 |
+
class ImportExportUsersCustomers{
|
18 |
+
function __construct(){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
}
|
20 |
|
21 |
+
public static function get_default_options_list(){
|
22 |
+
return array(
|
23 |
+
'acui_columns' => array(),
|
24 |
+
// emails
|
25 |
+
'acui_mail_subject' => __('Welcome to', 'import-users-from-csv-with-meta') . ' ' . get_bloginfo("name"),
|
26 |
+
'acui_mail_body' => __('Welcome,', 'import-users-from-csv-with-meta') . '<br/>' . __('Your data to login in this site is:', 'import-users-from-csv-with-meta') . '<br/><ul><li>' . __('URL to login', 'import-users-from-csv-with-meta') . ': **loginurl**</li><li>' . __( 'Username', 'import-users-from-csv-with-meta') . '= **username**</li><li>Password = **password**</li></ul>',
|
27 |
+
'acui_mail_template_id' => 0,
|
28 |
+
'acui_mail_attachment_id' => 0,
|
29 |
+
'acui_enable_email_templates' => false,
|
30 |
+
// cron
|
31 |
+
'acui_cron_activated' => false,
|
32 |
+
'acui_cron_send_mail' => false,
|
33 |
+
'acui_cron_send_mail_updated' => false,
|
34 |
+
'acui_cron_delete_users' => false,
|
35 |
+
'acui_cron_delete_users_assign_posts' => 0,
|
36 |
+
'acui_cron_change_role_not_present' => false,
|
37 |
+
'acui_cron_change_role_not_present_role' => 0,
|
38 |
+
'acui_cron_path_to_file' => '',
|
39 |
+
'acui_cron_path_to_move' => '',
|
40 |
+
'acui_cron_path_to_move_auto_rename' => false,
|
41 |
+
'acui_cron_period' => '',
|
42 |
+
'acui_cron_role' => '',
|
43 |
+
'acui_cron_update_roles_existing_users' => '',
|
44 |
+
'acui_cron_log' => '',
|
45 |
+
'acui_cron_allow_multiple_accounts' => 'not_allowed',
|
46 |
+
// frontend
|
47 |
+
'acui_frontend_send_mail'=> false,
|
48 |
+
'acui_frontend_send_mail_updated' => false,
|
49 |
+
'acui_frontend_mail_admin' => false,
|
50 |
+
'acui_frontend_delete_users' => false,
|
51 |
+
'acui_frontend_delete_users_assign_posts' => 0,
|
52 |
+
'acui_frontend_change_role_not_present' => false,
|
53 |
+
'acui_frontend_change_role_not_present_role' => 0,
|
54 |
+
'acui_frontend_role' => '',
|
55 |
+
'acui_frontend_update_existing_users' => false,
|
56 |
+
'acui_frontend_update_roles_existing_users' => false,
|
57 |
+
// emials
|
58 |
+
'acui_manually_send_mail' => false,
|
59 |
+
'acui_manually_send_mail_updated' => false,
|
60 |
+
'acui_automatic_wordpress_email' => false,
|
61 |
+
'acui_automatic_created_edited_wordpress_email' => false,
|
62 |
+
// profile fields
|
63 |
+
'acui_show_profile_fields' => false
|
64 |
+
);
|
65 |
}
|
66 |
|
67 |
+
public function on_loaded(){
|
68 |
+
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
|
|
|
|
69 |
|
70 |
+
if( is_plugin_active( 'buddypress/bp-loader.php' ) || function_exists( 'bp_is_active' ) ){
|
71 |
+
if ( defined( 'BP_VERSION' ) )
|
72 |
+
$this->loader();
|
73 |
+
else
|
74 |
+
add_action( 'bp_init', array( $this, 'loader' ) );
|
75 |
+
}
|
76 |
+
else{
|
77 |
+
$this->loader();
|
78 |
+
}
|
79 |
|
80 |
+
load_plugin_textdomain( 'import-users-from-csv-with-meta', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
|
|
|
|
|
81 |
}
|
82 |
|
83 |
+
public function loader(){
|
84 |
+
add_action( "admin_menu", array( $this, 'menu' ) );
|
85 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
86 |
+
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
|
87 |
+
add_action( 'wp_ajax_acui_delete_attachment', array( $this, 'delete_attachment' ) );
|
88 |
+
add_action( 'wp_ajax_acui_bulk_delete_attachment', array( $this, 'bulk_delete_attachment' ) );
|
89 |
+
add_filter( 'wp_check_filetype_and_ext', array( $this, 'wp_check_filetype_and_ext' ), PHP_INT_MAX, 4 );
|
90 |
+
|
91 |
+
if( is_plugin_active( 'buddypress/bp-loader.php' ) && file_exists( plugin_dir_path( __DIR__ ) . 'buddypress/bp-xprofile/classes/class-bp-xprofile-group.php' ) ){
|
92 |
+
require_once( plugin_dir_path( __DIR__ ) . 'buddypress/bp-xprofile/classes/class-bp-xprofile-group.php' );
|
93 |
+
}
|
94 |
+
|
95 |
+
if( get_option( 'acui_show_profile_fields' ) == true ){
|
96 |
+
add_action( "show_user_profile", array( $this, "extra_user_profile_fields" ) );
|
97 |
+
add_action( "edit_user_profile", array( $this, "extra_user_profile_fields" ) );
|
98 |
+
add_action( "personal_options_update", array( $this, "save_extra_user_profile_fields" ) );
|
99 |
+
add_action( "edit_user_profile_update", array( $this, "save_extra_user_profile_fields" ) );
|
100 |
+
}
|
101 |
+
|
102 |
+
// classes
|
103 |
+
foreach ( glob( plugin_dir_path( __FILE__ ) . "classes/*.php" ) as $file ) {
|
104 |
+
include_once( $file );
|
105 |
+
}
|
106 |
+
|
107 |
+
// includes
|
108 |
+
foreach ( glob( plugin_dir_path( __FILE__ ) . "include/*.php" ) as $file ) {
|
109 |
+
include_once( $file );
|
110 |
+
}
|
111 |
+
|
112 |
+
// addons
|
113 |
+
foreach ( glob( plugin_dir_path( __FILE__ ) . "addons/*.php" ) as $file ) {
|
114 |
+
include_once( $file );
|
115 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
+
require_once( "importer.php" );
|
|
|
118 |
}
|
119 |
+
|
120 |
+
public static function activate(){
|
121 |
+
$acui_default_options_list = self::get_default_options_list();
|
122 |
+
|
123 |
+
foreach ( $acui_default_options_list as $key => $value) {
|
124 |
+
add_option( $key, $value, '', false );
|
125 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
}
|
|
|
127 |
|
128 |
+
public static function deactivate(){
|
129 |
+
wp_clear_scheduled_hook( 'acui_cron' );
|
130 |
+
}
|
131 |
|
132 |
+
function menu() {
|
133 |
+
add_submenu_page( 'tools.php', __( 'Import and export users and customers', 'import-users-from-csv-with-meta' ), __( 'Import and export users and customers', 'import-users-from-csv-with-meta' ), apply_filters( 'acui_capability', 'create_users' ), 'acui', 'acui_options' );
|
134 |
+
}
|
|
|
135 |
|
136 |
+
function admin_enqueue_scripts() {
|
137 |
+
wp_enqueue_style( 'acui_css', plugins_url( 'assets/style.css', __FILE__ ), false, '1.0.0' );
|
138 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
|
140 |
+
function plugin_row_meta( $links, $file ){
|
141 |
+
if ( strpos( $file, basename( __FILE__ ) ) !== false ) {
|
142 |
+
$new_links = array(
|
143 |
+
'<a href="https://www.paypal.me/imalrod" target="_blank">' . __( 'Donate', 'import-users-from-csv-with-meta' ) . '</a>',
|
144 |
+
'<a href="mailto:contacto@codection.com" target="_blank">' . __( 'Premium support', 'import-users-from-csv-with-meta' ) . '</a>',
|
145 |
+
'<a href="http://codection.com/tienda" target="_blank">' . __( 'Premium plugins', 'import-users-from-csv-with-meta' ) . '</a>',
|
146 |
+
);
|
147 |
+
|
148 |
+
$links = array_merge( $links, $new_links );
|
149 |
+
}
|
150 |
|
151 |
+
return $links;
|
152 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
+
function delete_attachment() {
|
155 |
+
check_ajax_referer( 'codection-security', 'security' );
|
156 |
+
|
157 |
+
if( ! current_user_can( 'manage_options' ) )
|
158 |
+
wp_die( __('You are not an adminstrator', 'import-users-from-csv-with-meta' ) );
|
159 |
+
|
160 |
+
$attach_id = absint( $_POST['attach_id'] );
|
161 |
+
$mime_type = (string) get_post_mime_type( $attach_id );
|
162 |
+
|
163 |
+
if( $mime_type != 'text/csv' )
|
164 |
+
_e('This plugin only can delete the type of file it manages, CSV files.', 'import-users-from-csv-with-meta' );
|
165 |
+
|
166 |
+
$result = wp_delete_attachment( $attach_id, true );
|
167 |
+
|
168 |
+
if( $result === false )
|
169 |
+
_e( 'There were problems deleting the file, please check file permissions', 'import-users-from-csv-with-meta' );
|
170 |
+
else
|
171 |
+
echo 1;
|
172 |
+
|
173 |
+
wp_die();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
}
|
175 |
|
176 |
+
function bulk_delete_attachment(){
|
177 |
+
check_ajax_referer( 'codection-security', 'security' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
+
if( ! current_user_can( 'manage_options' ) )
|
180 |
+
wp_die( __('You are not an adminstrator', 'import-users-from-csv-with-meta' ) );
|
181 |
+
|
182 |
+
$args_old_csv = array( 'post_type'=> 'attachment', 'post_mime_type' => 'text/csv', 'post_status' => 'inherit', 'posts_per_page' => -1 );
|
183 |
+
$old_csv_files = new WP_Query( $args_old_csv );
|
184 |
+
$result = 1;
|
185 |
+
|
186 |
+
while($old_csv_files->have_posts()) :
|
187 |
+
$old_csv_files->the_post();
|
188 |
+
|
189 |
+
$mime_type = (string) get_post_mime_type( get_the_ID() );
|
190 |
+
if( $mime_type != 'text/csv' )
|
191 |
+
wp_die( __('This plugin only can delete the type of file it manages, CSV files.', 'import-users-from-csv-with-meta' ) );
|
192 |
+
|
193 |
+
if( wp_delete_attachment( get_the_ID(), true ) === false )
|
194 |
+
$result = 0;
|
195 |
+
endwhile;
|
196 |
+
|
197 |
+
wp_reset_postdata();
|
198 |
+
|
199 |
+
echo $result;
|
200 |
+
|
201 |
+
wp_die();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
}
|
203 |
|
204 |
+
function wp_check_filetype_and_ext( $values, $file, $filename, $mimes ) {
|
205 |
+
if ( extension_loaded( 'fileinfo' ) ) {
|
206 |
+
// with the php-extension, a CSV file is issues type text/plain so we fix that back to
|
207 |
+
// text/csv by trusting the file extension.
|
208 |
+
$finfo = finfo_open( FILEINFO_MIME_TYPE );
|
209 |
+
$real_mime = finfo_file( $finfo, $file );
|
210 |
+
finfo_close( $finfo );
|
211 |
+
if ( $real_mime === 'text/plain' && preg_match( '/\.(csv)$/i', $filename ) ) {
|
212 |
+
$values['ext'] = 'csv';
|
213 |
+
$values['type'] = 'text/csv';
|
214 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
} else {
|
216 |
+
// without the php-extension, we probably don't have the issue at all, but just to be sure...
|
217 |
+
if ( preg_match( '/\.(csv)$/i', $filename ) ) {
|
218 |
+
$values['ext'] = 'csv';
|
219 |
+
$values['type'] = 'text/csv';
|
220 |
+
}
|
221 |
}
|
222 |
+
return $values;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
|
225 |
+
function extra_user_profile_fields( $user ) {
|
226 |
+
$acui_restricted_fields = acui_get_restricted_fields();
|
227 |
+
$headers = get_option("acui_columns");
|
228 |
|
229 |
+
if( is_array( $headers ) && !empty( $headers ) ):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
?>
|
231 |
+
<h3>Extra profile information</h3>
|
232 |
+
|
233 |
+
<table class="form-table"><?php
|
234 |
+
foreach ( $headers as $column ):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
if( in_array( $column, $acui_restricted_fields ) )
|
236 |
continue;
|
237 |
+
?>
|
238 |
+
<tr>
|
239 |
+
<th><label for="<?php echo $column; ?>"><?php echo $column; ?></label></th>
|
240 |
+
<td><input type="text" name="<?php echo $column; ?>" id="<?php echo $column; ?>" value="<?php echo esc_attr(get_the_author_meta($column, $user->ID )); ?>" class="regular-text" /></td>
|
241 |
+
</tr>
|
242 |
+
<?php
|
243 |
+
endforeach;
|
244 |
+
?>
|
245 |
+
</table><?php
|
246 |
+
endif;
|
247 |
+
}
|
248 |
|
249 |
+
function save_extra_user_profile_fields( $user_id ){
|
250 |
+
$headers = get_option("acui_columns");
|
251 |
+
$acui_restricted_fields = acui_get_restricted_fields();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
|
253 |
+
$post_filtered = filter_input_array( INPUT_POST );
|
254 |
+
|
255 |
+
if( is_array( $headers ) && count( $headers ) > 0 ):
|
256 |
+
foreach ( $headers as $column ){
|
257 |
+
if( in_array( $column, $acui_restricted_fields ) )
|
258 |
+
continue;
|
259 |
+
|
260 |
+
$column_sanitized = str_replace(" ", "_", $column);
|
261 |
+
update_user_meta( $user_id, $column, $post_filtered[$column_sanitized] );
|
262 |
+
}
|
263 |
+
endif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
}
|
265 |
+
|
266 |
}
|
267 |
|
268 |
+
function acui_start(){
|
269 |
+
$import_export_users_customers = new ImportExportUsersCustomers();
|
270 |
+
add_action( 'wp_loaded', array( $import_export_users_customers, 'on_loaded' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
}
|
272 |
+
add_action( 'plugins_loaded', 'acui_start', 8);
|
273 |
|
274 |
+
register_activation_hook( __FILE__, array( 'ImportExportUsersCustomers', 'activate' ) );
|
275 |
+
register_deactivation_hook( __FILE__, array( 'ImportExportUsersCustomers', 'deactivate' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
importer.php
CHANGED
@@ -773,7 +773,7 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
|
|
773 |
}
|
774 |
|
775 |
function acui_options(){
|
776 |
-
if ( !current_user_can( 'create_users' ) ) {
|
777 |
wp_die( __( 'You are not allowed to see this content.', 'import-users-from-csv-with-meta' ));
|
778 |
}
|
779 |
|
@@ -866,4 +866,260 @@ function acui_options(){
|
|
866 |
do_action( 'acui_tab_action_' . $tab );
|
867 |
break;
|
868 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
869 |
}
|
773 |
}
|
774 |
|
775 |
function acui_options(){
|
776 |
+
if ( !current_user_can( apply_filters( 'acui_capability', 'create_users' ) ) ) {
|
777 |
wp_die( __( 'You are not allowed to see this content.', 'import-users-from-csv-with-meta' ));
|
778 |
}
|
779 |
|
866 |
do_action( 'acui_tab_action_' . $tab );
|
867 |
break;
|
868 |
}
|
869 |
+
}
|
870 |
+
|
871 |
+
function acui_get_wp_users_fields(){
|
872 |
+
return array( "id", "user_email", "user_nicename", "user_url", "display_name", "nickname", "first_name", "last_name", "description", "jabber", "aim", "yim", "user_registered", "password", "user_pass", "locale", "show_admin_bar_front", "user_login" );
|
873 |
+
}
|
874 |
+
|
875 |
+
function acui_get_restricted_fields(){
|
876 |
+
$wp_users_fields = acui_get_wp_users_fields();
|
877 |
+
$wp_min_fields = array( "Username", "Email", "bp_group", "bp_group_role", "role" );
|
878 |
+
$acui_restricted_fields = array_merge( $wp_users_fields, $wp_min_fields );
|
879 |
+
|
880 |
+
return apply_filters( 'acui_restricted_fields', $acui_restricted_fields );
|
881 |
+
}
|
882 |
+
|
883 |
+
function acui_get_not_meta_fields(){
|
884 |
+
return apply_filters( 'acui_not_meta_fields', array() );
|
885 |
+
}
|
886 |
+
|
887 |
+
function acui_detect_delimiter( $file ) {
|
888 |
+
$delimiters = array(
|
889 |
+
';' => 0,
|
890 |
+
',' => 0,
|
891 |
+
"\t" => 0,
|
892 |
+
"|" => 0
|
893 |
+
);
|
894 |
+
|
895 |
+
$handle = @fopen($file, "r");
|
896 |
+
$firstLine = fgets($handle);
|
897 |
+
fclose($handle);
|
898 |
+
foreach ($delimiters as $delimiter => &$count) {
|
899 |
+
$count = count(str_getcsv($firstLine, $delimiter));
|
900 |
+
}
|
901 |
+
|
902 |
+
return array_search(max($delimiters), $delimiters);
|
903 |
+
}
|
904 |
+
|
905 |
+
function acui_string_conversion( $string ){
|
906 |
+
if(!preg_match('%(?:
|
907 |
+
[\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
|
908 |
+
|\xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
|
909 |
+
|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
|
910 |
+
|\xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
|
911 |
+
|\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
|
912 |
+
|[\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
|
913 |
+
|\xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
|
914 |
+
)+%xs', $string)){
|
915 |
+
return utf8_encode($string);
|
916 |
+
}
|
917 |
+
else
|
918 |
+
return $string;
|
919 |
+
}
|
920 |
+
|
921 |
+
function acui_user_id_exists( $user_id ){
|
922 |
+
if ( get_userdata( $user_id ) === false )
|
923 |
+
return false;
|
924 |
+
else
|
925 |
+
return true;
|
926 |
+
}
|
927 |
+
|
928 |
+
function acui_get_roles( $user_id ){
|
929 |
+
$roles = array();
|
930 |
+
$user = new WP_User( $user_id );
|
931 |
+
|
932 |
+
if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
|
933 |
+
foreach ( $user->roles as $role )
|
934 |
+
$roles[] = $role;
|
935 |
+
}
|
936 |
+
|
937 |
+
return $roles;
|
938 |
+
}
|
939 |
+
|
940 |
+
function acui_get_editable_roles() {
|
941 |
+
global $wp_roles;
|
942 |
+
|
943 |
+
$all_roles = $wp_roles->roles;
|
944 |
+
$editable_roles = apply_filters('editable_roles', $all_roles);
|
945 |
+
$list_editable_roles = array();
|
946 |
+
|
947 |
+
foreach ($editable_roles as $key => $editable_role)
|
948 |
+
$list_editable_roles[$key] = $editable_role["name"];
|
949 |
+
|
950 |
+
return $list_editable_roles;
|
951 |
+
}
|
952 |
+
|
953 |
+
function acui_admin_tabs( $current = 'homepage' ) {
|
954 |
+
$tabs = array(
|
955 |
+
'homepage' => __( 'Import', 'import-users-from-csv-with-meta' ),
|
956 |
+
'export' => __( 'Export', 'import-users-from-csv-with-meta' ),
|
957 |
+
'frontend' => __( 'Frontend', 'import-users-from-csv-with-meta' ),
|
958 |
+
'cron' => __( 'Cron import', 'import-users-from-csv-with-meta' ),
|
959 |
+
'columns' => __( 'Extra profile fields', 'import-users-from-csv-with-meta' ),
|
960 |
+
'meta-keys' => __( 'Meta keys', 'import-users-from-csv-with-meta' ),
|
961 |
+
'mail-options' => __( 'Mail options', 'import-users-from-csv-with-meta' ),
|
962 |
+
'doc' => __( 'Documentation', 'import-users-from-csv-with-meta' ),
|
963 |
+
'donate' => __( 'Donate/Patreon', 'import-users-from-csv-with-meta' ),
|
964 |
+
'shop' => __( 'Shop', 'import-users-from-csv-with-meta' ),
|
965 |
+
'help' => __( 'Hire an expert', 'import-users-from-csv-with-meta' ),
|
966 |
+
'new_features' => __( 'New features', 'import-users-from-csv-with-meta' )
|
967 |
+
);
|
968 |
+
|
969 |
+
$tabs = apply_filters( 'acui_tabs', $tabs );
|
970 |
+
|
971 |
+
echo '<div id="icon-themes" class="icon32"><br></div>';
|
972 |
+
echo '<h2 class="nav-tab-wrapper">';
|
973 |
+
foreach( $tabs as $tab => $name ){
|
974 |
+
$class = ( $tab == $current ) ? ' nav-tab-active' : '';
|
975 |
+
|
976 |
+
if( $tab == "shop" ){
|
977 |
+
$href = "https://codection.com/tienda/";
|
978 |
+
$target = "_blank";
|
979 |
+
}
|
980 |
+
else{
|
981 |
+
$href = "?page=acui&tab=$tab";
|
982 |
+
$target = "_self";
|
983 |
+
}
|
984 |
+
|
985 |
+
echo "<a class='nav-tab$class' href='$href' target='$target'>$name</a>";
|
986 |
+
|
987 |
+
}
|
988 |
+
echo '</h2>';
|
989 |
+
}
|
990 |
+
|
991 |
+
function acui_fileupload_process( $form_data, $is_cron = false, $is_frontend = false ) {
|
992 |
+
if ( !defined( 'DOING_CRON' ) && ( !isset( $form_data['security'] ) || !wp_verify_nonce( $form_data['security'], 'codection-security' ) ) ){
|
993 |
+
wp_die( __( 'Nonce check failed', 'import-users-from-csv-with-meta' ) );
|
994 |
+
}
|
995 |
+
|
996 |
+
if( empty( $_FILES['uploadfile']['name'] ) || $is_frontend ):
|
997 |
+
$path_to_file = wp_normalize_path( $form_data["path_to_file"] );
|
998 |
+
|
999 |
+
if( validate_file( $path_to_file ) !== 0 ){
|
1000 |
+
wp_die( __( 'Error, path to file is not well written', 'import-users-from-csv-with-meta' ) . ": $path_to_file" );
|
1001 |
+
}
|
1002 |
+
|
1003 |
+
if( !file_exists ( $path_to_file ) ){
|
1004 |
+
wp_die( __( 'Error, we cannot find the file', 'import-users-from-csv-with-meta' ) . ": $path_to_file" );
|
1005 |
+
}
|
1006 |
+
|
1007 |
+
acui_import_users( $path_to_file, $form_data, 0, $is_cron, $is_frontend );
|
1008 |
+
else:
|
1009 |
+
$uploadfile = wp_handle_upload( $_FILES['uploadfile'], array( 'test_form' => false, 'mimes' => array('csv' => 'text/csv') ) );
|
1010 |
+
|
1011 |
+
if ( !$uploadfile || isset( $uploadfile['error'] ) ) {
|
1012 |
+
wp_die( __( 'Problem uploading file to import. Error details: ' . var_export( $uploadfile['error'], true ), 'import-users-from-csv-with-meta' ));
|
1013 |
+
} else {
|
1014 |
+
acui_import_users( $uploadfile['file'], $form_data, acui_get_attachment_id_by_url( $uploadfile['url'] ), $is_cron, $is_frontend );
|
1015 |
+
}
|
1016 |
+
endif;
|
1017 |
+
}
|
1018 |
+
|
1019 |
+
function acui_manage_extra_profile_fields( $form_data ){
|
1020 |
+
if ( !isset( $form_data['security'] ) || !wp_verify_nonce( $form_data['security'], 'codection-security' ) ) {
|
1021 |
+
wp_die( __( 'Nonce check failed', 'import-users-from-csv-with-meta' ) );
|
1022 |
+
}
|
1023 |
+
|
1024 |
+
if( isset( $form_data['show-profile-fields-action'] ) && $form_data['show-profile-fields-action'] == 'update' )
|
1025 |
+
update_option( "acui_show_profile_fields", isset( $form_data["show-profile-fields"] ) && $form_data["show-profile-fields"] == "yes" );
|
1026 |
+
|
1027 |
+
if( isset( $form_data['reset-profile-fields-action'] ) && $form_data['reset-profile-fields-action'] == 'reset' )
|
1028 |
+
update_option( "acui_columns", array() );
|
1029 |
+
}
|
1030 |
+
|
1031 |
+
function acui_save_mail_template( $form_data ){
|
1032 |
+
if ( !isset( $form_data['security'] ) || !wp_verify_nonce( $form_data['security'], 'codection-security' ) ) {
|
1033 |
+
wp_die( __( 'Nonce check failed', 'import-users-from-csv-with-meta' ) );
|
1034 |
+
}
|
1035 |
+
|
1036 |
+
$automatic_wordpress_email = sanitize_text_field( $form_data["automatic_wordpress_email"] );
|
1037 |
+
$automatic_created_edited_wordpress_email = sanitize_text_field( $form_data["automatic_created_edited_wordpress_email"] );
|
1038 |
+
$subject_mail = sanitize_text_field( stripslashes_deep( $form_data["subject_mail"] ) );
|
1039 |
+
$body_mail = wp_kses_post( stripslashes( $form_data["body_mail"] ) );
|
1040 |
+
$template_id = intval( $form_data["template_id"] );
|
1041 |
+
$email_template_attachment_id = intval( $form_data["email_template_attachment_id"] );
|
1042 |
+
|
1043 |
+
update_option( "acui_automatic_wordpress_email", $automatic_wordpress_email );
|
1044 |
+
update_option( "acui_automatic_created_edited_wordpress_email", $automatic_created_edited_wordpress_email );
|
1045 |
+
update_option( "acui_mail_subject", $subject_mail );
|
1046 |
+
update_option( "acui_mail_body", $body_mail );
|
1047 |
+
update_option( "acui_mail_template_id", $template_id );
|
1048 |
+
update_option( "acui_mail_attachment_id", $email_template_attachment_id );
|
1049 |
+
|
1050 |
+
$template_id = absint( $form_data["template_id"] );
|
1051 |
+
|
1052 |
+
if( !empty( $template_id ) ){
|
1053 |
+
wp_update_post( array(
|
1054 |
+
'ID' => $template_id,
|
1055 |
+
'post_title' => $subject_mail,
|
1056 |
+
'post_content' => $body_mail,
|
1057 |
+
) );
|
1058 |
+
|
1059 |
+
update_post_meta( $template_id, 'email_template_attachment_id', $email_template_attachment_id );
|
1060 |
+
}
|
1061 |
+
?>
|
1062 |
+
<div class="updated">
|
1063 |
+
<p><?php _e( 'Mail template and options updated correctly', 'import-users-from-csv-with-meta' )?></p>
|
1064 |
+
</div>
|
1065 |
+
<?php
|
1066 |
+
}
|
1067 |
+
|
1068 |
+
// wp-access-areas functions
|
1069 |
+
function acui_set_cap_for_user( $capability , &$user , $add ) {
|
1070 |
+
$has_cap = $user->has_cap( $capability );
|
1071 |
+
$is_change = ($add && ! $has_cap) || (!$add && $has_cap);
|
1072 |
+
if ( $is_change ) {
|
1073 |
+
if ( $add ) {
|
1074 |
+
$user->add_cap( $capability , true );
|
1075 |
+
do_action( 'wpaa_grant_access' , $user , $capability );
|
1076 |
+
do_action( "wpaa_grant_{$capability}" , $user );
|
1077 |
+
} else if ( ! $add ) {
|
1078 |
+
$user->remove_cap( $capability );
|
1079 |
+
do_action( 'wpaa_revoke_access' , $user , $capability );
|
1080 |
+
do_action( "wpaa_revoke_{$capability}" , $user );
|
1081 |
+
}
|
1082 |
+
}
|
1083 |
+
}
|
1084 |
+
|
1085 |
+
// misc
|
1086 |
+
function acui_get_attachment_id_by_url( $url ) {
|
1087 |
+
$wp_upload_dir = wp_upload_dir();
|
1088 |
+
// Strip out protocols, so it doesn't fail because searching for http: in https: dir.
|
1089 |
+
$dir = set_url_scheme( trailingslashit( $wp_upload_dir['baseurl'] ), 'relative' );
|
1090 |
+
|
1091 |
+
// Is URL in uploads directory?
|
1092 |
+
if ( false !== strpos( $url, $dir ) ) {
|
1093 |
+
|
1094 |
+
$file = basename( $url );
|
1095 |
+
|
1096 |
+
$query_args = array(
|
1097 |
+
'post_type' => 'attachment',
|
1098 |
+
'post_status' => 'inherit',
|
1099 |
+
'fields' => 'ids',
|
1100 |
+
'meta_query' => array(
|
1101 |
+
array(
|
1102 |
+
'key' => '_wp_attachment_metadata',
|
1103 |
+
'compare' => 'LIKE',
|
1104 |
+
'value' => $file,
|
1105 |
+
),
|
1106 |
+
),
|
1107 |
+
);
|
1108 |
+
|
1109 |
+
$query = new WP_Query( $query_args );
|
1110 |
+
|
1111 |
+
if ( $query->have_posts() ) {
|
1112 |
+
foreach ( $query->posts as $attachment_id ) {
|
1113 |
+
$meta = wp_get_attachment_metadata( $attachment_id );
|
1114 |
+
$original_file = basename( $meta['file'] );
|
1115 |
+
$cropped_files = wp_list_pluck( $meta['sizes'], 'file' );
|
1116 |
+
|
1117 |
+
if ( $original_file === $file || in_array( $file, $cropped_files ) ) {
|
1118 |
+
return (int) $attachment_id;
|
1119 |
+
}
|
1120 |
+
}
|
1121 |
+
}
|
1122 |
+
}
|
1123 |
+
|
1124 |
+
return false;
|
1125 |
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://codection.com/go/donate-import-users-from-csv-with-meta/
|
|
4 |
Tags: csv, import, importer, meta data, meta, user, users, user meta, editor, profile, custom, fields, delimiter, update, insert
|
5 |
Requires at least: 3.4
|
6 |
Tested up to: 5.5.1
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -99,6 +99,9 @@ Plugin will automatically detect:
|
|
99 |
|
100 |
== Changelog ==
|
101 |
|
|
|
|
|
|
|
102 |
= 1.15.9.2 =
|
103 |
* We try to make the plugin compatible with BuddyPress related themes and plugins that uses their functions but they are not BuddyPress really
|
104 |
* Problems exporting file when a site is behind CloudFare fixed
|
4 |
Tags: csv, import, importer, meta data, meta, user, users, user meta, editor, profile, custom, fields, delimiter, update, insert
|
5 |
Requires at least: 3.4
|
6 |
Tested up to: 5.5.1
|
7 |
+
Stable tag: 1.16
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
99 |
|
100 |
== Changelog ==
|
101 |
|
102 |
+
= 1.16 =
|
103 |
+
* Code is being rewritten to make it easy to update
|
104 |
+
|
105 |
= 1.15.9.2 =
|
106 |
* We try to make the plugin compatible with BuddyPress related themes and plugins that uses their functions but they are not BuddyPress really
|
107 |
* Problems exporting file when a site is behind CloudFare fixed
|