- WordPress 3 Plugin Development Essentials
- Brian Bondari Everett Griffiths
- 264字
- 2021-04-09 21:19:59
Referencing hooks via add_action() and add_filter()
The final vital component in a WordPress plugin is the hook, which defines when the plugin is executed. This is arguably the most confusing component of a plugin, so we will be thorough in our explanations. Just as in pop-music, the term "hook" is sometimes ambiguous—different people use the term to refer to different things. Technically, the term "hook" should refer to a WordPress event, such as get_header or the_content, but sometimes it is used generally to refer to the add_action()
or add_filter()
functions which reference the hook. Pay attention to the context, and it should be clear which meaning was intended. The most important thing to understand here is that you determine when your functions execute by attaching them to a WordPress event by using the add_action()
or add_filter()
functions. Remember: hooks are events.
The syntax for both functions is exactly the same. We'll discuss the reasoning for this shortly, but for now, just compare the two:
add_filter( string $hook, mixed $your_function_name [, int $priority = 10 [, int $accepted_args = 1]])
versus
add_action( string $hook, mixed $your_function_name [, int $priority = 10 [, int $accepted_args = 1]])
In practice, the most common usage includes only the name of the WordPress event and the name of your function, such as:
add_action('admin_footer', 'hello_dolly');
In "Hello Dolly", admin_footer
is the action or event, and hello_dolly
is the name of the function which we want WordPress to run when the admin_footer
event occurs. Note that we have intentionally digressed from WordPress' official terminology for the sake of clarity.
- Enhancing Microsoft Content Management Server with ASP.NET 2.0
- iOS應用逆向與安全之道
- 邊做邊學:Photoshop CS6 圖像制作案例教程
- eZ Publish 4: Enterprise Web Sites Step/by/Step
- Drupal 6 Content Administration
- SolidWorks快速入門教程(2022中文版)
- AutoCAD 2016中文版基礎教程(全圖解視頻版)
- 詳解AutoCAD 2022室內(nèi)設計(第6版)
- SharePoint Designer Tutorial: Working with SharePoint Websites
- 玩轉(zhuǎn)國潮:Procreate插畫創(chuàng)作及實例教程
- SQL編程基礎(原書第3版)
- Apache Geronimo 2.1: Quick Reference
- AutoCAD計算機輔助設計標準教程(慕課版)
- OpenCV輕松入門:面向Python(第2版)
- 和秋葉一起學:秒懂Photoshop圖像處理