How to create hook that blocking API Calls

andrzej.ol

Registered
Jul 19, 2021
3
0
1
Poland
cPanel Access Level
Root Administrator
Hi,

I am really confused because I want to create hook for my plugin that would block actions in pre stage of hooks.

For example I want to create Account::Create action in case of wrong package

How Can I do that? I am running many hook examples, trying to return different response.

If that is even possible? If yes what should I return or what should I register?


PHP:
'category' => 'Whostmgr',
    'event' => 'Accounts::Create',
    'stage' => 'pre',
    'hook' => '/usr/local/cpanel/whostmgr/docroot/cgi/myplugin/hooks.php --create',
    'exectype' => 'script',
    'weight' => 999,
],
 

andrzej.ol

Registered
Jul 19, 2021
3
0
1
Poland
cPanel Access Level
Root Administrator
Hi,

On every call Account::Create I want to check if my package is correct

I want to do that in the hook, before create (pre). So I want to stop this call and return own result instead of standard api response.

Shortly, I want to avoid account creating with that hook, Is that possible?


Code:
if($package == 'wrong'){
    // return message or result that would block api call
    return [0, 'Cannot create account, package is wrong'];
}
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
6,188
790
313
cPanel Access Level
Root Administrator

andrzej.ol

Registered
Jul 19, 2021
3
0
1
Poland
cPanel Access Level
Root Administrator
Hi,

Thanks! It helped, but I spent more than 4 hours to check what is wrong with my code. In your documentation there is info that is should be

PHP:
die("BAILOUT: $message");
But it has to be

PHP:
die("BAILOUT $message");