{"id":20930074,"url":"https://github.com/level-level/clarkson-hooks","last_synced_at":"2025-05-13T18:32:41.090Z","repository":{"id":62516911,"uuid":"85297534","full_name":"level-level/clarkson-hooks","owner":"level-level","description":"Solution for 'Just in time' WordPress Hooks.","archived":true,"fork":false,"pushed_at":"2025-03-17T08:26:50.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-02T06:35:42.735Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/level-level.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}},"created_at":"2017-03-17T10:03:17.000Z","updated_at":"2025-03-17T08:27:09.000Z","dependencies_parsed_at":"2022-11-02T10:31:14.811Z","dependency_job_id":null,"html_url":"https://github.com/level-level/clarkson-hooks","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/level-level%2Fclarkson-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/level-level%2Fclarkson-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/level-level%2Fclarkson-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/level-level%2Fclarkson-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/level-level","download_url":"https://codeload.github.com/level-level/clarkson-hooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254003428,"owners_count":21997886,"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":[],"created_at":"2024-11-18T21:28:42.973Z","updated_at":"2025-05-13T18:32:40.815Z","avatar_url":"https://github.com/level-level.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Clarkson Hooks\n\nSolution for 'Just in time' WordPress Hooks.\n\nClarkson-hooks combines the `all` action and composer autoloading to only include the filters you are actually going to use.\n\n# Setup\n\n## 1. Define clarkson-hooks as a dependency.\n`composer require level-level/clarkson-hooks`\n\nIt will load automatically.\n\n## 2. Point Composer towards a directory to find your `Hooks` namespace.\n\n```\n\"autoload\": {\n    \"psr-4\":{\n        \"Hooks\\\\\": \"app/Hooks\"\n    }\n}\n```\n\n## 3. Define a hook\n\nExample minimal init.php (put this in `app/Hooks/init.php` when using path specified in composer above.\n\n```\n\u003c?php\nnamespace Hooks;\n\nuse Clarkson\\Hooks\\iHook;\n\nclass init implements iHook {\n    public static function register_hooks( $name ){\n        add_action('init', function(){\n            wp_die('Hello world');\n        });\n    }\n}\n```\n\nNote: the `\\Clarkson\\Hooks\\iHook` interface makes sure you correctly define your `Hook` object.\n\nFor a real live example, check out the [init hook in Clarkson Theme](https://github.com/level-level/Clarkson-Theme/blob/021fcfe463b52f399d713b5bd867b01c19b4dead/app/Hooks/init.php).\n\n# What happens in the background\n\n1. An `apply_filters` or `do_action` is called from WordPress.\n2. Just before the actual hook is triggered, the `do_action('all')` is caught by Clarkson-hooks.\n3. Clarkson-hooks checks for the existence of `\\Hooks\\{hook-tag}` (Composer handles loading any corresponding file).\n4. The correspondig class gets the static method `register_hooks` called. The actual `add_filter` or `add_action` is done in this file.\n5. WordPress continues as expected.\n\n# Tips\n\nBe sure to use the `--optimize-autoloader` composer flag on production to have the loading process moving smoothly. Otherwise the class_exists function creates a lot of overhead.\n\nAll hooks initialize only once.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevel-level%2Fclarkson-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flevel-level%2Fclarkson-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevel-level%2Fclarkson-hooks/lists"}