Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wp-hooks/generator
Generates a JSON representation of the WordPress actions and filters in your code
https://github.com/wp-hooks/generator
wordpress
Last synced: 4 days ago
JSON representation
Generates a JSON representation of the WordPress actions and filters in your code
- Host: GitHub
- URL: https://github.com/wp-hooks/generator
- Owner: wp-hooks
- Created: 2019-11-18T11:28:49.000Z (about 5 years ago)
- Default Branch: trunk
- Last Pushed: 2024-12-04T22:35:46.000Z (24 days ago)
- Last Synced: 2024-12-17T22:05:47.419Z (11 days ago)
- Topics: wordpress
- Language: PHP
- Homepage: https://packagist.org/packages/wp-hooks/generator
- Size: 546 KB
- Stars: 78
- Watchers: 1
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# WP Hooks Generator
Generates a JSON representation of the WordPress actions and filters in your code. Can be used with WordPress plugins, themes, and core.
Note: If you just want the hook files without generating them yourself, use the following packages instead:
* [wp-hooks/wordpress-core](https://github.com/wp-hooks/wordpress-core) for WordPress core
## Requirements
PHP 8.3 or higher.
## Installation
```shell
composer require wp-hooks/generator
```## Generating the Hook Files
```shell
./bin/wp-hooks-generator --input=src --output=hooks
```## Usage of the Generated Hook Files in PHP
```php
// Get hooks as JSON:
$actions_json = file_get_contents( 'hooks/actions.json' );
$filters_json = file_get_contents( 'hooks/filters.json' );// Convert hooks to PHP:
$actions = json_decode( $actions_json, true )['hooks'];
$filters = json_decode( $filters_json, true )['hooks'];// Search for filters matching a string:
$search = 'permalink';
$results = array_filter( $filters, function( array $hook ) use ( $search ) {
return ( strpos( $hook['name'], $search ) !== false );
} );var_dump( $results );
```## Usage of the Generated Hook Files in JavaScript
```js
// Get hooks as array of objects:
const actions = require('hooks/actions.json').hooks;
const filters = require('hooks/filters.json').hooks;// Search for actions matching a string:
const search = 'menu';
const results = actions.filter( hook => ( hook.name.match( search ) !== null ) );console.log(results);
```## Ignoring Files or Directories
You can ignore files or directories in two ways:
### On the Command Line
./vendor/bin/wp-hooks-generator --input=src --output=hooks --ignore-files="ignore/this,ignore/that"
### In composer.json
```json
"extra": {
"wp-hooks": {
"ignore-files": [
"ignore/this",
"ignore/that"
]
}
}
```## Ignoring Hooks
You can ignore hooks in two ways:
### On the Command Line
./vendor/bin/wp-hooks-generator --input=src --output=hooks --ignore-hooks="this_hook,that_hook"
### In composer.json
```json
"extra": {
"wp-hooks": {
"ignore-hooks": [
"this_hook",
"that_hook"
]
}
}
```## TypeScript Interfaces for the Hook Files
The TypeScript interfaces for the hook files can be found in [`interface/index.d.ts`](interface/index.d.ts). Usage:
```typescript
import { Hooks, Hook, Doc, Tags, Tag } from 'hooks/index.d.ts';
```## JSON Schema for the Hook Files
The JSON schema for the hook files can be found in [`schema.json`](schema.json).