Import users from CSV with meta - Version 1.10.8.1

Version Description

= 1.0 = * First installation

Download this release

Release Info

Developer carazo
Plugin Icon 128x128 Import users from CSV with meta
Version 1.10.8.1
Comparing to
See all releases

Code changes from version 1.10.8 to 1.10.8.1

addons/acui-woocommerce-membership.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) exit;
4
+
5
+ if( is_plugin_active( 'woocommerce-memberships/woocommerce-memberships.php' ) ){
6
+ add_filter( 'acui_restricted_fields', 'acui_wm_restricted_fields', 10, 1 );
7
+ add_action( 'acui_documentation_after_plugins_activated', 'acui_wm_documentation_after_plugins_activated' );
8
+ add_action( 'post_acui_import_single_user', 'acui_wm_post_import_single_user', 10, 3 );
9
+ }
10
+
11
+ function acui_wm_restricted_fields( $acui_restricted_fields ){
12
+ return array_merge( $acui_restricted_fields, array( 'member_first_name', 'member_last_name', 'member_email', 'membership_plan_id', 'membership_plan_slug', 'membership_plan', 'membership_status', 'member_since', 'membership_expiration' ) );
13
+ }
14
+
15
+ function acui_wm_documentation_after_plugins_activated(){
16
+ ?>
17
+ <tr valign="top">
18
+ <th scope="row"><?php _e( "WooCommerce Membership is activated", 'import-users-from-csv-with-meta' ); ?></th>
19
+ <td><?php _e( "You can use the <strong>columns in the CSV format created by WooCommercer Membership</strong> in order to import data from this plugin.", 'import-users-from-csv-with-meta' ); ?>. <a href="https://docs.woocommerce.com/document/woocommerce-memberships-import-and-export/"><?php _e( "Read more about columns and formats", 'import-users-from-csv-with-meta' ); ?></a>
20
+ </td>
21
+ </tr>
22
+ <?php
23
+ }
24
+
25
+ function acui_wm_post_import_single_user( $headers, $row, $user_id ){
26
+ $keys = array( 'member_first_name', 'member_last_name', 'member_email', 'membership_plan_id', 'membership_plan_slug', 'membership_plan', 'membership_status', 'member_since', 'membership_expiration' );
27
+ $columns = array();
28
+
29
+ foreach ( $keys as $key ) {
30
+ $columns[ $key ] = array_search ( $key, $headers );
31
+ }
32
+
33
+ $membership_plan_id = isset( $columns['membership_plan_id'] ) && ! empty( $row[ $columns['membership_plan_id'] ] ) ? (int) $row[ $columns['membership_plan_id'] ] : null;
34
+ $membership_plan_slug = isset( $columns['membership_plan_slug'] ) && ! empty( $row[ $columns['membership_plan_slug'] ] ) ? $row[ $columns['membership_plan_slug'] ] : null;
35
+ $membership_plan = null;
36
+
37
+ if ( is_int( $membership_plan_id ) ) {
38
+ $membership_plan = wc_memberships_get_membership_plan( $membership_plan_id );
39
+ }
40
+
41
+ if ( ! $membership_plan && ! empty( $membership_plan_slug ) ) {
42
+ $membership_plan = wc_memberships_get_membership_plan( $membership_plan_slug );
43
+ }
44
+
45
+ // try to get an existing user membership from an id
46
+ $user_membership_id = isset( $columns['user_membership_id'] ) && ! empty( $row[ $columns['user_membership_id'] ] ) ? (int) $row[ $columns['user_membership_id'] ] : null;
47
+ $existing_user_membership = is_int( $user_membership_id ) ? wc_memberships_get_user_membership( $user_membership_id ) : null;
48
+
49
+ if ( ! $membership_plan && ! $existing_user_membership ) {
50
+ return;
51
+ } elseif ( ! $existing_user_membership && false ) {
52
+ return;
53
+ }
54
+
55
+ $import_data = array();
56
+
57
+ $import_data['membership_plan_id'] = $membership_plan_id;
58
+ $import_data['membership_plan_slug'] = $membership_plan_slug;
59
+ $import_data['membership_plan_name'] = isset( $columns['membership_plan'] ) && ! empty( $row[ $columns['membership_plan'] ] ) ? $row[ $columns['membership_plan'] ] : null;
60
+ $import_data['membership_plan'] = $membership_plan;
61
+ $import_data['user_membership_id'] = $user_membership_id;
62
+ $import_data['user_membership'] = $existing_user_membership;
63
+ $import_data['user_id'] = $user_id;
64
+ $import_data['user_name'] = isset( $columns['user_name'] ) && ! empty( $row[ $columns['user_name'] ] ) ? $row[ $columns['user_name'] ] : null;
65
+ $import_data['product_id'] = isset( $columns['product_id'] ) && ! empty( $row[ $columns['product_id'] ] ) ? $row[ $columns['product_id'] ] : null;
66
+ $import_data['order_id'] = isset( $columns['order_id'] ) && ! empty( $row[ $columns['order_id'] ] ) ? $row[ $columns['order_id'] ] : null;
67
+ $import_data['member_email'] = isset( $columns['member_email'] ) && ! empty( $row[ $columns['member_email'] ] ) ? $row[ $columns['member_email'] ] : null;
68
+ $import_data['member_first_name'] = isset( $columns['member_first_name'] ) && ! empty( $row[ $columns['member_first_name'] ] ) ? $row[ $columns['member_first_name'] ] : null;
69
+ $import_data['member_last_name'] = isset( $columns['member_last_name'] ) && ! empty( $row[ $columns['member_last_name'] ] ) ? $row[ $columns['member_last_name'] ] : null;
70
+ $import_data['membership_status'] = isset( $columns['membership_status'] ) && ! empty( $row[ $columns['membership_status'] ] ) ? $row[ $columns['membership_status'] ] : null;
71
+ $import_data['member_since'] = isset( $columns['member_since'] ) && ! empty( $row[ $columns['member_since'] ] ) ? $row[ $columns['member_since'] ] : null;
72
+ $import_data['membership_expiration'] = isset( $columns['membership_expiration'] ) && isset( $row[ $columns['membership_expiration'] ] ) ? $row[ $columns['membership_expiration'] ] : null;
73
+
74
+ $action = 'create';
75
+ $import_data = (array) apply_filters( 'wc_memberships_csv_import_user_memberships_data', $import_data, $action, $columns, $row );
76
+
77
+ $user_membership = null;
78
+
79
+ if ( isset( $import_data['membership_plan'] ) && $import_data['membership_plan'] instanceof WC_Memberships_Membership_Plan ) {
80
+ if ( wc_memberships_is_user_member( $user_id, $import_data['membership_plan'] ) ) {
81
+ return false;
82
+ }
83
+
84
+ $user_membership = wc_memberships_create_user_membership( array(
85
+ 'user_membership_id' => 0,
86
+ 'plan_id' => $import_data['membership_plan']->get_id(),
87
+ 'user_id' => $user_id,
88
+ 'product_id' => ! empty( $import_data['product_id'] ) ? (int) $import_data['product_id'] : 0,
89
+ 'order_id' => ! empty( $import_data['order_id'] ) ? (int) $import_data['order_id'] : 0,
90
+ ), 'create' );
91
+ }
92
+
93
+ acui_vm_update_user_membership_meta( $user_membership, $action, $import_data );
94
+
95
+ do_action( 'wc_memberships_csv_import_user_membership', $user_membership, $action, $import_data );
96
+ }
97
+
98
+ function acui_vm_update_user_membership_meta( WC_Memberships_User_Membership $user_membership, $action, array $data ) {
99
+ if( !empty( $data['product_id'] ) ) {
100
+ $user_membership->set_product_id( trim( $data['product_id'] ) );
101
+ }
102
+
103
+ if( !empty( $data['order_id'] ) ) {
104
+ $user_membership->set_order_id( trim( $data['order_id'] ) );
105
+ }
106
+
107
+ if( !empty( $data['member_since'] ) ) {
108
+ $user_membership->set_start_date( trim( $data['member_since'] ) );
109
+ }
110
+
111
+ if( !empty( $data['membership_status'] ) ){
112
+ $user_membership->update_status( trim( $data['membership_status'] ) );
113
+ }
114
+
115
+ if( !empty( $data['membership_expiration'] ) ){
116
+ $user_membership->set_end_date( trim( $data['membership_expiration'] ) );
117
+ }
118
+ }
import-users-from-csv-with-meta.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Import users from CSV with meta
4
  Plugin URI: https://www.codection.com
5
  Description: This plugins allows to import users using CSV files to WP database automatically
6
- Version: 1.10.8
7
  Author: codection
8
  Author URI: https://codection.com
9
  License: GPL2
@@ -52,7 +52,9 @@ function acui_loader(){
52
  add_action( "edit_user_profile_update", "acui_save_extra_user_profile_fields" );
53
  }
54
 
55
- require_once( "addons/acui-woocommerce-membership.php" );
 
 
56
  require_once( "importer.php" );
57
  }
58
 
3
  Plugin Name: Import users from CSV with meta
4
  Plugin URI: https://www.codection.com
5
  Description: This plugins allows to import users using CSV files to WP database automatically
6
+ Version: 1.10.8.1
7
  Author: codection
8
  Author URI: https://codection.com
9
  License: GPL2
52
  add_action( "edit_user_profile_update", "acui_save_extra_user_profile_fields" );
53
  }
54
 
55
+ if( file_exists( "addons/acui-woocommerce-membership.php") )
56
+ require_once( "addons/acui-woocommerce-membership.php" );
57
+
58
  require_once( "importer.php" );
59
  }
60
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://paypal.me/codection
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: 4.9
7
- Stable tag: 1.10.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
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: 4.9
7
+ Stable tag: 1.10.8.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10