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 for WordPress core
PHP 8.3 or higher.
composer require wp-hooks/generator./bin/wp-hooks-generator --input=src --output=hooks// 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 );// 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);You can ignore files or directories in two ways:
./vendor/bin/wp-hooks-generator --input=src --output=hooks --ignore-files="ignore/this,ignore/that"
"extra": {
    "wp-hooks": {
        "ignore-files": [
            "ignore/this",
            "ignore/that"
        ]
    }
}You can ignore hooks in two ways:
./vendor/bin/wp-hooks-generator --input=src --output=hooks --ignore-hooks="this_hook,that_hook"
"extra": {
    "wp-hooks": {
        "ignore-hooks": [
            "this_hook",
            "that_hook"
        ]
    }
}The TypeScript interfaces for the hook files can be found in interface/index.d.ts. Usage:
import { Hooks, Hook, Doc, Tags, Tag } from 'hooks/index.d.ts';The JSON schema for the hook files can be found in schema.json.