johnbillion/wp-hooks

This package is abandoned and no longer maintained. The author suggests using the wp-hooks/wordpress-core package instead.

All the actions and filters from WordPress core in machine-readable JSON format.

Fund package maintenance!
johnbillion

Installs: 143 293

Dependents: 0

Suggesters: 0

Security: 0

Stars: 123

Watchers: 6

Forks: 6

Open Issues: 1

Language:Shell

pkg:composer/johnbillion/wp-hooks

1.10.0 2025-04-16 22:20 UTC

README

All the actions and filters from WordPress core in machine-readable JSON format.

Last updated for WordPress 6.8.

Installation

  • As a Composer package for use in PHP:
    composer require wp-hooks/wordpress-core
  • As an npm package for use in JavaScript or TypeScript:
    npm install @wp-hooks/wordpress-core

Usage in PHP

// Get hooks as JSON:
$actions_json = file_get_contents( 'vendor/wp-hooks/wordpress-core/hooks/actions.json' );
$filters_json = file_get_contents( 'vendor/wp-hooks/wordpress-core/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 in JavaScript

// Get hooks as array of objects:
const actions = require('@wp-hooks/wordpress-core/hooks/actions.json').hooks;
const filters = require('@wp-hooks/wordpress-core/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);

Importing in TypeScript

import { hooks as actions } from '@wp-hooks/wordpress-core/hooks/actions.json';
import { hooks as filters } from '@wp-hooks/wordpress-core/hooks/filters.json';

Interfaces for the components of the hooks can be imported too, if you need them:

import { Hooks, Hook, Doc, Tags, Tag } from '@wp-hooks/wordpress-core/interface';

Actions, Filters, and Schemas

What can I use this for?

Anything that needs programmatic access to a list of available hooks, for example:

Regenerating the Hook Files

Change the roots/wordpress-full version in composer.json to one of:

  • The required major version, such as 6.8
  • dev-main for nightlies prior to RC
  • An RC version, such as 6.9-RC1

Install the dependencies:

npm i && composer i

Then run:

composer generate

During generation, a change and data integrity issues are saved in CHANGELOG.md and ISSUES.md respectively.

Hook Files for Plugins

Do you want the same hook files for your favourite plugins? The hook files in this repo are generated using wp-hooks-generator. It can generate hook files for WordPress plugins and themes as well as core.

Sponsors

The time that I spend maintaining this library and others is in part sponsored by:

Automattic

ServMask

Plus all my kind sponsors on GitHub:

Sponsors

Click here to find out about supporting my open source tools and plugins.