$wp_filterに登録されているインデックス順は実行順とは無関係
$wp_filterに登録されるデータはWordPressのアクション、フィルターであるような
記述を見かけたので、実際にそうなのか?と思いデータを探ってみた所、
あまり直接参照しても意味はなさそうでしたのでご紹介しておきます。
$wp_filterに登録されているインデックス順は実行順とは無関係
WordPressのグルーバル変数「$wp_filter」フィルター(アクション)フックの
実行順序を知る手掛かりにならないかと思い、探ってみました。
今回、テストで参照した「$wp_filter」内のキーを順に出力してみた結果が、
以下のようになっていました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
[0] => query [1] => pre_term_name [2] => pre_comment_author_name [3] => pre_link_name [4] => pre_link_target [5] => pre_link_rel [6] => pre_user_display_name [7] => pre_user_first_name [8] => pre_user_last_name [9] => pre_user_nickname [10] => term_name [11] => comment_author_name [12] => link_name [13] => link_target [14] => link_rel [15] => user_display_name [16] => user_first_name [17] => user_last_name [18] => user_nickname [19] => pre_term_description [20] => pre_link_description [21] => pre_link_notes [22] => pre_user_description [23] => pre_comment_author_email [24] => pre_user_email [25] => comment_author_email [26] => user_email [27] => pre_comment_author_url [28] => pre_user_url [29] => pre_link_url [30] => pre_link_image [31] => pre_link_rss [32] => pre_post_guid [33] => user_url [34] => link_url [35] => link_image [36] => link_rss [37] => comment_url [38] => post_guid [39] => pre_term_slug [40] => wp_insert_post_data [41] => pre_post_type [42] => pre_post_status [43] => pre_post_comment_status [44] => pre_post_ping_status [45] => pre_post_mime_type [46] => post_mime_type [47] => register_meta_args [48] => content_save_pre [49] => excerpt_save_pre [50] => comment_save_pre [51] => pre_comment_content [52] => comment_author [53] => link_description [54] => link_notes [55] => bloginfo [56] => wp_title [57] => widget_title [58] => the_content [59] => the_title [60] => comment_text [61] => single_post_title [62] => single_cat_title [63] => single_tag_title [64] => single_month_title [65] => nav_menu_attr_title [66] => nav_menu_description [67] => term_description [68] => get_the_post_type_description [69] => term_name_rss [70] => wp_insert_post_parent [71] => wp_update_term_parent [72] => the_excerpt [73] => get_the_excerpt [74] => the_post_thumbnail_caption [75] => comment_excerpt [76] => list_cats [77] => wp_sprintf [78] => widget_text [79] => widget_text_content [80] => date_i18n [81] => the_title_rss [82] => the_content_rss [83] => the_content_feed [84] => the_excerpt_rss [85] => comment_author_rss [86] => comment_text_rss [87] => bloginfo_rss [88] => the_author [89] => the_guid [90] => wp_mail [91] => publish_post [92] => publish_page [93] => wp_ajax_save-widget [94] => wp_ajax_widgets-order [95] => customize_save_after [96] => option_ping_sites [97] => option_blog_charset [98] => option_home [99] => option_siteurl [100] => tiny_mce_before_init [101] => teeny_mce_before_init [102] => pre_kses [103] => sanitize_title [104] => check_comment_flood [105] => comment_flood_filter [106] => comment_email [107] => option_tag_base [108] => option_category_base [109] => the_posts [110] => comments_open [111] => pings_open [112] => editable_slug [113] => nav_menu_meta_box_object [114] => pingback_ping_source_uri [115] => xmlrpc_pingback_error [116] => title_save_pre [117] => transition_comment_status [118] => http_request_host_is_external [119] => xmlrpc_rsd_apis [120] => wp_head [121] => template_redirect [122] => auth_cookie_malformed [123] => auth_cookie_expired [124] => auth_cookie_bad_username [125] => auth_cookie_bad_hash [126] => auth_cookie_valid [127] => rest_authentication_errors [128] => publish_future_post [129] => wp_footer [130] => wp_print_footer_scripts [131] => init [132] => after_switch_theme [133] => wp_print_styles [134] => login_head [135] => login_footer [136] => login_init [137] => rss2_head [138] => commentsrss2_head [139] => rss_head [140] => rdf_header [141] => atom_head [142] => comments_atom_head [143] => opml_head [144] => app_head [145] => do_feed_rdf [146] => do_feed_rss [147] => do_feed_rss2 [148] => do_feed_atom [149] => do_pings [150] => do_robots [151] => set_comment_cookies [152] => sanitize_comment_cookies [153] => admin_print_scripts [154] => admin_print_footer_scripts [155] => admin_print_styles [156] => plugins_loaded [157] => shutdown [158] => post_updated [159] => transition_post_status [160] => comment_form [161] => admin_init [162] => welcome_panel [163] => user_request_action_confirmed [164] => wp_privacy_personal_data_exporters [165] => wp_privacy_personal_data_erasers [166] => wp_privacy_delete_old_export_files [167] => wp_scheduled_delete [168] => wp_scheduled_auto_draft_delete [169] => importer_scheduled_cleanup [170] => upgrader_scheduled_cleanup [171] => delete_expired_transients [172] => delete_post [173] => delete_term [174] => begin_fetch_post_thumbnail_html [175] => end_fetch_post_thumbnail_html [176] => attachment_updated [177] => pre_option_gmt_offset [178] => admin_color_scheme_picker [179] => default_option_link_manager_enabled [180] => pre_option_embed_autourls [181] => heartbeat_settings [182] => admin_enqueue_scripts [183] => heartbeat_send [184] => heartbeat_nopriv_send [185] => authenticate [186] => determine_current_user [187] => split_shared_term [188] => wp_split_shared_term_batch [189] => comment_post [190] => after_password_reset [191] => register_new_user [192] => edit_user_created_user [193] => rest_api_init [194] => parse_request [195] => wp_loaded [196] => delete_attachment [197] => save_post [198] => update_option_start_of_week [199] => update_option_gmt_offset [200] => admin_menu [201] => before_delete_post [202] => wp_trash_post [203] => change_locale [204] => request [205] => term_link [206] => get_post_format [207] => get_terms [208] => wp_get_object_terms [209] => set_current_user [210] => wp_default_scripts [211] => wp_enqueue_scripts [212] => admin_print_scripts-index.php [213] => wp_print_scripts [214] => print_scripts_array [215] => customize_controls_print_styles [216] => wp_default_styles [217] => style_loader_src [218] => wp_playlist_scripts [219] => customize_controls_enqueue_scripts [220] => nav_menu_item_id [221] => before_signup_header [222] => activate_header [223] => in_admin_header [224] => media_buttons [225] => image_send_to_editor [226] => media_send_to_editor [227] => rest_pre_serve_request [228] => embed_head [229] => embed_content_meta [230] => embed_footer [231] => excerpt_more [232] => the_excerpt_embed [233] => oembed_dataparse [234] => oembed_response_data [235] => pre_oembed_result [236] => user_has_cap [237] => wp_version_check [238] => load-plugins.php [239] => load-update.php [240] => load-update-core.php [241] => wp_update_plugins [242] => load-themes.php [243] => wp_update_themes [244] => update_option_WPLANG [245] => wp_maybe_auto_update [246] => edit_form_advanced [247] => edit_page_form [248] => wp_ajax_add-category [249] => wp_ajax_add-post_tag [250] => wp_ajax_add-nav_menu [251] => wp_ajax_add-link_category [252] => wp_ajax_add-post_format [253] => future_post [254] => future_page [255] => future_attachment [256] => future_revision [257] => future_nav_menu_item [258] => future_custom_css [259] => future_customize_changeset [260] => future_oembed_cache [261] => future_user_request [262] => debug_bar_panels [263] => admin_bar_menu [264] => after_setup_theme [265] => posts_request [266] => pre_get_posts [267] => wp_redirect [268] => widgets_init [269] => register_sidebar [270] => wp_register_sidebar_widget [271] => send_headers [272] => parse_query [273] => posts_selection [274] => wp [275] => get_header [276] => get_template_part_loop [277] => loop_start [278] => the_post [279] => loop_end [280] => get_sidebar [281] => dynamic_sidebar [282] => get_search_form [283] => wp_meta [284] => get_footer [285] => twentyten_credits [286] => auth_redirect [287] => _admin_menu [288] => load-edit.php [289] => admin_xml_ns [290] => admin_print_styles-edit.php [291] => admin_print_scripts-edit.php [292] => admin_head-edit.php [293] => admin_head [294] => adminmenu [295] => admin_notices [296] => restrict_manage_posts [297] => in_admin_footer [298] => admin_footer [299] => admin_footer-edit.php [300] => admin_bar_init [301] => locale [302] => query_vars [303] => generate_rewrite_rules [304] => wp_resource_hints [305] => wp_calculate_image_sizes [306] => get_header_image_tag [307] => wp_get_attachment_image_attributes [308] => frontpage_template [309] => widget_tag_cloud_args [310] => header_video_settings [311] => edit_category [312] => body_class [313] => customize_register [314] => customize_preview_init [315] => walker_nav_menu_start_el [316] => nav_menu_item_title [317] => admin_print_scripts-widgets.php [318] => admin_footer-widgets.php [319] => display_media_states [320] => admin_head-widgets.php [321] => admin_body_class [322] => debug_bar_classes [323] => deprecated_function_run [324] => deprecated_file_included [325] => deprecated_argument_run [326] => deprecated_function_trigger_error [327] => deprecated_file_trigger_error [328] => deprecated_argument_trigger_error |
一見すると、なんとなく順序通りになっていそうにも見えて、
もしかしてこの順序なんじゃないの!?と期待してしまいそうになります。
抜く処理に関しては以前の記事の方法を取っていますが、
結果、誤りでしたのでこちらに転記しておきます。
ざっくりこんな感じで抜いています。
1 2 3 4 5 |
global $wp_filter; foreach($wp_filter as $key => $val){ $res[$cnt] = $key; $cnt++; } |
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 (←コレ)
ご参考になれば幸いです。
当サイト内のコンテンツおよび画像を含むすべてにおいて、管理人アルゴリズンが著作権を保持しております。
当サイトでご紹介しております写真等につきましては著作権の放棄はしませんが、
ライセンスフリーでご利用いただいて構いません。
コンテンツを有益であると感じていただけましたら非常に光栄です。
ありがとうございます。
サイト内コンテンツを引用される際には、出典元として当サイト(個別記事)へのリンクをお願いいたします。
申し訳ございませんが、無断転載、複製をお断りさせて頂いております。
公開日: