我在哪里可以找到所有WordPress钩子和过度拖欠功能(可插入,可拼写等)的列表?

编辑: 插件是 在这里列出.

有帮助吗?

解决方案

@Arlen:正如基思(Keith S)指出的那样 亚当·布朗(Adam Brown)的钩子清单 是WordPress的挂钩的Defatto资源。但是,这并不完美:

  • 它不会按照何时被调用的顺序显示钩子
  • 它不提供调用的文件名或行号,
  • 它没有提供许多通过的参数,
  • 这不是一个完整的列表,因为某些钩子可以动态地称为
  • 而且它不会显示插件的钩子。

因此,尽管亚当的列表是一个很好的资源,尤其是了解何时添加钩子的何时添加了钩子,但它并不像能够在自己网站上的任何给定页面上启动钩子那样有用。

我已经在玩这个想法了一段时间,所以您的问题触发了我写一个 插入 被称为WordPress的仪表钩“你可以找到 下面的完整来源 屏幕截图,您也可以 从GIST下载 这里.

因此,这是仪器外观的屏幕截图:

Screenshot of Instrument Hooks for WordPress Plugin in action

您使用URL参数触发仪器 instrument=hooks, , IE:

http://example.com?instrument=hooks

正如承诺的那样,这是来源(或下载它 这里.):

<?php
/*
Plugin Name: Instrument Hooks for WordPress
Description: Instruments Hooks for a Page. Outputs during the Shutdown Hook.
Version: 0.1
Author: Mike Schinkel
Author URI: http://mikeschinkel.com
*/

if ($_GET['instrument']=='hooks') {

    add_action('shutdown','instrument_hooks');
    function instrument_hooks() {
        global $wpdb;
        $hooks = $wpdb->get_results("SELECT * FROM wp_hook_list ORDER BY first_call");
        $html = array();
        $html[] = '<style>#instrumented-hook-list table,#instrumented-hook-list th,#instrumented-hook-list td {border:1px solid gray;padding:2px 5px;}</style>
<div align="center" id="instrumented-hook-list">
    <table>
        <tr>
        <th>First Call</th>
        <th>Hook Name</th>
        <th>Hook Type</th>
        <th>Arg Count</th>
        <th>Called By</th>
        <th>Line #</th>
        <th>File Name</th>
        </tr>';
        foreach($hooks as $hook) {
            $html[] = "<tr>
            <td>{$hook->first_call}</td>
            <td>{$hook->hook_name}</td>
            <td>{$hook->hook_type}</td>
            <td>{$hook->arg_count}</td>
            <td>{$hook->called_by}</td>
            <td>{$hook->line_num}</td>
            <td>{$hook->file_name}</td>
            </tr>";
        }
        $html[] = '</table></div>';
        echo implode("\n",$html);
    }

    add_action('all','record_hook_usage');
    function record_hook_usage($hook){
        global $wpdb;
        static $in_hook = false;
        static $first_call = 1;
        static $doc_root;
        $callstack = debug_backtrace();
        if (!$in_hook) {
            $in_hook = true;
            if ($first_call==1) {
                $doc_root = $_SERVER['DOCUMENT_ROOT'];
                $results = $wpdb->get_results("SHOW TABLE STATUS LIKE 'wp_hook_list'");
                if (count($results)==1) {
                    $wpdb->query("TRUNCATE TABLE wp_hook_list");
                } else {
                    $wpdb->query("CREATE TABLE wp_hook_list (
                    called_by varchar(96) NOT NULL,
                    hook_name varchar(96) NOT NULL,
                    hook_type varchar(15) NOT NULL,
                    first_call int(11) NOT NULL,
                    arg_count tinyint(4) NOT NULL,
                    file_name varchar(128) NOT NULL,
                    line_num smallint NOT NULL,
                    PRIMARY KEY (first_call,hook_name))"
                    );
                }
            }
            $args = func_get_args();
            $arg_count = count($args)-1;
            $hook_type = str_replace('do_','',
                str_replace('apply_filters','filter',
                    str_replace('_ref_array','[]',
                        $callstack[3]['function'])));
            $file_name = str_replace($doc_root,'',$callstack[3]['file']);
            $line_num = $callstack[3]['line'];
            $called_by = $callstack[4]['function'];
            $wpdb->query("INSERT wp_hook_list
                (first_call,called_by,hook_name,hook_type,arg_count,file_name,line_num)
                VALUES ($first_call,'$called_by()','$hook','$hook_type',$arg_count,'$file_name',$line_num)");
            $first_call++;
            $in_hook = false;
        }
    }
}

其他提示

调试栏动作钩插件

显示针对当前请求发射的动作列表。需要调试栏插件。

该法典有一个 动作参考过滤器参考. 。亚当·布朗创造了一个 钩数据库 它在源代码中具有所有挂钩,并从Wiki页面,版本信息和链接到源代码中添加文档。您可以通过在法典中编写文档来改进它。

当然,有些钩子是动态的,具体取决于其他数据。拿 wp_transition_post_status 功能:

function wp_transition_post_status($new_status, $old_status, $post) {
    do_action('transition_post_status', $new_status, $old_status, $post);
    do_action("${old_status}_to_$new_status", $post);
    do_action("${new_status}_$post->post_type", $post->ID, $post);
}

如果您注册自定义帖子类型 event 和自定义帖子状态 cancelled, ,你会有一个 cancelled_event 动作钩。

虽然原始,但此插件代码也许可以提供帮助?如果要查看过滤器,请切换使用“ add_filter”的“ add_action”。加载插件,然后刷新网站的主页。加载后,停用的痛苦是严重的痛苦,因此只需在插件文件夹下重命名插件文件,然后再次刷新站点 - 它将自动停用。我已经使用了很多时间来解决问题或找到可以插入一些东西的地方。

<?php
/*
Plugin Name: Hooks
Plugin URI: http://example.com/
Description: Hooks
Version: 1.00
Author: Hooks
Author URI: http://example.com/
*/

add_action('all','hook_catchall');
function hook_catchall(&$s1 = '', &$s2 = '', &$s3 = '', &$s4 = '') {
    echo "<h1>1</h1>\n";
    print_r($s1);
    echo "<br />\n";
    echo "<h1>2</h1>\n";
    print_r($s2);
    echo "<br />\n";
    echo "<h1>3</h1>\n";    
    print_r($s3);
    echo "<br />\n";
    echo "<h1>4</h1>\n";    
    print_r($s4);
    echo "<br />\n";
    return $s1;
}

我用这一点找到钩子的顺序。得到 filters 只是改变 add_actionadd_filter.

function echo_all_hooks() {
$not_arr = array('gettext','sanitize_key','gettext_with_context','attribute_escape');
if(!in_array(current_filter(),$not_arr)) echo current_filter()."<br/>";
}
add_action('all','echo_all_hooks');

@Kaiser建议不要仅发布链接,我正在改进它。但是在这里不可能使用整个代码,因此我在此处使用很少的图像来解释它如何具有描述每个图形的WordPress挂钩的完整列表。你可以在这里找到它 钩子, 课程, 功能, 插件, enter image description here

描述每个人enter image description here

您只能使用查询监视器插件: https://wordpress.org/plugins/query-monitor/

enter image description here

许可以下: CC-BY-SA归因
scroll top