remove_all_actions()
云策文档标注
概述
remove_all_actions() 函数用于从指定的 action hook 中移除所有回调函数。它基于 remove_all_filters() 实现,并返回 true。
关键要点
- 参数:$hook_name(必需,字符串类型,指定要移除回调的 action hook);$priority(可选,整数或 false,指定优先级,默认为 false)。
- 返回值:始终返回 true。
- 版本限制:在 WordPress 4.7 之前,不能从要移除回调的 hook 内部调用此函数,否则可能导致无限循环或警告;4.7 版本后已解决此问题。
- 相关函数:remove_all_filters() 用于从 filter hook 移除所有回调。
代码示例
remove_all_actions('the_content');
// 此示例将移除 the_content 函数的所有 hook。注意事项
在 WordPress 4.7 之前,避免在要移除回调的 hook 内部调用 remove_all_actions(),例如在 wp_footer 中调用 remove_all_actions('wp_footer') 会导致问题。建议在目标 hook 之前调用的 hook 中使用。
原文内容
Removes all of the callback functions from an action hook.
Parameters
$hook_namestringrequired-
The action to remove callbacks from.
$priorityint|falseoptional-
The priority number to remove them from.
Default:
false
Source
function remove_all_actions( $hook_name, $priority = false ) {
return remove_all_filters( $hook_name, $priority );
}
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |
Skip to note 3 content
Morteza Geransayeh
Example:
remove_all_actions('the_content');This example will remove all of the hooks from the_content function.
Skip to note 4 content
Pixelbart
If you want only show the admin bar, you can use this:
remove_all_actions( 'wp_head' ); remove_all_actions( 'wp_footer' ); // Add default wp_head actions add_action( 'wp_head', '_admin_bar_bump_cb', 0 ); add_action( 'wp_head', 'wp_print_styles', 8 ); add_action( 'wp_head', 'wp_print_head_scripts', 9 ); // Add default wp_footer actions add_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); // Add admin bar initialization actions add_action( 'template_redirect', '_wp_admin_bar_init', 0 ); add_action( 'admin_init', '_wp_admin_bar_init' ); add_action( 'before_signup_header', '_wp_admin_bar_init' ); add_action( 'activate_header', '_wp_admin_bar_init' ); // Render admin bar in the footer and admin header add_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); add_action( 'in_admin_header', 'wp_admin_bar_render', 0 );And if you use the action
wp, you can useget_query_varfor custom templates or other things. Just like that:add_action( 'wp', function() { if ( get_query_var( 'my_var' ) ) { // code from above here } } );