- 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.
- 中文版Photoshop CS6完全使用手冊(超值版)
- IBM Rational ClearCase 7.0: Master the Tools That Monitor, Analyze, and Manage Software Configurations
- 對比Excel,輕松學習SQL數據分析
- 中文版Illustrator CC實用教程
- 中文版Illustrator CC基礎培訓教程(移動學習版)
- 青少年美育趣味課堂:青少年學攝影修圖
- Photoshop影視動漫角色繪制技法精解
- SPSS統計分析
- Elgg Social Networking
- JBoss RichFaces 3.3
- Photoshop數字圖像處理
- 24小時玩賺剪映
- 3ds Max 2014/VRay效果圖制作實戰從入門到精通
- Photoshop 圖形圖像處理
- CorelDRAW 2017從新手到高手