plugin-hook
Registers new event hooks and creates static handler methods in src/Plugin.php with appropriate category guards.
Install
mkdir -p .claude/skills/plugin-hook && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/12041" && unzip -o skill.zip -d .claude/skills/plugin-hook && rm skill.zipInstalls to .claude/skills/plugin-hook
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Adds a new event hook to src/Plugin.php — registers in getHooks() and creates the static GenericEvent handler. Use when user says 'add hook', 'handle event', 'new plugin event', or adds a lifecycle action (activate/deactivate/change IP/reactivate). Do NOT use for modifying existing handlers or adding inc functions.Key capabilities
- →Decide event and handler names for a new hook
- →Register the new hook in `getHooks()` in `src/Plugin.php`
- →Add the handler method to `src/Plugin.php`
- →Update `tests/PluginTest.php` with the new hook key and method count
- →Ensure handler methods are `public static` and accept `GenericEvent $event`
How it works
The skill adds a new event hook to `getHooks()` and creates a corresponding static handler method in `src/Plugin.php`, then updates the test file to reflect these changes.
Inputs & outputs
When to use plugin-hook
- →Add a new plugin event hook
- →Register lifecycle actions
- →Create static event handlers
About this skill
plugin-hook
Critical
- All handler methods MUST be
public staticand accept exactly oneGenericEvent $eventparameter —testHookMethodsArePublicAndStaticandtestEventHandlerMethodSignatureswill fail otherwise. - Always guard the handler body with
if ($event['category'] == get_service_define('PARALLELS'))before any logic. - Always call
$event->stopPropagation()as the last statement inside the category guard. - Hook keys use
self::$module . '.event_name'(e.g.'licenses.change_ip') — never hardcode the module string. - The one exception is
'function.requirements'which uses a literal key, not the module prefix. - Run
composer testafter every change — a missing method or wrong signature will breaktestAllHookMethodsExistandtestClassMethodCount.
Instructions
-
Decide the event name and handler name. Event name is snake_case (e.g.
change_ip). Handler is PascalCase prefixed withget(e.g.getChangeIp). Verify no existing entry ingetHooks()already covers this event. -
Register the hook in
getHooks()insidesrc/Plugin.php. Add one line to the returned array:self::$module.'.change_ip' => [__CLASS__, 'getChangeIp'],If the new event should share an existing handler (like
reactivate→getActivate), point to the existing method name instead of creating a new one. Verify the array key is unique before proceeding. -
Add the handler method to
src/Plugin.phpafter the last existing handler, before the closing}:/** * @param \Symfony\Component\EventDispatcher\GenericEvent $event */ public static function getChangeIp(GenericEvent $event) { if ($event['category'] == get_service_define('PARALLELS')) { $serviceClass = $event->getSubject(); myadmin_log(self::$module, 'info', 'Parallels <Action Description>', __LINE__, __FILE__, self::$module, $serviceClass->getId()); // ... call function_requirements() then the inc function ... $event->stopPropagation(); } }The
use Symfony\Component\EventDispatcher\GenericEvent;import is already present at the top — do not add it again. -
If the handler calls an inc function, add
function_requirements('your_function')before the call and register the function path ingetRequirements():$loader->add_requirement('your_function', '/../src/parallels.inc.php');Verify the function exists in
src/parallels.inc.phpbefore registering. -
Update
tests/PluginTest.php— add the new hook key to the$expectedKeysarray intestGetHooksContainsExpectedKeys()and bump the count intestClassMethodCount()if a new method was added. Runcomposer testto confirm all tests pass.
Examples
User says: "Add a hook for licenses.change_ip that logs the old and new IP"
Actions taken:
getHooks() addition in src/Plugin.php:
self::$module.'.change_ip' => [__CLASS__, 'getChangeIp'],
New handler method in src/Plugin.php:
public static function getChangeIp(GenericEvent $event)
{
if ($event['category'] == get_service_define('PARALLELS')) {
$serviceClass = $event->getSubject();
myadmin_log(self::$module, 'info', 'IP Change - (OLD:'.$serviceClass->getIp().") (NEW:{$event['newip']})", __LINE__, __FILE__, self::$module, $serviceClass->getId());
// perform IP change logic here
$event['status'] = 'ok';
$event['status_text'] = 'The IP Address has been changed.';
$event->stopPropagation();
}
}
Result: composer test passes; testGetHooksContainsExpectedKeys and testAllHookMethodsExist both green.
Common Issues
testClassMethodCountfails with "Expected 7, got 8": You added a new handler but did not update the count assertion intests/PluginTest.php. Change theassertCount(7, ...)to the new total.testAllHookMethodsExistfails: The method name string ingetHooks()does not exactly match the declared method name. Check spelling and PascalCase —getChangeIp≠getChangeIP.testEventHandlerMethodSignaturesfails with "parameter should be GenericEvent": The handler is missing theGenericEvent $eventtype hint, or theusestatement is absent (it lives at the top ofsrc/Plugin.php— do not remove it).stopPropagationnot called: Event will continue dispatching to other plugins and produce duplicate side-effects. Always place$event->stopPropagation()as the final statement inside the category guard.function_requirementsnot registered: Ifactivate_parallelsor a new inc function is called but not registered ingetRequirements(), it will throw a fatal error at runtime. Verify$loader->add_requirement('fn_name', '...')is present.
When not to use it
- →For modifying existing event handlers
- →For adding `inc` functions directly without registration
Limitations
- →Handler methods must be `public static` and accept `GenericEvent $event`
- →Requires guarding handler body with `if ($event['category'] == get_service_define('PARALLELS'))`
- →Requires calling `$event->stopPropagation()` as the last statement inside the category guard
How it compares
This skill automates the structured addition of new event hooks and their handlers, including test updates, which is more guided than manually inserting code and updating tests.
Compared to similar skills
plugin-hook side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| plugin-hook (this skill) | 0 | 4mo | No flags | Intermediate |
| write-script-php | 1 | 3mo | No flags | Intermediate |
| import | 1 | 6mo | No flags | Beginner |
| controller | 1 | 6mo | No flags | Beginner |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by myadmin-plugins
View all by myadmin-plugins →You might also like
write-script-php
windmill-labs
MUST use when writing PHP scripts.
import
JaguarJack
Generate Excel import class for CatchAdmin module.
controller
JaguarJack
Generate CRUD controller for CatchAdmin module.
soap-bin-script
myadmin-plugins
Creates a new synchronous SOAP operation script in bin/ following the exact boilerplate from bin/GetVM.php, bin/DeleteVM.php, etc. Use when user says 'add a bin script', 'new SOAP operation', 'create a hyperv command', or adds a new HyperVService method. Generates the ini_set block, argc check, get_
laravel-backup
Scanix
Configure and extend spatie/laravel-backup for database and file backups, cleanup strategies, health monitoring, and notifications. Activates when working with backup configuration, scheduling backups, creating custom cleanup strategies or health checks, customizing notifications, or when the user m
woocommerce-code-review
woocommerce
Review WooCommerce code changes for coding standards compliance. Use when reviewing code locally, performing automated PR reviews, or checking code quality.