あるフィルターに適用された関数(フック)をすべて出力する
the_content
などのフィルタに現在適用されているフィルタを確認したかったので、
特定のフィルタにフックされている関数をすべて取得する方法について調査しました。
都合よく stackoverflow に掲載されていたので、それを利用させてもらいます。
フィルタフックをすべて出力するコード
次の print_filters_for
関数は、print_filters_for('the_content')
のように、
フィルタ名を指定して実行すると、そのフィルタにフックされているすべての関数が出力されます。
この関数では出力して確認していますが、単純に取得するときは $wp_filter[$filtername]
を上手く利用すればよいと思います。
function print_filters_for($filtername)
{
global $wp_filter;
print "<pre>";
print_r($wp_filter[$filtername]);
print "</pre>";
}
the_content の出力例
都合上多少弄ってありますが、ほぼ初期状態の WordPress で function print_filters_for('the_content')
を実行した結果は次の通りです。
Array
(
[11] => Array
(
[capital_P_dangit] => Array
(
[function] => capital_P_dangit
[accepted_args] => 1
)
[do_shortcode] => Array
(
[function] => do_shortcode
[accepted_args] => 1
)
)
[10] => Array
(
[wptexturize] => Array
(
[function] => wptexturize
[accepted_args] => 1
)
[convert_smilies] => Array
(
[function] => convert_smilies
[accepted_args] => 1
)
----中略----
[shortcode_unautop] => Array
(
[function] => shortcode_unautop
[accepted_args] => 1
)
[prepend_attachment] => Array
(
[function] => prepend_attachment
[accepted_args] => 1
)
)
[8] => Array
(
[00000000000000000000000000000000run_shortcode] => Array
(
[function] => Array
(
[0] => WP_Embed Object
(
[handlers] => Array
(
)
[post_ID] =>
[usecache] => 1
[linkifunknown] => 1
[return_false_on_fail] =>
)
[1] => run_shortcode
)
[accepted_args] => 1
)
[00000000000000000000000000000000autoembed] => Array
(
[function] => Array
(
[0] => WP_Embed Object
(
[handlers] => Array
(
)
[post_ID] =>
[usecache] => 1
[linkifunknown] => 1
[return_false_on_fail] =>
)
[1] => autoembed
)
[accepted_args] => 1
)
)
)