WordPress: Plugin API/Action Reference:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
无编辑摘要
无编辑摘要
第110行: 第110行:


== 模板 Actions ==
== 模板 Actions ==
;comment_form : Runs in standard themes to insert the comment form. Action function argument: post ID.


;comment_form :在标准主题中运行,插入评论形式。Action function argument:文章ID。
;comment_form :在标准主题中运行,插入评论形式。Action function argument:文章ID。
;do_robots: Runs when the template file chooser determines that it is a robots.txt request.


;do_robots:选择模板文件的人,确认模板文件是robots.txt请求的时候,运行。
;do_robots:选择模板文件的人,确认模板文件是robots.txt请求的时候,运行。
;do_robotstxt: Runs in the <tt>do_robots</tt> function before it prints out the Disallow lists for the robots.txt file.


;do_robotstxt:在<tt>do_robots</tt>函数中运行,然后输出robots.txt文件不接受的列表。
;do_robotstxt:在<tt>do_robots</tt>函数中运行,然后输出robots.txt文件不接受的列表。
;get_footer: Runs when the template calls the <tt>get_footer</tt> function, just before the <tt>footer.php</tt> template file is loaded.


;get_footer:模板调用<tt>get_footer</tt>函数的时候,运行,在载入<tt>footer.php</tt>模板文件之前。
;get_footer:模板调用<tt>get_footer</tt>函数的时候,运行,在载入<tt>footer.php</tt>模板文件之前。
;get_header: Runs when the template calls the <tt>get_header</tt> function, just before the <tt>header.php</tt> template file is loaded.


;get_header:模板调用<tt>get_header</tt>函数时候,运行,在载入<tt>header.php</tt>模板文件之前。
;get_header:模板调用<tt>get_header</tt>函数时候,运行,在载入<tt>header.php</tt>模板文件之前。
;switch_theme : Runs when the blog's theme is changed. Action function argument: name of the new theme.


;switch_theme :博客的主题更改的时候,运行。Action function argument:新的主题的名称。
;switch_theme :博客的主题更改的时候,运行。Action function argument:新的主题的名称。
;template_redirect:  Runs before the determination of the template file to be used to display the requested page, so that a plugin can override the template file choice. Example (pedagogical, not useful):  Redirect all requests to the <tt>all.php</tt> template file in the current themes' directory.


;template_redirect:在决定使用模板文件,显示请求的网页之前,运行,这样插件可以废除模板文件选项。例子(教育学的, 没用):将所有请求重新导向当前主题目录的<tt>all.php</tt>模板文件。
;template_redirect:在决定使用模板文件,显示请求的网页之前,运行,这样插件可以废除模板文件选项。例子(教育学的, 没用):将所有请求重新导向当前主题目录的<tt>all.php</tt>模板文件。
<pre>
function all_on_one () {
include(TEMPLATEPATH . '/all.php');
exit;
}
add_action('template_redirect', 'all_on_one');
</pre>
<pre>
<pre>
function all_on_one () {
function all_on_one () {
第156行: 第132行:
add_action('template_redirect', 'all_on_one');
add_action('template_redirect', 'all_on_one');
</pre>
</pre>
;wp_footer : Runs when the template calls the <tt>wp_footer</tt> function, generally near the bottom of the blog page.


;wp_footer :模板调用<tt>wp_footer</tt>函数的时候,运行,一般在博客页面的底部。
;wp_footer :模板调用<tt>wp_footer</tt>函数的时候,运行,一般在博客页面的底部。


;[[WordPress:Hook Reference/wp_head|wp_head]] : Runs when the template calls the <tt>wp_head</tt> function. This hook is generally placed near the top of a page template between <tt><head></tt> and <tt></head></tt>. This hook does not take any parameters.
;[[WordPress:Hook Reference/wp_head|wp_head]] :当模板调用<tt>wp_head</tt>函数的时候,运行。这个hook一般放在网页模板的顶上方,在<tt><head></tt>和 <tt></head></tt>之间。这个hook没有任何参数。
;[[WordPress:Hook Reference/wp_head|wp_head]] :当模板调用<tt>wp_head</tt>函数的时候,运行。这个hook一般放在网页模板的顶上方,在<tt><head></tt>和 <tt></head></tt>之间。这个hook没有任何参数。
;wp_meta : Runs when the <tt>sidebar.php</tt> template file calls the <tt>wp_meta</tt> function, to allow the plugin to insert content into the sidebar.


;wp_meta : <tt>sidebar.php</tt>模板文件调用<tt>wp_meta</tt>函数的时候,运行,使得插件将内容插入到边栏中。
;wp_meta : <tt>sidebar.php</tt>模板文件调用<tt>wp_meta</tt>函数的时候,运行,使得插件将内容插入到边栏中。
;wp_print_scripts: Runs just before WordPress prints registered JavaScript scripts into the page header.


;wp_print_scripts:WordPress将注册的JavaScript脚本发表到网页标头之前,运行。
;wp_print_scripts:WordPress将注册的JavaScript脚本发表到网页标头之前,运行。


== Administrative Actions ==
== Administrative Actions ==
== Administrative Actions ==
;[[WordPress:Plugin_API/Action_Reference/activate_(plugin_file_name)|activate_(plugin file name)]]: Runs when the plugin is first activated. See example in [[WordPress:Creating Tables with Plugins]].


;[[WordPress:Plugin_API/Action_Reference/activate_(plugin_file_name)|activate_(plugin file name)]]:插件首次激活的时候,运行。请看看[[WordPress:Creating Tables with Plugins|使用插件创建表格]]中的例子。
;[[WordPress:Plugin_API/Action_Reference/activate_(plugin_file_name)|activate_(plugin file name)]]:插件首次激活的时候,运行。请看看[[WordPress:Creating Tables with Plugins|使用插件创建表格]]中的例子。
;activity_box_end: Runs at the end of the activity box on the admin Dashboard screen.


;activity_box_end:在管理Dashboard界面上,activity box的结尾部分,运行。
;activity_box_end:在管理Dashboard界面上,activity box的结尾部分,运行。
;add_category_form_pre: Runs before the add category form is put on the screen in the admin menus.


;add_category_form_pre:在添加类别形式放到管理菜单的界面之前,运行。
;add_category_form_pre:在添加类别形式放到管理菜单的界面之前,运行。
;admin_head :Runs in the HTML <tt><head></tt> section of the admin panel.


;admin_head :在管理面板的HTML <tt><head></tt>部分,运行。
;admin_head :在管理面板的HTML <tt><head></tt>部分,运行。
;admin_head-(page_hook) or admin_head-(plugin_page): Runs in the HTML <tt><head></tt> section of the admin panel of a plugin-generated page.


;admin_head-(page_hook)或者admin_head-(plugin_page):在插件产生的网页的管理面板的HTML <tt><head></tt>部分运行。
;admin_head-(page_hook)或者admin_head-(plugin_page):在插件产生的网页的管理面板的HTML <tt><head></tt>部分运行。
;admin_footer:  Runs at the end of the admin panel inside the body tag.


;admin_footer:在标签内,管理面板的结尾,运行。
;admin_footer:在标签内,管理面板的结尾,运行。
;admin_print_scripts: Runs in the HTML header so a plugin can add JavaScript scripts to all admin pages.


;admin_print_scripts:在HTML标头中运行,这样插件可以将JavaScript脚本添加到所有的管理页面。
;admin_print_scripts:在HTML标头中运行,这样插件可以将JavaScript脚本添加到所有的管理页面。
;admin_print_scripts-(page_hook) or admin_print_scripts-(plugin_page): Runs to print JavaScript scripts in the HTML head section of a specific plugin-generated admin page. The (page_hook) is returned when using any of the functions that add plugin menu items to the admin menu: add_management_page(), add_options_page(), etc. Example:


;admin_print_scripts-(page_hook) 或者admin_print_scripts-(plugin_page):运行,将JavaScript脚本放到插件产生的管理页面的HTML标头部分。使用任何将插件菜单内容添加到管理菜单的函数时,返回(page_hook):add_management_page(), add_options_page(),等等。例如:
;admin_print_scripts-(page_hook) 或者admin_print_scripts-(plugin_page):运行,将JavaScript脚本放到插件产生的管理页面的HTML标头部分。使用任何将插件菜单内容添加到管理菜单的函数时,返回(page_hook):add_management_page(), add_options_page(),等等。例如:
function myplugin_menu() {
  if ( function_exists('add_management_page') ) {
    $page = add_management_page( 'myplugin', 'myplugin', 9, __FILE__, 'myplugin_admin_page' );
    add_action( "admin_print_scripts-$page", 'myplugin_admin_head' );
  }
}
function myplugin_menu() {
function myplugin_menu() {
   if ( function_exists('add_management_page') ) {
   if ( function_exists('add_management_page') ) {
第223行: 第164行:
   }
   }
  }  
  }  
;check_passwords: Runs to validate the double-entry of password when creating a new user. Action function arguments: array of login name, first password, second password.


;check_passwords:运行,在创建新的用户的时候,两次输入密码确认。Action function arguments:登录名,第一个密码,第二个密码。
;check_passwords:运行,在创建新的用户的时候,两次输入密码确认。Action function arguments:登录名,第一个密码,第二个密码。
;dbx_page_advanced: Runs at the bottom of the "advanced" section on the page editing screen in the admin menus.


;dbx_page_advanced:在管理菜单,网页编辑界面的"高级"部分的底部,运行。
;dbx_page_advanced:在管理菜单,网页编辑界面的"高级"部分的底部,运行。
;dbx_page_sidebar: Runs at the bottom of the sidebar on the page editing screen in the admin menus.


;dbx_page_sidebar:在管理菜单,网页编辑界面的边栏的底部,运行。
;dbx_page_sidebar:在管理菜单,网页编辑界面的边栏的底部,运行。
;dbx_post_advanced: Runs at the bottom of the "advanced" section on the post editing screen in the admin menus.


;dbx_post_advanced:在管理菜单,网页编辑界面的"高级"部分的底部运行。
;dbx_post_advanced:在管理菜单,网页编辑界面的"高级"部分的底部运行。
;dbx_post_sidebar: Runs at the bottom of the sidebar on the post editing screen in the admin menus.


;dbx_post_sidebar:在管理菜单,文本编辑界面的边栏的底部,运行。
;dbx_post_sidebar:在管理菜单,文本编辑界面的边栏的底部,运行。
;deactivate_(plugin file name): Runs when a plugin is deactivated.


;deactivate_(插件文件名):插件不运行的状态,运行。
;deactivate_(插件文件名):插件不运行的状态,运行。
;delete_user: Runs when a user is deleted. Action function arguments: user ID.


;delete_user:删除用户的时候,运行。Action function arguments: 用户 ID。
;delete_user:删除用户的时候,运行。Action function arguments: 用户 ID。
;edit_category_form: Runs after the add/edit category form is put on the screen (but before the end of the HTML form tag).


;edit_category_form:在添加/编辑类别形式放到界面之后(但是在HTML形式标签结束之前)运行。
;edit_category_form:在添加/编辑类别形式放到界面之后(但是在HTML形式标签结束之前)运行。
;edit_category_form_pre: Runs before the edit category form is put on the screen in the admin menus.


;edit_category_form_pre:在编辑类别形式放入管理菜单中的界面之前,运行。
;edit_category_form_pre:在编辑类别形式放入管理菜单中的界面之前,运行。
;edit_form_advanced: Runs just before the "advanced" section of the post editing form in the admin menus.


;edit_form_advanced:在管理菜单中的文本编辑形式的"高级"部分之前,运行。
;edit_form_advanced:在管理菜单中的文本编辑形式的"高级"部分之前,运行。
;edit_page_form: Runs just before the "advanced" section of the page editing form in the admin menus.


;edit_page_form:在管理菜单中的文本编辑形式的"高级"部分之前,运行。
;edit_page_form:在管理菜单中的文本编辑形式的"高级"部分之前,运行。
;edit_user_profile: Runs near the end of the user profile editing screen in the admin menus.


;edit_user_profile:在管理菜单中的用户基本资料编辑界面的结尾部分运行。
;edit_user_profile:在管理菜单中的用户基本资料编辑界面的结尾部分运行。
;load-(page): Runs when an administration menu page is loaded. This action is not usually added directly -- see [[WordPress:Adding Administration Menus]] for more details of how to add admin menus. If you do want to use it directly, the return value from <tt>add_options_page</tt> and similar functions gives you the <tt>(page)</tt> part of the action name.


;load-(page):载入菜单页面的时候,运行。这个部分并不是直接添加的—关于怎样添加管理菜单的更多详细信息,请看看[[WordPress:Adding Administration Menus|添加管理菜单]]。如果你不想直接使用,<tt>add_options_page</tt>的返回值和相似的函数,会给你action 名称的<tt>(page)</tt>部分。
;load-(page):载入菜单页面的时候,运行。这个部分并不是直接添加的—关于怎样添加管理菜单的更多详细信息,请看看[[WordPress:Adding Administration Menus|添加管理菜单]]。如果你不想直接使用,<tt>add_options_page</tt>的返回值和相似的函数,会给你action 名称的<tt>(page)</tt>部分。
;login_form: Runs just before the end of the login form.


;login_form:在登录形式之前,运行。
;login_form:在登录形式之前,运行。
;login_head: Runs just before the end of the HTML head section of the login page.


;login_head:在登录页面的HTML标头部分的结束之前,运行。
;login_head:在登录页面的HTML标头部分的结束之前,运行。
;lost_password: Runs before the "retrieve your password by email" form is printed on the login screen.


;lost_password:在"通过电子邮件得到你的密码"形式,发表在管理界面之前,运行。
;lost_password:在"通过电子邮件得到你的密码"形式,发表在管理界面之前,运行。
;lostpassword_form: Runs at the end of the form used to retrieve a user's password by email, to allow a plugin to supply extra fields.


;lostpassword_form:在使用形式,通过电子邮件获得用户密码,结束之后,运行,使用插件支持额外的栏。
;lostpassword_form:在使用形式,通过电子邮件获得用户密码,结束之后,运行,使用插件支持额外的栏。
;lostpassword_post: runs when the user has requested an email message to retrieve their password, to allow a plugin to modify the PHP <tt>$_POST</tt> variable before processing.


;lostpassword_post:当用户需要电子邮件信息,获取密码的时候,运行,运行前,运行插件更改PHP <tt>$_POST</tt>变数。
;lostpassword_post:当用户需要电子邮件信息,获取密码的时候,运行,运行前,运行插件更改PHP <tt>$_POST</tt>变数。
;manage_link_custom_column: Runs when there is an unknown column name for the blogroll managing admin screen. Action function arguments: column name, link ID. See also filter <tt>manage_link_columns</tt> in the [[WordPress:Plugin API/Filter Reference]], which adds custom columns.


;manage_link_custom_column:当友情链接管理界面有个不知名的栏的时候,运行。Action function arguments:栏名,链接ID。也看看[[WordPress:Plugin API/Filter Reference]]中的filter <tt>manage_link_columns</tt>,添加自定义栏。
;manage_link_custom_column:当友情链接管理界面有个不知名的栏的时候,运行。Action function arguments:栏名,链接ID。也看看[[WordPress:Plugin API/Filter Reference]]中的filter <tt>manage_link_columns</tt>,添加自定义栏。
;manage_posts_custom_column: Runs when there is an unknown column name for the managing posts admin screen. Action function arguments: column name, post ID. See also filter <tt>manage_posts_columns</tt> in the [[WordPress:Plugin API/Filter Reference]], which adds custom columns. (see [http://scompt.com/archives/2007/10/20/adding-custom-columns-to-the-wordpress-manage-posts-screen Scompt's tutorial] for examples and use.)


;manage_posts_custom_column:管理文章管理界面有未知的栏名称的时候,运行。Action function arguments:栏名,文章ID。也看看[[WordPress:Plugin API/Filter Reference]]中的filter <tt>manage_posts_columns</tt>,添加了自定义栏。(关于例子和使用,请看看[http://scompt.com/archives/2007/10/20/adding-custom-columns-to-the-wordpress-manage-posts-screen Scompt的指南]。)
;manage_posts_custom_column:管理文章管理界面有未知的栏名称的时候,运行。Action function arguments:栏名,文章ID。也看看[[WordPress:Plugin API/Filter Reference]]中的filter <tt>manage_posts_columns</tt>,添加了自定义栏。(关于例子和使用,请看看[http://scompt.com/archives/2007/10/20/adding-custom-columns-to-the-wordpress-manage-posts-screen Scompt的指南]。)
;manage_pages_custom_column: Runs when there is an unknown column name for the managing pages admin screen. Action function arguments: column name, page ID. See also filter <tt>manage_pages_columns</tt> in the [[WordPress:Plugin API/Filter Reference]], which adds custom columns.


;manage_pages_custom_column: 管理网页管理界面有未知的栏名称的时候,运行。Action function arguments:栏名,网页ID。也看看[[WordPress:Plugin API/Filter Reference| Plugin API/Filter Reference]]中的filter <tt>manage_pages_columns</tt>,添加了自定义栏。
;manage_pages_custom_column: 管理网页管理界面有未知的栏名称的时候,运行。Action function arguments:栏名,网页ID。也看看[[WordPress:Plugin API/Filter Reference| Plugin API/Filter Reference]]中的filter <tt>manage_pages_columns</tt>,添加了自定义栏。
;password_reset: Runs before the user's password is reset to a random new password.


;password_reset:用户密码重新设置为随意的新密码之前,运行。
;password_reset:用户密码重新设置为随意的新密码之前,运行。
;personal_options_update: Runs when a user updates personal options from the admin screen.


;personal_options_update:用户从管理界面更新个人选项的时候,运行。
;personal_options_update:用户从管理界面更新个人选项的时候,运行。
;plugins_loaded: Runs after all plugins have been loaded.


;plugins_loaded:载入所有插件的时候,运行。
;plugins_loaded:载入所有插件的时候,运行。
;profile_personal_options: Runs at the end of the Personal Options section of the user profile editing screen.


;profile_personal_options:在用户基本资料编辑界面的个人选项部分的结尾部分,运行。
;profile_personal_options:在用户基本资料编辑界面的个人选项部分的结尾部分,运行。
;profile_update: Runs when a user's profile is updated. Action function argument: user ID.


;profile_update:更新用户基本资料的时候,运行。Action function argument: 用户 ID。
;profile_update:更新用户基本资料的时候,运行。Action function argument: 用户 ID。
;register_form: Runs just before the end of the new user registration form.


;register_form:新的用户注册形式结束之前,运行。
;register_form:新的用户注册形式结束之前,运行。
;register_post: Runs before a new user registration request is processed.


;register_post:处理新的用户注册请求之前,运行。
;register_post:处理新的用户注册请求之前,运行。
;restrict_manage_posts: Runs before the list of posts to edit is put on the screen in the admin menus.


;restrict_manage_posts:文章放到管理菜单界面中编辑之前,运行。
;restrict_manage_posts:文章放到管理菜单界面中编辑之前,运行。
;retrieve_password: Runs when a user's password is retrieved, to send them a reminder email. Action function argument: login name.


;retrieve_password:返回用户密码时,运行,向用户发送电子邮件提醒。Action function argument:注册名。
;retrieve_password:返回用户密码时,运行,向用户发送电子邮件提醒。Action function argument:注册名。
;set_current_user: Runs after the user has been changed by the default <tt>wp_set_current_user</tt> function. Note that <tt>wp_set_current_user</tt> is also a "pluggable" function, meaning that plugins can override it; see [[WordPress:Plugin API]]).


;set_current_user:用户被默认的<tt>wp_set_current_user</tt>函数更改后,运行。注意<tt>wp_set_current_user</tt>也是个"pluggable"函数,意思是插件可以取代这个函数。请看看[[WordPress:Plugin API|插件API]]。)
;set_current_user:用户被默认的<tt>wp_set_current_user</tt>函数更改后,运行。注意<tt>wp_set_current_user</tt>也是个"pluggable"函数,意思是插件可以取代这个函数。请看看[[WordPress:Plugin API|插件API]]。)
;show_user_profile: Runs near the end of the user profile editing screen.


;show_user_profile:在用户基本资料编辑界面的结束部分附近,运行。
;show_user_profile:在用户基本资料编辑界面的结束部分附近,运行。
;simple_edit_form: Runs at the end of the "simple" post editing form in the admin menus (by default the simple form is used only for bookmarklets -- it doesn't have the "advanced" sections).


;simple_edit_form:在管理菜单的"简单"文章编辑形式的结尾,运行(默认情况下,只有bookmarklets使用简单形式—没有"高级"部分)。
;simple_edit_form:在管理菜单的"简单"文章编辑形式的结尾,运行(默认情况下,只有bookmarklets使用简单形式—没有"高级"部分)。
;update_option_(option_name): Runs after a WordPress option has been update by the <tt>update_option</tt> function. Action function arguments: old option value, new option value. You must add an action for the specific options that you want to respond to, such as <tt>update_option_foo</tt> to respond when option "foo" has been updated.


;update_option_(option_name):WordPress选项已经由<tt>update_option</tt>函数更新后,运行。Action function arguments:旧选项参数值,新的选项参数值。你必须为你想要回应的选项添加一个action,例如更新了选项"foo"时,回应<tt>update_option_foo</tt>。
;update_option_(option_name):WordPress选项已经由<tt>update_option</tt>函数更新后,运行。Action function arguments:旧选项参数值,新的选项参数值。你必须为你想要回应的选项添加一个action,例如更新了选项"foo"时,回应<tt>update_option_foo</tt>。
;upload_files_(tab) : Runs to print a screen on the upload files admin screen; "tab" is the name of the custom action tab. Define custom tabs using the <tt>wp_upload_tabs</tt> filter (see [[WordPress:Plugin API/Filter Reference]]).


;upload_files_(tab) :运行,在管理界面上传文件上产生界面;"tab"是自定义action 标签的名称。使用<tt>wp_upload_tabs</tt> filter定义自定义的标签(请看看[[WordPress:Plugin API/Filter Reference| Plugin API/Filter Reference]])。
;upload_files_(tab) :运行,在管理界面上传文件上产生界面;"tab"是自定义action 标签的名称。使用<tt>wp_upload_tabs</tt> filter定义自定义的标签(请看看[[WordPress:Plugin API/Filter Reference| Plugin API/Filter Reference]])。
;user_register: Runs when a user's profile is first created. Action function argument: user ID.


;user_register:首次创建用户基本资料的时候,运行。Action function argument: 用户 ID。
;user_register:首次创建用户基本资料的时候,运行。Action function argument: 用户 ID。
;wp_ajax_(action): Runs to do an unknown type of AJAX action in the administrative menus.


;wp_ajax_(action):运行,在管理菜单中操作未知类型的AJAX。
;wp_ajax_(action):运行,在管理菜单中操作未知类型的AJAX。
;wp_authenticate: Runs to authenticate a user when they log in. Action function arguments: array with user name and password.


;wp_authenticate:用于用户登录时,确认用户。Action function arguments:用户名和密码数组。
;wp_authenticate:用于用户登录时,确认用户。Action function arguments:用户名和密码数组。
;wp_login: Runs when a user logs in.


;wp_login:用户登录时,运行。
;wp_login:用户登录时,运行。
;wp_logout: Runs when a user logs out.


;wp_logout:用户退出时,运行。
;wp_logout:用户退出时,运行。


== Advanced Actions ==
== Advanced Actions ==
== Advanced Actions ==
This section contains actions related to the queries WordPress uses to figure out what posts to display, the WordPress loop, activating plugins, and other fundamental-level WordPress code.


这个部分包含了与WordPress使用的查询相关的actions,取人要显示什么文章,WordPress Loop,激活插件,以及其它基本的WordPress代码。
这个部分包含了与WordPress使用的查询相关的actions,取人要显示什么文章,WordPress Loop,激活插件,以及其它基本的WordPress代码。
;admin_menu: Runs after the basic admin panel menu structure is in place.


;admin_menu:基本的管理面板菜单结构到位后,运行。
;admin_menu:基本的管理面板菜单结构到位后,运行。
;admin_notices: Runs after the admin menu is printed to the screen.


;admin_notices:管理菜单出现在界面上后,运行。
;admin_notices:管理菜单出现在界面上后,运行。
;blog_privacy_selector: Runs after the default blog privacy options are printed on the screen.


;blog_privacy_selector:默认博客保密选项出现在界面上后,运行。
;blog_privacy_selector:默认博客保密选项出现在界面上后,运行。
;check_admin_referer: Runs in the default <tt>check_admin_referrer</tt> function after the nonce has been checked for security purposes, to allow a plugin to force WordPress to die for extra security reasons. Note that <tt>check_admin_referrer</tt> is also a "pluggable" function, meaning that plugins can override it; see [[WordPress:Plugin API]]).


;check_admin_referer: nonce经过了安全检查后,在默认<tt>check_admin_referrer</tt>函数中,运行,允许插件迫使WordPress因为额外的安全考虑,而停止运行。注意<tt>check_admin_referrer</tt>也是"pluggable"函数,指的是插件可以代替这个函数;请看看[[WordPress:Plugin API|插件API]])。
;check_admin_referer: nonce经过了安全检查后,在默认<tt>check_admin_referrer</tt>函数中,运行,允许插件迫使WordPress因为额外的安全考虑,而停止运行。注意<tt>check_admin_referrer</tt>也是"pluggable"函数,指的是插件可以代替这个函数;请看看[[WordPress:Plugin API|插件API]])。
;check_ajax_referer: Runs in the default <tt>check_ajax_referer</tt> function (which is called when an AJAX request goes to the <tt>wp-admin/admin-ajax.php</tt> script) after the user's login and password have been successfully validated from cookies, to allow a plugin to force WordPress to die for extra security reasons. Note that <tt>check_ajax_referer</tt> is also a "pluggable" function, meaning that plugins can override it; see [[WordPress:Plugin API]]).


;check_ajax_referer:在默认<tt>check_ajax_referer</tt>函数中运行(当AJAX请求进入了<tt>wp-admin/admin-ajax.php</tt>脚本,这个函数得到调用),cookies成功地确认了用户登录和密码后,允许插件迫使WordPress停止运行,以增加安全性。注<tt>check_ajax_referer</tt>也是个"pluggable"函数,意思是插件可以代替这个函数;请看看[[WordPress:Plugin API|插件API]])。
;check_ajax_referer:在默认<tt>check_ajax_referer</tt>函数中运行(当AJAX请求进入了<tt>wp-admin/admin-ajax.php</tt>脚本,这个函数得到调用),cookies成功地确认了用户登录和密码后,允许插件迫使WordPress停止运行,以增加安全性。注<tt>check_ajax_referer</tt>也是个"pluggable"函数,意思是插件可以代替这个函数;请看看[[WordPress:Plugin API|插件API]])。
;generate_rewrite_rules : Runs after the rewrite rules are generated. Action function arguments: the <tt>WP_Rewrite</tt> class variables as a list. Note that it is easier to use the <tt>rewrite_rules_array</tt> filter instead of this action, to modify the rewrite rules.


;generate_rewrite_rules :产生rewrite 规则之后,运行。Action function arguments: <tt>WP_Rewrite</tt> class variables作为列表。注意,使用<tt>rewrite_rules_array</tt>比使用这个action,更易于更改rewrite 规则。
;generate_rewrite_rules :产生rewrite 规则之后,运行。Action function arguments: <tt>WP_Rewrite</tt> class variables作为列表。注意,使用<tt>rewrite_rules_array</tt>比使用这个action,更易于更改rewrite 规则。
;init: Runs after WordPress has finished loading but before any headers are sent. Useful for intercepting $_GET or $_POST triggers.


;init:WordPress结束了载入,但是在发送任何标头之前,运行。有利于截取$_GET or $_POST triggers。
;init:WordPress结束了载入,但是在发送任何标头之前,运行。有利于截取$_GET or $_POST triggers。
;loop_end: Runs after the last post of the WordPress loop is processed.


;loop_end:运行WordPress loop最后一篇文章的时候,运行。
;loop_end:运行WordPress loop最后一篇文章的时候,运行。
;loop_start: Runs before the first post of the WordPress loop is processed.


;loop_start:运行WordPress loop中第一篇文章之前,运行。
;loop_start:运行WordPress loop中第一篇文章之前,运行。
;parse_query: Runs at the end of query parsing. Action function arguments: contents of the <tt>$wp_query</tt> object as a list.


;parse_query:在查询解析结束后,运行。Action function arguments: <tt>$wp_query</tt> object的内容作为列表。
;parse_query:在查询解析结束后,运行。Action function arguments: <tt>$wp_query</tt> object的内容作为列表。
;parse_request: Runs after the query request is parsed inside the main WordPress function <tt>wp</tt>. Action function argument: an array with a reference to the global $wp object.


;parse_request:查询请求在主要的WordPress函数 <tt>wp</tt>中解析后,运行。Action function argument: an array with a reference to the global $wp object.
;parse_request:查询请求在主要的WordPress函数 <tt>wp</tt>中解析后,运行。Action function argument: an array with a reference to the global $wp object.
;pre_get_posts: Runs before the query in the <tt>get_posts</tt> function. Action function argument: contents of the <tt>$wp_query</tt> object, as a list.


;pre_get_posts:在<tt>get_posts</tt>函数查询之前,运行。Action function argument: <tt>$wp_query</tt> object的内容,作为列表。
;pre_get_posts:在<tt>get_posts</tt>函数查询之前,运行。Action function argument: <tt>$wp_query</tt> object的内容,作为列表。
;sanitize_comment_cookies: Runs after cookies have been read from the HTTP request.


;sanitize_comment_cookies:cookies已经从HTTP请求中读出之后,运行。
;sanitize_comment_cookies:cookies已经从HTTP请求中读出之后,运行。
;send_headers: Runs after the basic HTTP headers are sent inside the main WordPress function <tt>wp</tt>. Action function argument: an array with a reference to the global $wp object.


;send_headers:基本的HTTP标头发送到主要的WordPress函数<tt>wp</tt>内部后,运行。Action function argument: an array with a reference to the global $wp object.
;send_headers:基本的HTTP标头发送到主要的WordPress函数<tt>wp</tt>内部后,运行。Action function argument: an array with a reference to the global $wp object.
;shutdown: Runs when the page output is complete.


;shutdown:输出网页后,运行。
;shutdown:输出网页后,运行。
;wp : Executes after the query has been parsed and post(s) loaded, but before any template execution, inside the main WordPress function <tt>wp</tt>. Useful if you need to have access to post data but can't use templates for output. Action function argument: an array with a reference to the global $wp object.


;wp :查询已经解析并且文章载入后,运行,但是在运行模板之前,在主要的WordPress函数<tt>wp</tt>中。如果你需要使用文章数据,但是不能使用模板输出数据,这个有用。Action function argument: an array with a reference to the global $wp object.
;wp :查询已经解析并且文章载入后,运行,但是在运行模板之前,在主要的WordPress函数<tt>wp</tt>中。如果你需要使用文章数据,但是不能使用模板输出数据,这个有用。Action function argument: an array with a reference to the global $wp object.
== Further Reading ==


== 深入阅读==
== 深入阅读==
* [[WordPress:Writing a Plugin]] - description of how to write a plugin
* [[WordPress:Plugin API]] - article on how to use filters and actions
* [[WordPress:Plugin API/Filter Reference]] - reference list for filter hooks
* [[WordPress:Plugin Resources]] - comprehensive list of plugin-related resources
* [http://codex.wordpress.org/User:Skippy Skippy's list] of actions and filters
* [http://wphooks.flatearth.org WordPress Hooks], a work in progress directory of all of WordPress’ hooks.
* [http://adambrown.info/p/wp_hooks WordPress Hooks Database], a database of all WordPress' hooks, showing which version they come from, and linking to the source code spots that use them
* [http://blog.taragana.com/index.php/archive/wordpress-2x-hooks-for-action-comprehensive-list-for-plugin-and-theme-developers/ Angsuman's list], a comprehensive listing of WordPress action hooks with documentation and source code location information. It contains all documented and undocumented action hooks in WordPress 2.0.


* [[WordPress:Writing a Plugin|编写插件]] – 描述怎样编写插件
* [[WordPress:Writing a Plugin|编写插件]] – 描述怎样编写插件

2008年8月26日 (二) 19:46的版本

这篇文章是WordPress2.1以及更高版本中的插件发展中可以使用的action hooks的列表(希望全面)。更多的信息:

  • 学习更多关于filter和action hooks是什么的内容,请看看插件API
  • 学习更多编写插件的内容,请看看编写插件

注:如果你想要添加或者阐明这个文件,请采用当前的文章格式。描述action运行的时间,如action function带有参数,请描述这个参数。

文章,网页,配属,和类别Actions

add_attachment
当附属文件首次添加到数据库的时候,请运行这个。Action function 参数:attachment ID。
add_category
create_category相同。
create_category
创建新的类别的时候,运行。Aciton function arguments: 类别 ID。
delete_attachment
数据库中删除附加文件后,运行。Action function arguments: attachment ID。
delete_category
类别从数据库中删除而且类别相关的链接/文章得到更新,移除类别的时候,运行。Action function arguments: 类别 ID。
delete_post
文章或者网页将要删除的时候,运行。Action function arguments:文章或者网页ID。
edit_attachment
附加文件编辑/更新到数据库中的时候,运行。Action function arguments: attachment ID。
edit_category
类别升级/编辑的时候,包括文章或者友情链接添加/删除的时间或者类别更新的时间(致使类别数目更新),运行edit_category。Action function arguments: 类别 ID。
edit_post
文章或者网页更新/编辑的时候,包括添加或者更新评论的时候(致使文章的评论数目更新),运行edit_post。Action function arguments: 文章或者网页 ID。
private_to_published
文章从保密更改为发表状态的时候,运行private_to_published。Action function arguments: 文章 ID。
publish_page
发表网页的时候,或者编辑网页,或者网页状态为"已发表"的时候,运行publish_page。Action function arguments:网页ID。(注:这个hook似乎在2.3版本以及更高的版本中已经不能够运行了。'transition_post_status'能够运行;更新:publish_page hook似乎从2.6版本开始,即可运行)
publish_phone
在文章通过电子邮件添加后,运行publish_phone。Action function argument: 文章 ID。
publish_post
文章发表,或者文章正在编辑并且状态是"已发表"时,运行publish_post。Action function arguments:文章ID。
save_post
创建或者更新文章或者网页的时候,可以是导入的文章/网页编辑形式,xmlrpc,或者通过电子邮件发送的文章,运行save_post。Action function arguments:文章ID。
wp_insert_post
save_post相同,在稍后运行。
xmlrpc_publish_post
文章通过XMLRPC发表,或者文章通过XMLRPC编辑,并且文章的状态是"已发表"时,运行xmlrpc_publish_post。Action function arguments:文章ID。

评论, Ping,和 Trackback Actions

comment_closed
尝试显示评论内容形式的时候,文章标记为不允许评论,运行。Action function argument: 文章 ID。
comment_id_not_found
试着显示评论或者评论内容形式的时候,没有找到文章ID时,运行。Action function argument: 文章 ID。
comment_flood_trigger
发现垃圾评论,在调用wp_die阻止接受评论之前,运行。Action function arguments:先前评论时间,当前评论时间。
comment_on_draft
当文章是草稿,试着显示评论内容形式或者评论的时候,运行。Action function argument: 文章ID。
comment_post
评论保存到数据库时,运行。Action function arguments: 评论 ID, 批准状态 ("垃圾广告", 或者 0/1 表示不批准/批准)。
edit_comment
评论在数据库中更新/编辑时候,运行。Action function arguments: 评论 ID。
delete_comment
评论删除之前,运行。Action function arguments: 评论 ID。
pingback_post
当ping添加到文章时候,运行。Action function argument: 评论 ID。Action function argument: comment ID.
pre_ping
ping完全地运行之前,运行。Action function arguments:运行一组文章链接,以及文章的"pung"设置。
trackback_post
当trackback添加到文章的时候,运行。Action function argument:评论ID。
wp_blacklist_check
运行,查看评论是否应该放到黑名单。Action function arguments:作者名,作者电子邮件,作者URL,评论文本,作者IP地址,作者的用户代理(浏览器)。你的函数能够执行wp_die拒绝评论,或者更改其中输入的一个函数,这样WordPress选项中会包含其中的一个黑名单关键词。
wp_set_comment_status
评论状态更改的时候,运行。Action function arguments:评论ID,状态字符串只是新的状态("删除", "准许", "垃圾广告", "hold")。

友情链接 Actions

add_link
当一个新的友情链接首次添加到数据库的时候,运行。Action function arguments:链接ID。
delete_link
删除友情链接的时候,运行。Action function arguments:链接ID。
edit_link
编辑友情链接的时候,运行。Action function arguments:链接ID。

Feed Actions

atom_entry
atom feed中的每个博客entry信息发表后(但是entry标签关闭之前),运行。
atom_head
博客信息在atom feed,第一个entry之前,发表后,运行。
atom_ns
为atom feed,在根XML元素内部运行(要添加名字空间)。
commentrss2_item
评论feed中发表了单个评论的信息后(但是在关闭item标签之前),运行。Action function arguments:评论ID,文章ID。
commentrss2_item
do_feed_feed
产生feed时,运行,feed是feed的类型(rss2, atom, rdf, 等等)。
rdf_header
博客信息在RDF feed中发表后,在第一个entry之前,运行。
rdf_item
RDF feed中的每篇博客文章信息都发表后(但是在关闭文章标签之前),运行。
rdf_ns
在RDF feed中的根XML元素内运行(添加名字空间)。
rss_head
博客信息在RSS feed中发表后,在第一篇文章之前,运行。
rss_item
RSS feed中的每篇博客文章信息发表后(但是在文章标签关闭之前),运行。
rss2_head
博客信息在RSS 2 feed中发表后,在第一篇文章之前,运行。
rss2_item
在RSS 2 feed中发表了每篇博客文章信息后(但是在文章标签关闭之前),运行。
rss2_ns
在RSS 2 feed内的根XML元素中运行(添加名字空间)。

模板 Actions

comment_form
在标准主题中运行,插入评论形式。Action function argument:文章ID。
do_robots
选择模板文件的人,确认模板文件是robots.txt请求的时候,运行。
do_robotstxt
do_robots函数中运行,然后输出robots.txt文件不接受的列表。
get_footer
模板调用get_footer函数的时候,运行,在载入footer.php模板文件之前。
get_header
模板调用get_header函数时候,运行,在载入header.php模板文件之前。
switch_theme
博客的主题更改的时候,运行。Action function argument:新的主题的名称。
template_redirect
在决定使用模板文件,显示请求的网页之前,运行,这样插件可以废除模板文件选项。例子(教育学的, 没用):将所有请求重新导向当前主题目录的all.php模板文件。
function all_on_one () {
	include(TEMPLATEPATH . '/all.php');
	exit;
}

add_action('template_redirect', 'all_on_one');
wp_footer
模板调用wp_footer函数的时候,运行,一般在博客页面的底部。
wp_head
当模板调用wp_head函数的时候,运行。这个hook一般放在网页模板的顶上方,在<head></head>之间。这个hook没有任何参数。
wp_meta
sidebar.php模板文件调用wp_meta函数的时候,运行,使得插件将内容插入到边栏中。
wp_print_scripts
WordPress将注册的JavaScript脚本发表到网页标头之前,运行。

Administrative Actions

activate_(plugin file name)
插件首次激活的时候,运行。请看看使用插件创建表格中的例子。
activity_box_end
在管理Dashboard界面上,activity box的结尾部分,运行。
add_category_form_pre
在添加类别形式放到管理菜单的界面之前,运行。
admin_head
在管理面板的HTML <head>部分,运行。
admin_head-(page_hook)或者admin_head-(plugin_page)
在插件产生的网页的管理面板的HTML <head>部分运行。
admin_footer
在标签内,管理面板的结尾,运行。
admin_print_scripts
在HTML标头中运行,这样插件可以将JavaScript脚本添加到所有的管理页面。
admin_print_scripts-(page_hook) 或者admin_print_scripts-(plugin_page)
运行,将JavaScript脚本放到插件产生的管理页面的HTML标头部分。使用任何将插件菜单内容添加到管理菜单的函数时,返回(page_hook):add_management_page(), add_options_page(),等等。例如:

function myplugin_menu() {

  if ( function_exists('add_management_page') ) {
    $page = add_management_page( 'myplugin', 'myplugin', 9, __FILE__, 'myplugin_admin_page' );
    add_action( "admin_print_scripts-$page", 'myplugin_admin_head' );
  }
} 
check_passwords
运行,在创建新的用户的时候,两次输入密码确认。Action function arguments:登录名,第一个密码,第二个密码。
dbx_page_advanced
在管理菜单,网页编辑界面的"高级"部分的底部,运行。
dbx_page_sidebar
在管理菜单,网页编辑界面的边栏的底部,运行。
dbx_post_advanced
在管理菜单,网页编辑界面的"高级"部分的底部运行。
dbx_post_sidebar
在管理菜单,文本编辑界面的边栏的底部,运行。
deactivate_(插件文件名)
插件不运行的状态,运行。
delete_user
删除用户的时候,运行。Action function arguments: 用户 ID。
edit_category_form
在添加/编辑类别形式放到界面之后(但是在HTML形式标签结束之前)运行。
edit_category_form_pre
在编辑类别形式放入管理菜单中的界面之前,运行。
edit_form_advanced
在管理菜单中的文本编辑形式的"高级"部分之前,运行。
edit_page_form
在管理菜单中的文本编辑形式的"高级"部分之前,运行。
edit_user_profile
在管理菜单中的用户基本资料编辑界面的结尾部分运行。
load-(page)
载入菜单页面的时候,运行。这个部分并不是直接添加的—关于怎样添加管理菜单的更多详细信息,请看看添加管理菜单。如果你不想直接使用,add_options_page的返回值和相似的函数,会给你action 名称的(page)部分。
login_form
在登录形式之前,运行。
login_head
在登录页面的HTML标头部分的结束之前,运行。
lost_password
在"通过电子邮件得到你的密码"形式,发表在管理界面之前,运行。
lostpassword_form
在使用形式,通过电子邮件获得用户密码,结束之后,运行,使用插件支持额外的栏。
lostpassword_post
当用户需要电子邮件信息,获取密码的时候,运行,运行前,运行插件更改PHP $_POST变数。
manage_link_custom_column
当友情链接管理界面有个不知名的栏的时候,运行。Action function arguments:栏名,链接ID。也看看WordPress:Plugin API/Filter Reference中的filter manage_link_columns,添加自定义栏。
manage_posts_custom_column
管理文章管理界面有未知的栏名称的时候,运行。Action function arguments:栏名,文章ID。也看看WordPress:Plugin API/Filter Reference中的filter manage_posts_columns,添加了自定义栏。(关于例子和使用,请看看Scompt的指南。)
manage_pages_custom_column
管理网页管理界面有未知的栏名称的时候,运行。Action function arguments:栏名,网页ID。也看看 Plugin API/Filter Reference中的filter manage_pages_columns,添加了自定义栏。
password_reset
用户密码重新设置为随意的新密码之前,运行。
personal_options_update
用户从管理界面更新个人选项的时候,运行。
plugins_loaded
载入所有插件的时候,运行。
profile_personal_options
在用户基本资料编辑界面的个人选项部分的结尾部分,运行。
profile_update
更新用户基本资料的时候,运行。Action function argument: 用户 ID。
register_form
新的用户注册形式结束之前,运行。
register_post
处理新的用户注册请求之前,运行。
restrict_manage_posts
文章放到管理菜单界面中编辑之前,运行。
retrieve_password
返回用户密码时,运行,向用户发送电子邮件提醒。Action function argument:注册名。
set_current_user
用户被默认的wp_set_current_user函数更改后,运行。注意wp_set_current_user也是个"pluggable"函数,意思是插件可以取代这个函数。请看看插件API。)
show_user_profile
在用户基本资料编辑界面的结束部分附近,运行。
simple_edit_form
在管理菜单的"简单"文章编辑形式的结尾,运行(默认情况下,只有bookmarklets使用简单形式—没有"高级"部分)。
update_option_(option_name)
WordPress选项已经由update_option函数更新后,运行。Action function arguments:旧选项参数值,新的选项参数值。你必须为你想要回应的选项添加一个action,例如更新了选项"foo"时,回应update_option_foo
upload_files_(tab)
运行,在管理界面上传文件上产生界面;"tab"是自定义action 标签的名称。使用wp_upload_tabs filter定义自定义的标签(请看看 Plugin API/Filter Reference)。
user_register
首次创建用户基本资料的时候,运行。Action function argument: 用户 ID。
wp_ajax_(action)
运行,在管理菜单中操作未知类型的AJAX。
wp_authenticate
用于用户登录时,确认用户。Action function arguments:用户名和密码数组。
wp_login
用户登录时,运行。
wp_logout
用户退出时,运行。

Advanced Actions

这个部分包含了与WordPress使用的查询相关的actions,取人要显示什么文章,WordPress Loop,激活插件,以及其它基本的WordPress代码。

admin_menu
基本的管理面板菜单结构到位后,运行。
admin_notices
管理菜单出现在界面上后,运行。
blog_privacy_selector
默认博客保密选项出现在界面上后,运行。
check_admin_referer
nonce经过了安全检查后,在默认check_admin_referrer函数中,运行,允许插件迫使WordPress因为额外的安全考虑,而停止运行。注意check_admin_referrer也是"pluggable"函数,指的是插件可以代替这个函数;请看看插件API)。
check_ajax_referer
在默认check_ajax_referer函数中运行(当AJAX请求进入了wp-admin/admin-ajax.php脚本,这个函数得到调用),cookies成功地确认了用户登录和密码后,允许插件迫使WordPress停止运行,以增加安全性。注check_ajax_referer也是个"pluggable"函数,意思是插件可以代替这个函数;请看看插件API)。
generate_rewrite_rules
产生rewrite 规则之后,运行。Action function arguments: WP_Rewrite class variables作为列表。注意,使用rewrite_rules_array比使用这个action,更易于更改rewrite 规则。
init
WordPress结束了载入,但是在发送任何标头之前,运行。有利于截取$_GET or $_POST triggers。
loop_end
运行WordPress loop最后一篇文章的时候,运行。
loop_start
运行WordPress loop中第一篇文章之前,运行。
parse_query
在查询解析结束后,运行。Action function arguments: $wp_query object的内容作为列表。
parse_request
查询请求在主要的WordPress函数 wp中解析后,运行。Action function argument: an array with a reference to the global $wp object.
pre_get_posts
get_posts函数查询之前,运行。Action function argument: $wp_query object的内容,作为列表。
sanitize_comment_cookies
cookies已经从HTTP请求中读出之后,运行。
send_headers
基本的HTTP标头发送到主要的WordPress函数wp内部后,运行。Action function argument: an array with a reference to the global $wp object.
shutdown
输出网页后,运行。
wp
查询已经解析并且文章载入后,运行,但是在运行模板之前,在主要的WordPress函数wp中。如果你需要使用文章数据,但是不能使用模板输出数据,这个有用。Action function argument: an array with a reference to the global $wp object.

深入阅读

  • 编写插件 – 描述怎样编写插件
  • 插件API – 关于怎样使用filters和actions的文章
  • Plugin API/Filter Reference - reference list for filter hooks
  • 插件资源 – 插件相关资源的完整列表
  • Skippy's list of actions and filters
  • WordPress Hooks, a work in progress directory of all of WordPress’ hooks.
  • WordPress Hooks 数据库, a database of all WordPress的所有的hooks的数据库,显示这些hooks是源自那个版本,并且链接到使用这些hooks的源代码。
  • Angsuman's list, a comprehensive listing of WordPress action hooks 的完整列表,带有文件和源代码位置信息。包含了WordPress2.0中所有备有文件证明的和没有备有文件正面的action hooks。