0

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.

1 Answer 1

2

Take return statement out of } else {.

You should always return member_ids that should be deleted.

So, change

if (!empty($cleared_entries)) {
    $this->entry_update_del($cleared_entries, $member_id);
} else {
    return $member_ids;
}

to

if (!empty($cleared_entries)) {
    $this->entry_update_del($cleared_entries, $member_id);
} 
return $member_ids;
1
  • Brilliant! Thank you very much for that. I understand why it didn't work now. Jan 13, 2015 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.