Prioritizing and Troubleshooting Actions and Filters

Both actions and filters can take an optional third argument: the priority. If left out, this argument will default to 10, and your hooked functions will occur after all the built-in ones have completed. However, you can set the priority to any number at all. Set it to a lower number if you need your function to operate before the built-in actions and filters.

If you have installed plugins that use filters, or you've written your own filter, it can be hard to tell where the original content ends and the filtered addition begins. Sometimes it's also not clear when certain actions take place. The Hooks & Filters Flow plugin (planetozh.com/blog/my-projects/wordpress-hooks-filter-flow/) is a great way to list all the actions and filters that are operating on your content. Unlike most plugins, this one must be placed in your WordPress root directory or wp-admin. You have to enter its URL into your browser, because there is no link to it from your admin menu.

Figure 9-7 shows the plugin's report on my test installation, which has a few plugins installed. You'll see several functions belonging to my HTML Import and Dashboard Notepad plugins mixed in with default WordPress functions. Hooks & Filters Flow is a great way to see if your plugin is interfering with another filter, or if you need to adjust its priority.

Figure 9-7. The Hooks & Filters Flow plugin
0 0

Post a comment