devuri/wp-hook-scanner 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

devuri/wp-hook-scanner

Composer 安装命令:

composer require devuri/wp-hook-scanner

包简介

Scans PHP files for WordPress hooks and outputs a categorized report or JSON.

README 文档

README

A PHP tool that scans your codebase for WordPress hooks (add_action, do_action, add_filter, apply_filters) and generates categorized reports.

Perfect for:

  • Documenting hooks in your WordPress plugins and themes
  • CI/CD pipelines to track hook changes between releases
  • Code audits to understand hook dependencies

Requirements

  • PHP 8.1 or higher

Installation

Install via Composer:

composer require --dev devuri/wp-hook-scanner

Or add to your composer.json:

{
    "require-dev": {
        "devuri/wp-hook-scanner": "^1.0"
    }
}

Usage

Command Line

Pretty output (default):

vendor/bin/scan-hooks src

Output:

  Hook Scanner v1.0
  ══════════════════════════════════════════════════

  ▶ Registered Actions (3)
  ────────────────────────────────────────────────
    ✓ admin_init → src/Admin.php:45
    ✓ init → src/Plugin.php:23
    ✓ wp_loaded → src/Bootstrap.php:12

  ⚡ Fired Actions (2)
  ────────────────────────────────────────────────
    ✓ my_plugin_loaded → src/Plugin.php:30
    ✓ my_custom_event (2 occurrences)

  ══════════════════════════════════════════════════
  Summary: 5 unique hooks found
  3 registered actions · 2 fired actions

JSON output:

vendor/bin/scan-hooks src --json

All options:

vendor/bin/scan-hooks [directory] [options]

Options:
  --json                 Output results as JSON
  --update               Create/update snapshot file
  --check                Compare against snapshot (for CI)
  --snapshot=<path>      Custom snapshot file path (default: .hooks-snapshot.json)
  --no-color             Disable colored output
  --help, -h             Show help message
  --version, -v          Show version information

Snapshot Mode (CI/CD)

Track hook changes across releases using snapshots:

Create a snapshot:

vendor/bin/scan-hooks src --update

This creates .hooks-snapshot.json containing all current hooks.

Check against snapshot:

vendor/bin/scan-hooks src --check

Returns exit code 0 if hooks match, 1 if there are differences.

Custom snapshot path:

vendor/bin/scan-hooks src --update --snapshot=hooks.json
vendor/bin/scan-hooks src --check --snapshot=hooks.json

GitHub Actions Example

name: Hook Check

on: [push, pull_request]

jobs:
  hooks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.1'
          
      - name: Install dependencies
        run: composer install --no-progress
        
      - name: Check hooks
        run: vendor/bin/scan-hooks src --check

Programmatic Usage

use WPHookScanner\HookScanner;

$scanner = new HookScanner();
$scanner->scan('src');

// Get all hooks as array
$hooks = $scanner->toArray();

// Get hooks as JSON
$json = $scanner->toJson();

// Check for specific hook
if ($scanner->hasHook('my_custom_action', 'add_action')) {
    echo "Found it!";
}

// Get hooks by type
$actions = $scanner->getHooksByType('add_action');
$filters = $scanner->getHooksByType('apply_filters');

// Get total count
$total = $scanner->getTotalCount();

// Snapshot operations
$scanner->saveSnapshot('.hooks-snapshot.json');
$snapshot = HookScanner::loadSnapshot('.hooks-snapshot.json');
$diff = $scanner->compareToSnapshot($snapshot);

Hook Types Detected

Type Description Symbol
add_action Registered action hooks
do_action Fired/triggered actions
add_filter Registered filter hooks
apply_filters Applied filter hooks

Output Formats

Pretty Print (Terminal)

Colorized, categorized output ideal for development.

JSON

Machine-readable format for tooling integration:

{
    "add_action": {
        "init": [
            {"file": "src/Plugin.php", "line": 23}
        ],
        "admin_init": [
            {"file": "src/Admin.php", "line": 45}
        ]
    },
    "do_action": { ... },
    "add_filter": { ... },
    "apply_filters": { ... }
}

Snapshot

Normalized format for comparison (excludes line numbers):

{
    "add_action": ["admin_init", "init", "wp_loaded"],
    "do_action": ["my_custom_event", "my_plugin_loaded"],
    "add_filter": ["the_content", "the_title"],
    "apply_filters": ["my_plugin_value"]
}

Testing

Run the test suite:

composer test

Or directly:

vendor/bin/phpunit

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License. See LICENSE for details.

devuri/wp-hook-scanner 适用场景与选型建议

devuri/wp-hook-scanner 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 478 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「wordpress」 「filters」 「scanner」 「hooks」 「actions」 「static-analysis」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 devuri/wp-hook-scanner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 devuri/wp-hook-scanner 我们能提供哪些服务?
定制开发 / 二次开发

基于 devuri/wp-hook-scanner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 478
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 29
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-14