{"id":37261986,"url":"https://github.com/nlemoine/wp-hook-kit","last_synced_at":"2026-01-15T23:13:57.231Z","repository":{"id":330148622,"uuid":"1121797730","full_name":"nlemoine/wp-hook-kit","owner":"nlemoine","description":"A lightweight WordPress hook helper library. Register hooks before WordPress loads, run callbacks only once, and more.","archived":false,"fork":false,"pushed_at":"2025-12-23T15:36:10.000Z","size":16,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-25T03:46:44.998Z","etag":null,"topics":["wordpress","wordpress-php-library"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nlemoine.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-23T15:13:58.000Z","updated_at":"2025-12-24T08:26:54.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/nlemoine/wp-hook-kit","commit_stats":null,"previous_names":["nlemoine/wp-hook-kit"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/nlemoine/wp-hook-kit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlemoine%2Fwp-hook-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlemoine%2Fwp-hook-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlemoine%2Fwp-hook-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlemoine%2Fwp-hook-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nlemoine","download_url":"https://codeload.github.com/nlemoine/wp-hook-kit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlemoine%2Fwp-hook-kit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28419206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["wordpress","wordpress-php-library"],"created_at":"2026-01-15T23:13:56.709Z","updated_at":"2026-01-15T23:13:57.226Z","avatar_url":"https://github.com/nlemoine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WP Hook Kit\n\n[![Tests](https://img.shields.io/github/actions/workflow/status/nlemoine/wp-hook-kit/tests.yml?branch=main\u0026label=tests)](https://github.com/nlemoine/wp-hook-kit/actions/workflows/tests.yml)\n[![Coverage](https://img.shields.io/codecov/c/github/nlemoine/wp-hook-kit)](https://codecov.io/gh/nlemoine/wp-hook-kit)\n[![PHPStan](https://img.shields.io/badge/PHPStan-max-brightgreen)](https://phpstan.org/)\n\nA lightweight WordPress hook helper library. Register hooks before WordPress loads, run callbacks only once, and more.\n\n## Installation\n\n```bash\ncomposer require n5s/wp-hook-kit\n```\n\n## Usage\n\n```php\nuse n5s\\WpHookKit\\Hook;\n\n// Basic usage - works even before WordPress is loaded\nHook::addFilter('the_content', fn($content) =\u003e $content . '\u003cp\u003eFooter\u003c/p\u003e');\nHook::addAction('init', fn() =\u003e register_post_type('book', []));\n\n// Run a callback only once (removes itself after first execution)\nHook::addFilterOnce('the_title', fn($title) =\u003e $title . ' - Launch Sale!');\nHook::addActionOnce('wp_footer', fn() =\u003e echo '\u003c!-- First visit --\u003e');\n\n// Side effects - run code without modifying the filtered value\nHook::addFilterSideEffect('the_content', function($content) {\n    error_log('Content rendered: ' . strlen($content) . ' chars');\n});\n\n// Combine both: side effect that runs once\nHook::addFilterSideEffectOnce('template_include', function($template) {\n    log_first_template_load($template);\n});\n\n// Register same callback on multiple hooks\nHook::addFilters(['the_title', 'the_content'], 'esc_html');\nHook::addActions(['wp_head', 'wp_footer'], fn() =\u003e do_something());\n```\n\nAll methods accept the standard WordPress parameters: `$hook`, `$callback`, `$priority = 10`, `$accepted_args = 1`.\n\n## Why?\n\n**Early registration**: Register hooks before WordPress fully loads. The library writes directly to `$wp_filter` when `add_filter()` isn't available yet. Unlocks the power of bringing features without the \"plugin\" way hassle when it's not needed (library, composer autoloaded files, etc.).\n\n**Once variants**: Because sometimes, you might not want your callback to be executed every time a hook is called.\n\n**Side effects**: Runs your callback and returns the original value unchanged. Useful to trigger actions when an actual action isn't available, observe filter behavior, etc.\n\n## Acknowledgments\n\nThis package is gathering multiple package implementations inside a single library, credits goes to:\n\n- [wecodemore/wordpress-early-hook](https://github.com/wecodemore/wordpress-early-hook) — Early hook registration. The only downside is that it can't safely be used inside a library (because Composer doesn't guarantee autoloaded files order). Plus some minor performance improvements.\n- [stevegrunwell/one-time-callbacks](https://github.com/stevegrunwell/one-time-callbacks) — Once variants\n- [alleyinteractive/wp-filter-side-effects](https://github.com/alleyinteractive/wp-filter-side-effects) — Side effects\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlemoine%2Fwp-hook-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnlemoine%2Fwp-hook-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlemoine%2Fwp-hook-kit/lists"}