# wordpress 的action钩子的动作名

(If you want to add to or clarify this documentation, please follow the style of the existing entries. Describe when the action runs, and if the action function takes arguments, describe the arguments.)

[hide]

## Actions Run During a Typical Request

These actions are called when a logged-in user opens the home page in Version 3.3.1. This list may show only the first time each action is called, and in many cases no function is hooked to the action. Themes and plugins can cause actions to be called multiple times and at differing times during a request. As proof of this, you can see action calls specific to the Twenty Eleven theme on this list. Cron tasks may also fire when a user visits the site, adding additional action calls. This list should be viewed as a guide line or approximation of WordPress action execution order, and not a concrete specification.

Actions are called with the function do_action, except those marked (ref array), which are called with the functiondo_action_ref_array.

## Actions Run During an Admin Page Request

These actions are run when a logged-in user opens the Posts page in Version 3.3.1. This list shows only the first time an action is called, and in many cases no function is hooked to the action. Each admin page has a different list of actions depending upon the purpose of the page and the plugins installed. This list should be viewed as a guide line or approximation, and not a concrete specification.

In these actions, (hookname) depends on the page. For the Posts page it isedit.php, or for a theme's Background page it isappearance_page_custom-background.

Actions are called with the function do_action, except those marked (ref array), which are called with the functiondo_action_ref_array.

## Post, Page, Attachment, and Category Actions (Admin)

Runs when an attached file is first added to the database. Action function arguments: attachment ID.
Same as create_category.
clean_post_cache
Runs when post cache is cleaned. Action function arguments: post ID. See clean_post_cache().
create_category
Runs when a new category is created. Action function arguments: category ID.
delete_attachment
Runs just after an attached file is deleted from the database. Action function arguments: attachment ID.
delete_category
Runs just after a category is deleted from the database and its corresponding links/posts are updated to remove the category. Action function arguments: category ID.
trash_post
Runs when a post or page is about to be trashed. Action function arguments: post or page ID.
trashed_post
Runs just after a post or page is trashed. Action function arguments: post or page ID.
before_delete_post
Runs when a post or page is about to be deleted. Comments, attachments and metadata are still available. Action function arguments: post or page ID.
delete_post
Runs when a post or page is about to be deleted. Comments, attachments and metadata are already deleted. Action function arguments: post or page ID.
deleted_post
Runs just after a post or page is deleted. Action function arguments: post or page ID.
edit_attachment
Runs when an attached file is edited/updated to the database. Action function arguments: attachment ID.
edit_category
Runs when a category is updated/edited, including when a post or blogroll link is added/deleted or its categories are updated (which causes the count for the category to update). Action function arguments: category ID.
edit_post
Runs when a post or page is updated/edited, including when a comment is added or updated (which causes the comment count for the post to update). Action function arguments: post or page ID.
pre_post_update
Runs just before a post or page is updated. Action function arguments: post Content.
private_to_publish
(See also Post Status Transitions) Runs when a post is changed from private to published status. Action function arguments: post object. (Actions for all post status transitions are available: see wp_transition_post_status()).
publish_page
Runs when a page is published, or if it is edited and its status is "published". Action function arguments: page ID. (WARNING: this hook seems to never fire on v2.3 and higher. The 'transition_post_status' hook does work though; UPDATE : publish_page hook appears to be working as of 2.6)
publish_phone
Runs just after a post is added via email. Action function argument: post ID.
publish_post
Runs when a post is published, or if it is edited and its status is "published". Action function arguments: post ID.
publish_future_post
Runs when a future post or page is published. Action function arguments: post ID.
save_post
Runs whenever a post or page is created or updated, which could be from an import, post/page edit form, xmlrpc, or post by email. Action function arguments: post ID and post object.

Runs after the data is saved to the database.

Note that post ID may reference a post revision and not the last saved post. Usewp_is_post_revision() to get the ID of the real post.

wp_insert_post
Same as save_post, runs immediately afterwards.
xmlrpc_publish_post
Runs when a post is published via XMLRPC request, or if it is edited via XMLRPC and its status is "published". Action function arguments: post ID.

## Comment, Ping, and Trackback Actions

comment_closed
Runs when the post is marked as not allowing comments while trying to display comment entry form. Action function argument: post ID.
comment_id_not_found
Runs when the post ID is not found while trying to display comments or comment entry form. Action function argument: post ID.
comment_flood_trigger
Runs when a comment flood is detected, just before wp_die is called to stop the comment from being accepted. Action function arguments: time of previous comment, time of current comment.
comment_(old status)_to_(new status)
Runs when a comment status transition occurs. Action function arguments: Comment object.
comment_on_draft
Runs when the post is a draft while trying to display a comment entry form or comments. Action function argument: post ID.
comment_post
Runs just after a comment is saved in the database. Action function arguments: comment ID, approval status ("spam", or 0/1 for disapproved/approved).
edit_comment
Runs after a comment is updated/edited in the database. Action function arguments: comment ID.
delete_comment
Runs just before a comment is deleted. Action function arguments: comment ID.
deleted_comment
Runs just after a comment is deleted. Action function arguments: comment ID.
trash_comment
Runs just before a comment is trashed. Action function arguments: comment ID.
trashed_comment
Runs just after a comment is trashed. Action function arguments: comment ID.
comment_closed
Runs when the post is marked as not a spam.
pingback_post
Runs when a ping is added to a post. Action function argument: comment ID.
pre_ping
Runs before a ping is fully processed. Action function arguments: array of the post links to be processed, and the "pung" setting for the post.
Runs when a trackback is added to a post. Action function argument: comment ID.
wp_blacklist_check
Runs to check whether a comment should be blacklisted. Action function arguments: author name, author email, author URL, comment text, author IP address, author's user agent (browser). Your function can execute awp_die to reject the comment, or perhaps modify one of the input arguments so that it will contain one of the blacklist keywords set in the WordPress options.
wp_set_comment_status
Runs when the status of a comment changes. Action function arguments: comment ID, status string indicating the new status ("delete", "approve", "spam", "hold").

## Blogroll Actions

Runs when a new blogroll link is first added to the database. Action function arguments: link ID.
Runs when a blogroll link is deleted. Action function arguments: link ID.
Runs when a blogroll link is edited. Action function arguments: link ID.

## Feed Actions

atom_entry
Runs just after the entry information has been printed (but before closing the entry tag) for each blog entry in an atom feed.
Runs just after the blog information has been printed in an atom feed, just before the first entry.
atom_ns
Runs inside the root XML element for an atom feed (to add namespaces).
Runs just after a single comment's information has been printed in a comment feed (but before closing the item tag). Action function arguments: comment ID, post ID.
do_feed_(feed)
Runs when a feed is generated, where feed is the type of feed (rss2, atom, rdf, etc.). Usepriority less than 10 to runbefore printing the feed. Action function argument:true (the feed is for comments) orfalse (it is for posts).
Runs just after the blog information has been printed in an RDF feed, just before the first entry.
rdf_item
Runs just after the entry information has been printed (but before closing the item tag) for each blog entry in an RDF feed.
rdf_ns
Runs inside the root XML element in an RDF feed (to add namespaces).
Runs just after the blog information has been printed in an RSS feed, just before the first entry.
Runs just after the entry information has been printed (but before closing the item tag) for each blog entry in an RSS feed.
Runs just after the blog information has been printed in an RSS 2 feed, just before the first entry.
Runs just after the entry information has been printed (but before closing the item tag) for each blog entry in an RSS 2 feed.
Runs inside the root XML element in an RSS 2 feed (to add namespaces).

## Template Actions

after_setup_theme
Runs during a themes initialization. Is generally used to perform basic setup, registration, and init actions for a theme.
comment_form
Runs in standard themes to insert the comment form. Action function argument: post ID.
do_robots
Runs when the template file chooser determines that it is a robots.txt request.
do_robotstxt
Runs in the do_robots function before it prints out the Disallow lists for the robots.txt file.
get_footer
Runs when the template calls the get_footer function, just before thefooter.php template file is loaded.
switch_theme
Runs when the blog's theme is changed. Action function argument: name of the new theme.
template_redirect
Runs before the determination of the template file to be used to display the requested page.
wp_footer
Runs when the template calls the wp_footer function, generally near the bottom of the blog page.
Runs when the template calls the wp_head function. This hook is generally placed near the top of a page template between<head> and</head>. This hook does not take any parameters.
wp_meta
Runs when the sidebar.php template file calls the wp_meta function, to allow the plugin to insert content into the sidebar.
wp_print_scripts
Runs just before WordPress prints registered JavaScript scripts into the page header.

activate_(plugin file name)
Runs when the plugin is first activated. See Function_Reference/register_activation_hook.
activity_box_end
Runs at the end of the activity box on the admin Dashboard screen.
Runs in the HTML <head> section of a specific admin page or the admin panel of a plugin-generated page.
Runs at the end of the <body> section of the admin panel of a plugin-generated page.
Runs at the end of the admin panel inside the body tag
Runs in the HTML header so a plugin or theme can enqueue JavaScript and CSS to all admin pages.
function myplugin_menu() {
$page = add_management_page( 'myplugin', 'myplugin', 'manage_options', 'myplugin_slug', 'myplugin_admin_page' ); add_action( "admin_print_scripts-$page", 'myplugin_admin_head' );
}
}

Runs when styles should be enqueued with wp_enqueue_style() for a particular admin page. Use the return value of a function such asadd_submenu_page() to determine the value of (page_hook).
Runs to validate the double-entry of password when creating a new user. Action function arguments: array of login name, first password, second password.
Runs at the bottom of the "advanced" section on the page editing screen in the admin menus.
dbx_page_sidebar
Runs at the bottom of the sidebar on the page editing screen in the admin menus.
Runs at the bottom of the "advanced" section on the post editing screen in the admin menus.
dbx_post_sidebar
Runs at the bottom of the sidebar on the post editing screen in the admin menus. Useadd_meta_box() in Wordpress 2.5 and higher.
deactivate_(plugin file name)
Runs when a plugin is deactivated.
delete_user
Runs when a user is deleted. Action function arguments: user 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_pre
Runs before the edit category form is put on the screen in the admin menus.
edit_tag_form
Runs after the add/edit tag form is put on the screen (but before the end of the HTML form tag).
edit_tag_form_pre
Runs before the edit tag form is put on the screen in the admin menus.
edit_page_form
edit_user_profile
Runs near the end of the user profile editing screen in the admin menus.
Runs just before the end of the login form.
Runs just before the end of the HTML head section of the login page.
Runs at the end of the form used to retrieve a user's password by email, to allow a plugin to supply extra fields.
runs when the user has requested an email message to retrieve their password, to allow a plugin to modify the PHP$_POST variable before processing. 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 filtermanage_link_columns in thePlugin API/Filter Reference, which adds custom columns. 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 filtermanage_posts_columns in the Plugin API/Filter Reference, which adds custom columns. (see Scompt's tutorial for examples and use.) 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 filtermanage_pages_columns in the Plugin API/Filter Reference, which adds custom columns. manage_{$post_type}_posts_custom_column
Runs when there is an unknown column name for the managing custom post type admin screen. Action function arguments: column name, post ID. See also filtermanage_${post_type}_posts_columns in the Plugin API/Filter Reference, which adds custom columns for custom post types. password_reset Runs before the user's password is reset to a random new password. personal_options_update Runs when a user updates personal options from the admin screen. plugins_loaded Runs after all plugins have been loaded. profile_personal_options Runs at the end of the Personal Options section of the user profile editing screen. profile_update Runs when a user's profile is updated. Action function argument: user ID. quick_edit_custom_box Runs when there is an unknown column name when creating the quick editor. register_form Runs just before the end of the new user registration form. register_post Runs before a new user registration request is processed. restrict_manage_posts Runs before the list of posts to edit is put on the screen in the admin menus. retrieve_password Runs when a user's password is retrieved, to send them a reminder email. Action function argument: login name. set_current_user Runs after the user has been changed by the default wp_set_current_user function. Note thatwp_set_current_user is also a "pluggable" function, meaning that plugins can override it; seePlugin API). show_user_profile Runs near the end of the user profile editing screen. 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). update_option_(option_name) Runs after a WordPress option has been updated by the update_option 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 asupdate_option_foo to respond when option "foo" has been updated. 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 thewp_upload_tabs filter (seePlugin API/Filter Reference). user_register Runs when a user's profile is first created. Action function argument: user ID. wp_ajax_(action) Runs to do an unknown type of AJAX action in the administrative menus. wp_authenticate Runs to authenticate a user when they log in. Action function arguments: array with user name and password. wp_login Runs when a user logs in. wp_logout Runs when a user logs out. ### Dashboard "Right Now" Widget Actions right_now_content_table_end Adds table rows at the bottom the content column of the Right Now Dashboard widget. right_now_table_end Called after displaying the number of Spam comments in the Discussion column of the Right Now Dashboard widget. right_now_discussion_table_end Called after displaying the number of Spam comments and after the right_now_table_end action in the Discussion column of the Right Now Dashboard widget. right_now_end Called after the current version information is displayed on the Right Now Dashboardwidget. activity_box_end Last action called on the Right Now Dashboard widget. ## 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. add_meta_boxes Runs when "edit post" page loads. (3.0+) admin_menu Runs after the basic admin panel menu structure is in place. network_admin_notices Runs after the admin menu is printed to network admin screens. user_admin_notices Runs after the admin menu is printed to user admin screens. admin_notices Runs after the admin menu is printed to screens that aren't network- or user-admin screens. all_admin_notices Runs after the admin menu is printed to all screens. blog_privacy_selector Runs after the default blog privacy options are printed on the screen. check_admin_referer Runs in the default check_admin_referrer function after the nonce has been checked for security purposes, to allow a plugin to force WordPress to die for extra security reasons. Note thatcheck_admin_referrer is also a "pluggable" function, meaning that plugins can override it; seePlugin API). check_ajax_referer Runs in the default check_ajax_referer function (which is called when an AJAX request goes to thewp-admin/admin-ajax.php 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 thatcheck_ajax_referer is also a "pluggable" function, meaning that plugins can override it; seePlugin API). generate_rewrite_rules Runs after the rewrite rules are generated. Action function arguments: WP_Rewrite object ($wp_rewrite) by reference. Note that it is easier to use therewrite_rules_array filter instead of this action, to modify the rewrite rules.
init
Runs after WordPress has finished loading but before any headers are sent. Useful for intercepting $_GET or$_POST triggers.
loop_end
Runs after the last post of the WordPress loop is processed.
loop_start
Runs before the first post of the WordPress loop is processed.
parse_query
Runs at the end of query parsing in the main query or any instance of WP_Query, such as query_posts, get_posts, or get_children. Action function arguments: WP_Query object by reference.
parse_request
Runs after the query request is parsed inside the main WordPress function wp. Action function argument: WP object ($wp) by reference. pre_get_posts Runs before a query is executed in the main query or any instance of WP_Query, such as query_posts, get_posts, or get_children. Action function arguments: WP_Query object by reference. sanitize_comment_cookies Runs after cookies have been read from the HTTP request. send_headers Runs after the basic HTTP headers are sent inside the main WordPress functionwp. Action function argument:WP object ($wp) by reference.
shutdown
Runs when the page output is complete.