wp-hooks / wordpress-core
All the actions and filters from WordPress core in machine-readable JSON format.
Fund package maintenance!
johnbillion
Installs: 151 441
Dependents: 2
Suggesters: 0
Security: 0
Stars: 116
Watchers: 5
Forks: 5
Open Issues: 1
Requires (Dev)
- erusev/parsedown: 1.8.0-beta-7
- oomphinc/composer-installers-extender: ^2
- roots/wordpress-core-installer: ^1.0.0
- roots/wordpress-full: 6.6-RC4
- wp-hooks/generator: 0.9.0
Replaces
- dev-develop
- 1.8.0
- 1.7.0
- 1.6.0
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.0
- 0.9.0
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.1
- 0.7.0
- 0.6.1
- 0.6.0
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.4
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.1
- 0.2.0
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.2
- 0.1.1
- 0.1.0
- dev-wp-66
- dev-master
- dev-wp64
- dev-cron-hooks
This package is auto-updated.
Last update: 2024-11-15 20:37:00 UTC
README
All the actions and filters from WordPress core in machine-readable JSON format.
Last updated for WordPress 6.6.
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 ( false !== strpos( $hook['name'], $search ) ); } ); 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 => ( null !== hook.name.match( search ) ) ); 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
- The actions can be found in hooks/actions.json
- The filters can be found in hooks/filters.json
- The JSON schema can be found in hooks/schema.json
- The TypeScript interfaces can be found in interface/index.d.ts
What can I use this for?
Anything that needs programmatic access to a list of available hooks, for example:
- Autocomplete WordPress action and filter names in VS Code
- Autocomplete WordPress action and filter names in Vim
- WordPress plugin for Psalm
Regenerating the Hook Files
Change the roots/wordpress-full
version in composer.json to the required WordPress version, or dev-main
for nightly.
Install the dependencies:
npm i && composer i
Then run:
composer generate
Some scripts are available for checking the data:
- Check everything:
npm run check
- Find hooks with missing
@since
tags:jq '.hooks[] | . as $d | .doc .tags | map(.name) | select( contains(["since"]) | not ) | $d' hooks/filters.json
jq '.hooks[] | . as $d | .doc .tags | map(.name) | select( contains(["since"]) | not ) | $d' hooks/actions.json
- Find hooks with incorrect number of
@param
tags (not completely accurate, not sure why):jq '.hooks[] | select( .args == ( .doc.tags | map(.name) | select( contains(["param"]) ) | length ) ) | .name' hooks/filters.json
jq '.hooks[] | select( .args == ( .doc.tags | map(.name) | select( contains(["param"]) ) | length ) ) | .name' hooks/actions.json
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:
Plus all my kind sponsors on GitHub: