npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wp-hooks/wordpress-core

v1.8.0

Published

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

Downloads

18

Readme

WordPress Hooks Reference

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

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 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:

Automattic

Plus all my kind sponsors on GitHub:

Sponsors

Click here to find out about supporting this library and my other WordPress development tools and plugins.