WordPressのすべてのフックとオーバーライド可能な関数(プラガブル、スクリプト可能など)のリストはどこにありますか?
編集:プラグインはここにリストされています。
WordPressのすべてのフックとオーバーライド可能な関数(プラガブル、スクリプト可能など)のリストはどこにありますか?
編集:プラグインはここにリストされています。
回答:
@Arlen:Keith Sが指摘するように、Adam Brownのフックのリストは WordPressのフックの事実上のリソースです。ただし、完璧ではありません。
そのため、Adamのリストは特にフックが歴史的に追加された時期を理解するための優れたリソースですが、自分のサイトの特定のページでフックを装備できるほど有用ではありません。
私はしばらくこのアイデアをいじっていたので、あなたの質問がきっかけで、「Instrument Hooks for WordPress」というプラグインを書くことになりました。あなたは見つけることができます以下の完全なソースのスクリーンショットを、あなたもすることができますすることができ要旨からダウンロードしてくださいここに。
インストルメンテーションがどのように見えるかのスクリーンショットは次のとおりです。

URLパラメーターを使用して、インストルメンテーションをトリガーします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;
        }
    }
}
              コーデックスには、アクション参照とフィルター参照があります。Adam Brown は、ソースコードにすべてのフックを持つフックデータベースを作成し、Wikiページ、バージョン情報、およびソースコードへのリンクからドキュメントを追加します。Codexでドキュメントを書くことで改善できます。
もちろん、他のデータに応じて、いくつかのフックは動的です。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_action」を「add_filter」に切り替えます。プラグインをロードしてから、サイトのホームページを更新します。一度ロードすると、非アクティブ化するのは非常に苦痛なので、プラグインフォルダーの下のプラグインファイルの名前を変更し、サイトを再度更新するだけで、自動的に非アクティブ化されます。私はこのトリックを何度も使ってトラブルシューティングをしたり、何かを挿入できる場所を見つけました。
<?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;
}
              クエリモニタープラグインを使用できます:https : //wordpress.org/plugins/query-monitor/