$wp_filterに登録されているインデックス順は実行順とは無関係
$wp_filterに登録されるデータはWordPressのアクション、フィルターであるような
記述を見かけたので、実際にそうなのか?と思いデータを探ってみた所、
あまり直接参照しても意味はなさそうでしたのでご紹介しておきます。
概要 [表示]
$wp_filterに登録されているインデックス順は実行順とは無関係
WordPressのグルーバル変数「$wp_filter」フィルター(アクション)フックの
実行順序を知る手掛かりにならないかと思い、探ってみました。
今回、テストで参照した「$wp_filter」内のキーを順に出力してみた結果が、
以下のようになっていました。
一見すると、なんとなく順序通りになっていそうにも見えて、
もしかしてこの順序なんじゃないの!?と期待してしまいそうになります。
抜く処理に関しては以前の記事の方法を取っていますが、
結果、誤りでしたのでこちらに転記しておきます。
ざっくりこんな感じで抜いています。
Debug BarとWordPress公式の順と比較
Debug Barプラグインによる出力「Action Hooks」を抜き出したものを一覧化し、
またWordPressの公式サイトには以下のヘルプ記載の
「一般的リクエスト中に実行されるアクション」の項目から抜き出したリストを、
それぞれナンバリングして突合せを行いました。
一番右が「$wp_filter」配列のキーの番号(配列順)を示しています。
「Action Hooks」出力とWordPressヘルプの順は、
環境による有無の差異はありながらも、順番は概ね同一順です。
しかし、「$wp_filter」配列のキーの番号はバラバラという結果でした。
しかもアクションフックとしてリストされているものが取れる訳でもなく、
あったりなかったりが激しい事から、直接覗いても手掛かりにはならなそうな印象を受けます。
Debug Bar のAction Hooks出力 | WordPress(公式順序例) | $wp_filter | |
---|---|---|---|
1. muplugins_loaded | 1 | muplugins_loaded | - |
2. registered_taxonomy | 2 | registered_taxonomy | - |
3. registered_post_type | 3 | registered_post_type | - |
4. plugins_loaded | 4 | plugins_loaded | 156 |
5. sanitize_comment_cookies | 5 | sanitize_comment_cookies | 152 |
6. wp_roles_init | - | - | - |
7. setup_theme | 6 | setup_theme | - |
8. unload_textdomain | 7 | load_textdomain | - |
9. load_textdomain | - | - | - |
10. after_setup_theme | 8 | after_setup_theme | 264 |
11. auth_cookie_malformed | 9 | auth_cookie_malformed | 122 |
12. auth_cookie_valid | 10 | auth_cookie_valid | 126 |
13. set_current_user | 11 | set_current_user | 209 |
14. init | 12 | init | 131 |
15. widgets_init | 13 | └─ widgets_init | 268 |
16. register_sidebar | 14 | register_sidebar | 269 |
17. wp_register_sidebar_widget | 15 | wp_register_sidebar_widget | 270 |
18. wp_default_scripts | 16 | wp_default_scripts | 210 |
19. add_option | - | - | - |
20. add_option__transient_doing_cron | - | - | - |
21. added_option | - | - | - |
22. set_transient_doing_cron | - | - | - |
23. setted_transient | - | - | - |
24. requests-requests.before_request | - | - | - |
25. requests-curl.before_request | - | - | - |
26. http_api_curl | - | - | - |
27. requests-curl.before_send | - | - | - |
28. requests-curl.after_send | - | - | - |
29. requests-curl.after_request | - | - | - |
30. requests-requests.before_parse | - | - | - |
31. http_api_debug | - | - | - |
32. wp_default_styles | 17 | wp_default_styles | 216 |
- | 18 | admin_bar_init | 300 |
- | 19 | add_admin_bar_menus | - |
33. wp_loaded | 20 | wp_loaded | 195 |
34. update_option | - | - | - |
35. update_option_rewrite_rules | - | - | - |
36. updated_option | - | - | - |
37. generate_rewrite_rules | - | - | 303 |
38. parse_request | 21 | parse_request | 194 |
39. send_headers | 22 | send_headers | 271 |
40. parse_query | 23 | parse_query | 272 |
41. pre_get_posts | 24 | pre_get_posts | 266 |
42. posts_selection | 25 | posts_selection | 273 |
43. wp | 26 | wp | 274 |
44. template_redirect | 27 | template_redirect | 121 |
45. admin_bar_init | - | - | 300 |
46. debug_bar_enqueue_scripts | - | - | - |
47. add_admin_bar_menus | - | - | - |
48. get_header | 28 | get_header | 275 |
- | 30 | twentyeleven_enqueue_color_scheme (Twenty Eleven 特有) | - |
49. wp_head | 31 | wp_head | 120 |
50. wp_enqueue_scripts | 29 | wp_enqueue_scripts | 211 |
51. wp_print_styles | 32 | wp_print_styles | 133 |
52. wp_print_scripts | 33 | wp_print_scripts | 213 |
53. get_template_part_template-parts/header/header | - | - | - |
54. get_template_part_template-parts/header/site | - | - | - |
55. get_template_part_template-parts/navigation/navigation | - | - | - |
56. parse_tax_query | - | - | - |
- | 34 | get_search_form | 282 |
57. loop_start | 35 | loop_start | 277 |
58. the_post | 36 | the_post | 278 |
59. get_template_part_template-parts/page/content | 37 | get_template_part_content | - |
60. loop_end | 38 | loop_end | 279 |
- | 39 | get_sidebar | 280 |
- | 40 | dynamic_sidebar | 281 |
- | 41 | get_search_form | 282 |
- | 42 | pre_get_comments | - |
- | 43 | wp_meta | 283 |
61. get_footer | 44 | get_footer | 284 |
- | 45 | get_sidebar | 280 |
- | twentyeleven_credits (Twenty Eleven 特有) | - | |
62. get_template_part_template-parts/footer/footer | - | - | - |
63. get_template_part_template-parts/footer/site | - | - | - |
64. wp_footer | 47 | wp_footer | 129 |
65. wp_print_footer_scripts | 48 | wp_print_footer_scripts | 130 |
66. admin_bar_menu | 49 | admin_bar_menu | 263 |
67. wp_before_admin_bar_render | 50 | wp_before_admin_bar_render | - |
68. wp_after_admin_bar_render | 51 | wp_after_admin_bar_render | - |
- | 52 | shutdown | - |
結論として、アクション・フィルターの実行順を知りたい場合には、
とりあえずのところ、以下のプラグインを導入して確認する方がいいと思います。
Debug Bar (←本体)
Debug Bar Extender (←拡張用)
Debug Bar Actions and Filters Addon (←コレ)
ご参考になれば幸いです。
当サイト内のコンテンツおよび画像を含むすべてにおいて、管理人アルゴリズンが著作権を保持しております。
当サイトでご紹介しております写真等につきましては著作権の放棄はしませんが、
ライセンスフリーでご利用いただいて構いません。
コンテンツを有益であると感じていただけましたら非常に光栄です。
ありがとうございます。
サイト内コンテンツを引用される際には、出典元として当サイト(個別記事)へのリンクをお願いいたします。
申し訳ございませんが、無断転載、複製をお断りさせて頂いております。
公開日: