PHPackages                             akirk/extract-wp-hooks - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. akirk/extract-wp-hooks

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

akirk/extract-wp-hooks
======================

Extract available WordPress hooks for a Github Wiki

1.4.0(3mo ago)732.5k↑2200%1[2 issues](https://github.com/akirk/extract-wp-hooks/issues)1GPL-2.0-or-laterPHPPHP &gt;=7.4CI passing

Since Jul 25Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/akirk/extract-wp-hooks)[ Packagist](https://packagist.org/packages/akirk/extract-wp-hooks)[ RSS](/packages/akirk-extract-wp-hooks/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (21)Used By (1)

extract-hooks
=============

[](#extract-hooks)

This script is intended for WordPress plugins that provide hooks that can be used by other plugins. By parsing its source code, it creates a documentation in a Github wiki.

You can configure this tool either through a JSON configuration file or directly through GitHub Action inputs. For local usage, you'll need a configuration file, but for GitHub Actions, you can specify all configuration directly in your workflow file.

Examples
--------

[](#examples)

-  (extracted from [example.php](https://github.com/akirk/extract-hooks/blob/main/example.php))
-
-

How it works
------------

[](#how-it-works)

The PHP script doesn't have any dependencies. It uses PHP's internal parser (using [`token_get_all`](https://www.php.net/manual/en/function.token-get-all.php)) to identify PHP function calls to `apply_filters()` or `do_action()`.

It generates a markdown file for each filter which is suitable for a Github wiki. The page contains potentially provided documentation (via a comment in the source code), an (auto-generated) example, parameters, return value, references to the source code (including extracted source snippet).

### Example: Provide Documentation Via a Comment

[](#example-provide-documentation-via-a-comment)

For each filter, it looks at the comment preceeding the filter, so that you can document it, for example:

```
/*
 * This is example filter 1.
 *
 * @param string $text The text to modify.
 * @param string $mode Extra information that might be useful.
 * @return string The modified text.
 */
$result = apply_filters( 'example_filter1', $text, $mode );
```

This will generate an [example\_filter1.md](https://github.com/akirk/extract-hooks/wiki/example_filter1) that contains the text `This is an example filter` and a list of parameters and return value:

> # example\_filter1
>
> [](#example_filter1)
>
> This is an example filter.
>
> ## Parameters
>
> [](#parameters)
>
> - `string` `$text` The text to modify.
> - `string` `$mode` Extra information that might be useful.
>
> ## Returns
>
> [](#returns)
>
> `string` The modified text.

But not only that, it will contain an auto-generated example:

> ## Auto-generated Example
>
> [](#auto-generated-example)
>
> ```
> add_filter(
>     'example_filter1',
>     function(
>         string $text,
>         string $mode
>     ) {
>         // Your code
>         return $text;
>     },
>     10,
>     2
> );
> ```

### Provide an Example

[](#provide-an-example)

You can also provide your own example in the comment, that will override the auto-generated example:

```
/*
 * This is example filter 2.
 *
 * Example:
 * ```php
 * add_filter( 'example_filter2', function ( $text ) {
 *     return strtolower( $text );
 * } );
 * ```
 *
 * @param string $text The text to modify.
 * @param string $mode Extra information that might be useful.
 * @return string The modified text.
 */
$result = apply_filters( 'example_filter2', $text, $mode );
```

It generates this output: [example\_filter2](https://github.com/akirk/extract-hooks/wiki/example_filter2)

> ## Example
>
> [](#example)
>
> ```
> add_filter( 'example_filter2', function ( $text ) {
>     return strtolower( $text );
> } );
> ```

### No Documentation

[](#no-documentation)

Finally, if you have an filter without any documentation, the script attempts to create a useful auto-generated example. So suppose you have code

```
$result = apply_filters( 'example_filter3', $text, $mode );

```

It generates this output: [example\_filter3](https://github.com/akirk/extract-hooks/wiki/example_filter3)

> ## Auto-generated Example
>
> [](#auto-generated-example-1)
>
> ```
> add_filter(
>     'example_filter3',
>     function (
>         $text,
>         $mode
>     ) {
>         // Your code here
>         return $text;
>     },
>     10,
>     2
> );
> ```
>
>
>
> ## Parameters
>
> [](#parameters-1)
>
> - `$text`
> - `$mode`

Install
-------

[](#install)

### Option 1: GitHub Action (Recommended)

[](#option-1-github-action-recommended)

Add the following workflow file to your WordPress plugin repository at `.github/workflows/extract-hooks.yml`:

```
name: Extract WordPress Hooks

on:
  push:
    branches: [ main, master ]
    paths: [ '**.php' ]
  workflow_dispatch:

jobs:
  extract-hooks:
    runs-on: ubuntu-latest
    permissions:
      contents: write  # Required to push to wiki repository
    steps:
    - uses: actions/checkout@v4
    - uses: akirk/extract-wp-hooks@main
```

This will automatically extract hooks from your PHP files and update your GitHub wiki whenever you push changes.

#### Configuration

[](#configuration)

You can configure the action in two ways:

1. **Using action inputs (recommended):**

```
- uses: akirk/extract-wp-hooks@main
  with:
    namespace: "My_Plugin"
    base-dir: "."
    wiki-directory: "wiki"
    exclude-dirs: "vendor,tests,node_modules"
    ignore-filters: "debug_hook,internal_filter"
    section: "file"
```

2. **Using a configuration file:**

Create an `.extract-wp-hooks.json` file in your repository root:

```
{
    "namespace": "My_Plugin", // PHP Namespace used in the project.
    "base_dir": ".", // The directory to analyse for php files.
    "wiki_directory": "wiki", // Where the files will be written to.
    "github_blob_url": "https://github.com/username/my-plugin/blob/main/", // This is the base url for the links to the source files.
    "exclude_dirs": ["vendor", "tests"],
    "ignore_filter": ["debug_hook", "internal_filter"]
}
```

#### Available Action Inputs

[](#available-action-inputs)

InputDescriptionDefault`namespace`PHP Namespace that's used`base-dir`Base directory to scan for hooks`.``wiki-directory`Directory to store wiki files`wiki``github-blob-url`GitHub blob URL for source linksAuto-generated from repository`exclude-dirs`Comma-separated list of directories to exclude`vendor,node_modules``ignore-filters`Comma-separated list of filter names to ignore`ignore-regex`Regex pattern to ignore filter names`section`How to group hooks in documentation: 'file' or 'dir'`file``wiki-repo`Wiki repository URL (e.g., username/repo.wiki.git)Auto-generated from repository`config-file`Path to config file (optional if other inputs are provided)`.extract-wp-hooks.json`### Option 2: Composer

[](#option-2-composer)

Via composer:

```
composer require --dev akirk/extract-wp-hooks

```

You will then be able to run `extract-wp-hooks.php` from the vendor bin directory:

```
./vendor/bin/extract-wp-hooks.php

```

Place a `.extract-wp-hooks.json` or `extract-wp-hooks.json` in your project directory to use it.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance74

Regular maintenance activity

Popularity35

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~20 days

Recently: every ~2 days

Total

9

Last Release

107d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d4e1c2b807f44f821b9391c5501a2682aa0cbc1b598cf1952842f382d72d023b?d=identicon)[akirk](/maintainers/akirk)

---

Top Contributors

[![akirk](https://avatars.githubusercontent.com/u/203408?v=4)](https://github.com/akirk "akirk (140 commits)")[![obenland](https://avatars.githubusercontent.com/u/1398304?v=4)](https://github.com/obenland "obenland (16 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/akirk-extract-wp-hooks/health.svg)

```
[![Health](https://phpackages.com/badges/akirk-extract-wp-hooks/health.svg)](https://phpackages.com/packages/akirk-extract-wp-hooks)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
