Download the PHP package spenserhale/wp-autohook-library without Composer
On this page you can find all versions of the php package spenserhale/wp-autohook-library. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download spenserhale/wp-autohook-library
More information about spenserhale/wp-autohook-library
Files in spenserhale/wp-autohook-library
Package wp-autohook-library
Short Description A library for automatically hooking classes into WordPress actions and filters.
License MIT
Informations about the package wp-autohook-library
WP AutoHooks
WP AutoHooks is a PHP Library that allows you to define Attributes on Classes and Methods to document and register WordPress Hooks.
Features
- Developer Experience: Document hooks next to the method, giving you context and a better developer experience.
- Performance: Hooks are registered without loading classes or instantiating objects until needed.
- Flexibility: The underlying PHP Library can be used for both simple and complex projects.
- Modularity: Ability to add and remove standalone classes quickly and easily.
Getting Started
Prerequisites
By default, the library is geared toward Composer, but there is flexibility, and you can integrate the library with your class loading system.
Installation
Basic Usage
Attribute your class and methods with the Hook and Shortcode attributes.
Method-Level Attributes
Apply attributes directly to methods. The method name is automatically used as the callback:
Named Parameters
Use named parameters for flexibility in argument order:
Multiple Hooks on a Single Method
Apply multiple hooks to the same method using stacked attributes or comma-separated syntax:
Shortcodes
Register shortcodes using the Shortcode attribute:
Class-Level Attributes (Inherited Methods)
Apply attributes at the class level when you need to hook methods inherited from a parent class. Since attributes on parent methods aren't scanned in child classes, class-level attributes let you register hooks for inherited methods:
Complete Example
Generated Output
The above example generates:
Build/Wire Up
Advanced Usage
Some projects may not have the composer.json available at runtime, so you can use the class loader object.
Build/Wire Up
Tests
To run tests, make sure to create class list through composer:
Then run the tests:
License
The WordPress AutoHooks Library is open-sourced software licensed under the MIT license.
(back to top)