https://github.com/blockifywp/hooks
Hook methods based on annotation.
https://github.com/blockifywp/hooks
Last synced: 4 months ago
JSON representation
Hook methods based on annotation.
- Host: GitHub
- URL: https://github.com/blockifywp/hooks
- Owner: blockifywp
- Created: 2024-04-24T08:45:09.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-21T12:36:18.000Z (about 2 years ago)
- Last Synced: 2025-12-05T14:47:47.703Z (6 months ago)
- Language: PHP
- Size: 7.81 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Blockify Hooks
Hook methods by comment annotation in docblock.
Based on Hook Annotations by Viktor Szépe - [https://github.com/szepeviktor/SentencePress](https://github.com/szepeviktor/SentencePress)
## Installation
```bash
composer require blockify/hooks
```
## Usage
### PHP
First, require Composer's autoloader and then register the hooks with
WordPress:
```php
require_once __DIR__ . '/vendor/autoload.php';
```
Add hook tag and optional priority to method docblock:
```php
class MyPlugin
{
/**
* Enqueue scripts.
*
* @hook wp_enqueue_scripts 12
*/
public function enqueueScripts()
{
wp_enqueue_script('my-script', 'path/to/my-script.js', [], null, true);
}
}
```
Then, call the `annotations` method on the class:
```php
use Blockify\Hooks\Hook;
$my_class = new MyPlugin();
Hook::annotations( $my_class );
```