0

Firstly apologies for my explanation and terminology, this is a relatively new area for me.

I've built an extension which uses three hooks:

  • user_register_end
  • user_edit_end
  • user_delete_account_end

The first two are working correctly however the last one doesn't appear to be. The hook is referenced in Solspace User in file mod.user.php as is the user_register_end one.

Here are the two hook initiations:

//Register user hook (working)
if (ee()->extensions->active_hook('user_register_end') === TRUE)
{
    $edata = ee()->extensions->universal_call('user_register_end', $this, $member_id);
    if (ee()->extensions->end_script === TRUE) return;
}

//Delete user hook (not working)
if (ee()->extensions->active_hook('user_delete_account_end') === TRUE)
{
    $edata = ee()->extensions->universal_call('user_delete_account_end', $this);
    if (ee()->extensions->end_script === TRUE) return;
}

And here is my code for both hooks:

//Hook array used to populate the extensions table
$hooks = array(
    'user_register_end' => 'new_client_check',
    'user_edit_end' => 'upd_client_check',
    'user_delete_account_end' => 'del_client_check'
);

function upd_client_check($member_id, $user_object, $cfields) {
    //Function code
}

function del_client_check($member_data) {
    return('working');
    die;
}

During my tests I've been printing out comments or data and killing the function so it stops right away and this has been working fine so far. Now though when I delete a member I'm just shown the successful delete message so the hook isn't being noticed.

I can confirm that all the hooks and methods are in the database correctly. Image of extensions table hooks and methods

Can anyone help at all? And if you need to me explain in more detail I'll try my best.

Edit I am using this extension with the Solspace User delete form.

Thank you.

3
  • 1
    You're using return before die, which means your PHP script will see return then stop, and never see the die command. Try echo 'working'; die(); or even simply die('working');
    – Solspace
    Commented Jan 12, 2015 at 9:45
  • Aha! Thank you very much for that, it's working as intended now. Always nice to learn something new too. Commented Jan 12, 2015 at 10:30
  • Great! I posted the above as a solution. Feel free to mark it as the solution. :)
    – Solspace
    Commented Jan 13, 2015 at 7:58

2 Answers 2

0

You're using return before die, which means your PHP script will see return then stop, and never see the die command. Try echo 'working'; die(); or even simply die('working');

0

Looking at the change log for when that hook was added, it states:

Added a "user_delete_account_end" hook to the end of the delete_account function for the Delete_form tag

So this tells me that this hook only fires when an account is deleted using User's own delete_form tag.

To hook into member deletion via the control panel, you'll want to use EE's own cp_members_member_delete_end hook.

1
  • Sorry, I should've mentioned that this is using the Solspace User delete form. I'll add this to my question. Thanks for the prompt response though. Commented Jan 9, 2015 at 17:01

Your Answer

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

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