{"id":22567835,"url":"https://github.com/yardinternet/wp-hook-registrar","last_synced_at":"2025-04-10T12:22:42.483Z","repository":{"id":263667981,"uuid":"884282969","full_name":"yardinternet/wp-hook-registrar","owner":"yardinternet","description":"An Acorn package for WordPress Hook Registration.","archived":false,"fork":false,"pushed_at":"2025-03-31T10:36:01.000Z","size":452,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-31T11:31:40.980Z","etag":null,"topics":["acorn","wordpress"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yardinternet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-06T13:28:34.000Z","updated_at":"2025-03-31T10:36:04.000Z","dependencies_parsed_at":"2024-11-19T20:08:47.223Z","dependency_job_id":"1061ce4b-1e49-4673-9acf-f4c3eacdfb43","html_url":"https://github.com/yardinternet/wp-hook-registrar","commit_stats":null,"previous_names":["yardinternet/wp-hook-registrar"],"tags_count":3,"template":false,"template_full_name":"yardinternet/skeleton-package","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yardinternet%2Fwp-hook-registrar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yardinternet%2Fwp-hook-registrar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yardinternet%2Fwp-hook-registrar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yardinternet%2Fwp-hook-registrar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yardinternet","download_url":"https://codeload.github.com/yardinternet/wp-hook-registrar/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248217112,"owners_count":21066633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["acorn","wordpress"],"created_at":"2024-12-08T00:09:23.269Z","updated_at":"2025-04-10T12:22:42.457Z","avatar_url":"https://github.com/yardinternet.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wp-hook-registrar\n\n[![Code Style](https://github.com/yardinternet/wp-hook-registrar/actions/workflows/format-php.yml/badge.svg?no-cache)](https://github.com/yardinternet/wp-hook-registrar/actions/workflows/format-php.yml)\n[![PHPStan](https://github.com/yardinternet/wp-hook-registrar/actions/workflows/phpstan.yml/badge.svg?no-cache)](https://github.com/yardinternet/wp-hook-registrar/actions/workflows/phpstan.yml)\n[![Tests](https://github.com/yardinternet/wp-hook-registrar/actions/workflows/run-tests.yml/badge.svg?no-cache)](https://github.com/yardinternet/wp-hook-registrar/actions/workflows/run-tests.yml)\n[![Code Coverage Badge](https://github.com/yardinternet/wp-hook-registrar/blob/badges/coverage.svg)](https://github.com/yardinternet/wp-hook-registrar/actions/workflows/badges.yml)\n[![Lines of Code Badge](https://github.com/yardinternet/wp-hook-registrar/blob/badges/lines-of-code.svg)](https://github.com/yardinternet/wp-hook-registrar/actions/workflows/badges.yml)\n\nAn Acorn package for WordPress Hook Registration.\n\n## Features\n\n- [x] Register Hooks using php attributes\n- [x] Configure Hook registration using a config file\n- [x] Load plugin-specific hooks only when the plugin is active\n\nSee [config](./config/hooks.php) for all configuration options.\n\n## Requirements\n\n- [Sage](https://github.com/roots/sage) \u003e= 10.0\n- [Acorn](https://github.com/roots/acorn) \u003e= 4.0\n\n## Installation\n\n1. Install this package with Composer:\n\n    ```sh\n    composer require yard/wp-hook-registrar\n    ```\n\n2. Run the Acorn WP-CLI command to discover this package:\n\n    ```shell\n    wp acorn package:discover\n    ```\n\n3. Publish the config file with:\n\n   ```shell\n   wp acorn vendor:publish --provider=\"Yard\\Hook\\HookServiceProvider\"\n   ```\n\n4. Register all your project hooks in the published configuration file `config/hooks.php`.\n\n## Installation in WordPress plugins\n\nTo use this package in a standard WordPress plugin, you can use the `HookRegistrar` to register hooks.\nYou can skip step 3 and 4 from the installation instructions above and instead add the following to your plugin's\nmain file:\n\n```php\n/**\n * Plugin Name: My Plugin\n */\n\nrequire __DIR__ . '/vendor/autoload.php';\n\n$classNames = [\n    \\Plugin\\ClassContainsHooks::class,\n    \\Plugin\\AnotherClassContainsHooks::class,\n];\n\n$registrar = new \\Yard\\Hook\\Registrar($classNames);\n$registrar-\u003eregisterHooks();\n```\n\n## Hook Attributes\n\nThis package provides two Attributes: `Action` and `Filter`. They can be used to register hooks instead of the\nWordPress functions [add_action()](https://developer.wordpress.org/reference/functions/add_action/) and [add_filter()](https://developer.wordpress.org/reference/functions/add_filter/)\n\nThis syntax allows you to place the hook registration directly above the method it invokes when the hook is triggered.\n\n```php\n#[Action(string $hookName, int $priority = 10)]\npublic function doSomething(): void\n```\n\n```php\n#[Filter(string $hookName, int $priority = 10)]\npublic function filterSomething(): mixed\n```\n\nNotice that you do not need to pass the number of accepted arguments to the `Action` and `Filter` attributes as you would\nwith `add_action()` and `add_filter()`. Instead, the number of accepted arguments is determined by the method\nsignature.\n\nYou can add as many hooks to the same method as you want.\n\n## Example\n\n```php\n\u003c?php\n\nnamespace App\\Hooks;\n\nuse Yard\\Hook\\Action;\nuse Yard\\Hook\\Filter;\n\nclass Theme\n{\n    #[Action('save_post')]\n    public function doSomething(int $postId, \\WP_Post $post, bool $update): string\n    {\n        // do something\n    }\n\n    #[Filter('the_content')]\n    #[Filter('the_excerpt')]\n    public function filterSomething(string $content)\n    {\n        // filter content\n        return $content;\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyardinternet%2Fwp-hook-registrar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyardinternet%2Fwp-hook-registrar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyardinternet%2Fwp-hook-registrar/lists"}