-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to use import members from CSV file Add On combined with … #31
base: dev
Are you sure you want to change the base?
Changes from all commits
ecdb6d4
74ca509
9ad648b
8b7f18c
e8d5b90
f3e6029
439e9ea
71b7b67
5225b7e
050b1d1
b83d1fb
d5330f9
e1d7083
f08bfcf
f40c1ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,3 +215,47 @@ function pmprogroupacct_plugin_row_meta($links, $file) { | |
return $links; | ||
} | ||
add_filter('plugin_row_meta', 'pmprogroupacct_plugin_row_meta', 10, 2); | ||
|
||
|
||
/** | ||
* Import group account member associations when using the Import Users From CSV plugin. | ||
* | ||
* @param WP_User $user The user object that was imported. | ||
* @param int $membership_id The membership level ID that was imported. | ||
* @param MemberOrder|null $order The order object that was created during import. Null if no order is created. | ||
* @since TBD | ||
*/ | ||
function pmprogroupacct_pmproiucsv_post_user_import( $user, $membership_id, $order ) { | ||
global $wpdb; | ||
|
||
$group_level_settings = pmprogroupacct_get_settings_for_level( $membership_id ); | ||
$parent_group = PMProGroupAcct_Group::get_group_by_parent_user_id_and_parent_level_id( $user->ID, $membership_id ); | ||
$group_id = $user->pmprogroupacct_group_id; // Child accounts would pass through the Group ID. | ||
$seats = ! empty( $user->pmprogroupacct_group_total_seats ) ? intval( $user->pmprogroupacct_group_total_seats ) : $group_level_settings['max_seats']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we always want to default to the max seats for a group, or if the number of seats is not specified, do we instead just not want to alter group seat data? |
||
|
||
// Add user to group if their level is a parent level and create the group if it doesn't exist. | ||
if ( ! empty( $parent_group ) ) { | ||
//Update seats if the user has a total seats value from CSV. | ||
$parent_group->update_group_total_seats( $seats ); | ||
} elseif ( empty( $group_id ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is tricky. I think we only want to create a new group if:
|
||
// There is not already a group for this user and level. Let's create one. | ||
PMProGroupAcct_Group::create( $user->ID, $membership_id, $seats ); | ||
} | ||
|
||
// Add the child account if the level is a child level and passed through a group ID. | ||
if ( ! empty( $group_id ) && pmprogroupacct_level_can_be_claimed_using_group_codes( $membership_id ) ) { | ||
|
||
// Let's set all previous instances to "inactive" before trying to insert the child record. | ||
$wpdb->query( | ||
$wpdb->prepare( | ||
"UPDATE $wpdb->pmprogroupacct_group_members SET group_child_status = 'inactive' WHERE group_child_user_id = %d AND group_child_level_id = %d", | ||
$user->ID, | ||
$membership_id | ||
) | ||
); | ||
|
||
// Add them back. | ||
PMProGroupAcct_Group_Member::create( $user->ID, $membership_id, $group_id ); | ||
} | ||
} | ||
add_action( 'pmproiucsv_after_member_import', 'pmprogroupacct_pmproiucsv_post_user_import', 10, 3 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
I can't find the required csv structure for using this code.
Can you help me ?