Skip to content
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

Update child group status if exists #35

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion classes/class-pmprogroupacct-group-member.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,23 @@ public static function create( $group_child_user_id, $group_child_level_id, $gro
return false;
}

// Create the group member in the database with an "active" status.
// Check if the group member and group already exists, if so just update the status instead of not doing anything.
$existing_group_member = $wpdb->get_row(
$wpdb->prepare(
"SELECT * FROM {$wpdb->pmprogroupacct_group_members} WHERE group_child_user_id = %d AND group_child_level_id = %d AND group_id = %d AND group_child_status = 'inactive'",
$group_child_user_id,
$group_child_level_id,
$group_id
)
);

if ( ! empty( $existing_group_member ) ) {
$group_member = new self( (int) $existing_group_member->id );
$group_member->update_group_child_status( 'active' );
return $existing_group_member->id;
}

// Create the group member in the database with an "active" status if they don't exist.
$wpdb->insert(
$wpdb->pmprogroupacct_group_members,
array(
Expand Down