I've got an extension that is using the member_delete hook which checks a specific entry field for the deleted member's ID and removes it if found.
This is working fine (field cleared of member ID) and I am shown the EE message saying that the member has been deleted however when I view the member list the member still remains.
I read question Cancelling member deletion in member_delete hook handler and it says that you need to return an array of member_ids for it to continue. I've done just that but it doesn't appear to be doing anything.
Here is my code:
function del_client_check($member_ids) {
$cleared_entries = array();
$member_id = $member_ids[0];
$field['m_client'] = $this->settings['client_field'];
$field['e_client'] = $this->settings['e_client_field'];
$m_field = $this->settings['member_field'];
$this->EE->db->select('entry_id, ' . $m_field . '');
$entries = $this->EE->db->get('channel_data')->result_array();
foreach ($entries as $entry) {
if ($entry[$m_field] != '') {
$members = explode('|', $entry[$m_field]);
if (($key = array_search($member_id, $members)) !== false) {
unset($members[$key]);
$entry[$m_field] = implode('|', $members);
$cleared_entries[] = $entry;
}
}
}
if (!empty($cleared_entries)) {
$this->entry_update_del($cleared_entries, $member_id);
} else {
return $member_ids;
}
}
function entry_update_del($entries, $member_id) {
$member_ids = array();
$this->EE->db->update_batch('channel_data', $entries, 'entry_id');
$member_ids[0] = $member_id;
return $member_ids;
}
Just a note, in the entry_update_del function I am setting $member_ids[0]
to $member_id
. There is always only going to be 1 member deleted at a time.
If anyone could help that would be great.