wordpress 的action钩子的动作名

来源:互联网 发布:java增删改查sql语句 编辑:程序博客网 时间:2024/06/05 22:44

This article is a (hopefully complete) list of the action hooks available for use in plugin development in Version 2.1 and above of WordPress. For more information:

  • To learn more about what filter and action hooks are, see Plugin API.
  • To learn about writing plugins in general, see Writing a Plugin.
  • For a reference list of filter hooks, see Plugin API/Filter Reference.
  • For information about filter and action hooks in previous versions of WordPress, seePlugin API/Hooks 2.0.x.

(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.)

Contents

[hide]
  • 1Actions Run During a Typical Request
  • 2Actions Run During an Admin Page Request
  • 3Post, Page, Attachment, and Category Actions (Admin)
  • 4Comment, Ping, and Trackback Actions
  • 5Blogroll Actions
  • 6Feed Actions
  • 7Template Actions
  • 8Administrative Actions
    • 8.1Dashboard "Right Now" Widget Actions
  • 9Advanced Actions
  • 10Further Reading

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.

muplugins_loadedAfter must-use plugins are loadedregistered_taxonomyFor category, post_tag, etc.registered_post_typeFor post, page, etc.plugins_loadedAfter active plugins and pluggable functions are loadedsanitize_comment_cookies setup_theme load_textdomainFor the default domainafter_setup_themeGenerally used to initialize theme settings/options.auth_cookie_malformed auth_cookie_valid set_current_user initTypically used by plugins to initializewidgets_init register_sidebarFor each sidebar and footer areawp_register_sidebar_widgetFor each widgetwp_default_scripts(ref array)wp_default_styles(ref array)admin_bar_init add_admin_bar_menus wp_loadedAfter WordPress is fully loadedparse_request(ref array)send_headers(ref array)parse_query(ref array)pre_get_postsExposes the query-variables object before a query is executed. (ref array)posts_selection wpAfter WP object is set up (ref array)template_redirect get_header wp_head wp_enqueue_scripts twentyeleven_enqueue_color_scheme (Specific to Twenty Eleven)wp_print_styles wp_print_scripts get_search_form loop_start(ref array)the_post(ref array)get_template_part_contentTemplate part for the contentloop_end(ref array)get_sidebar dynamic_sidebar get_search_form pre_get_postsExposes the query-variables object before a query is executed. (ref array)pre_get_comments(ref array)wp_meta get_footer get_sidebarThis 'sidebar' is a footer areatwentyeleven_credits(Specific to Twenty Eleven)wp_footer wp_print_footer_scripts admin_bar_menu(ref array)wp_before_admin_bar_render wp_after_admin_bar_render shutdownPHP execution is about to end

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.

muplugins_loadedAfter must-use plugins are loadedregistered_taxonomyFor category, post_teg, etc.registered_post_typeFor post, page, etc.plugins_loadedAfter active plugins and pluggable functions are loadedsanitize_comment_cookiessetup_themeload_textdomainFor domain defaultafter_setup_themeload_textdomainFor domain twentyelevenauth_cookie_validset_current_userinitTypically used by plugins to initializewidgets_initregister_sidebarFor each sidebarwp_register_sidebar_widgetFor each widgetwp_default_scripts(ref array)wp_default_styles(ref array)admin_bar_initadd_admin_bar_menuswp_loadedAfter WordPress is fully loadedauth_cookie_validauth_redirect_admin_menuSee also: _user_admin_menu, _network_admin_menuadmin_menuSee also: user_admin_menu, network_admin_menuadmin_initcurrent_screenload-(hookname)parse_request(ref array)send_headers(ref array)parse_query(ref array)pre_get_postsExposes the query-variables object before a query is executed. (ref array)posts_selectionwpAfter WP object is set up (ref array)admin_xml_nsadmin_xml_nsadmin_enqueue_scriptsadmin_print_styles-(hookname)admin_print_stylesadmin_print_scripts-(hookname)admin_print_scriptswp_print_scriptsadmin_head-(hookname)admin_headadminmenuin_admin_headeradmin_noticesall_admin_notices(hookname)restrict_manage_poststhe_post(ref array)pre_user_query(ref array)pre_user_query(ref array)in_admin_footeradmin_footeradmin_bar_menu(ref array)wp_before_admin_bar_renderwp_after_admin_bar_renderadmin_print_footer_scriptsadmin_footer-(hookname)shutdownPHP execution is about to end

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

add_attachment 
Runs when an attached file is first added to the database. Action function arguments: attachment ID.
add_category 
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.
trackback_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

add_link 
Runs when a new blogroll link is first added to the database. Action function arguments: link ID.
delete_link 
Runs when a blogroll link is deleted. Action function arguments: link ID.
edit_link 
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.
atom_head 
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).
commentrss2_item 
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).
rdf_header 
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).
rss_head 
Runs just after the blog information has been printed in an RSS feed, just before the first entry.
rss_item 
Runs just after the entry information has been printed (but before closing the item tag) for each blog entry in an RSS feed.
rss2_head 
Runs just after the blog information has been printed in an RSS 2 feed, just before the first entry.
rss2_item 
Runs just after the entry information has been printed (but before closing the item tag) for each blog entry in an RSS 2 feed.
rss2_ns 
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.
get_header 
Runs when the template calls the get_header function, just before theheader.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.
wp_head 
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.

Administrative Actions

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.
add_category_form_pre 
Runs before the add category form is put on the screen in the admin menus.
admin_head 
Runs in the HTML <head> section of the admin panel.
admin_head-(page_hook) or admin_head-(plugin_page) 
Runs in the HTML <head> section of a specific admin page or the admin panel of a plugin-generated page.
admin_init 
Runs at the beginning of every admin page before the page is rendered. See wp-admin/admin.php, wp-admin/admin-post.php, and wp-admin/admin-ajax.php.
admin_footer-(plugin_page) 
Runs at the end of the <body> section of the admin panel of a plugin-generated page.
admin_footer 
Runs at the end of the admin panel inside the body tag
admin_enqueue_scripts 
Runs in the HTML header so a plugin or theme can enqueue JavaScript and CSS to all admin pages.
admin_print_scripts 
Runs in the HTML header so a plugin can add JavaScript scripts to all admin pages.
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:
function myplugin_menu() {  if ( function_exists('add_management_page') ) {    $page = add_management_page( 'myplugin', 'myplugin', 'manage_options', 'myplugin_slug', 'myplugin_admin_page' );    add_action( "admin_print_scripts-$page", 'myplugin_admin_head' );  }} 
admin_print_styles 
Runs in the HTML header so a plugin can add CSS/Stylesheets to all admin pages.
admin_print_styles-(page_hook) or admin_print_style-(plugin_page) 
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).
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.
dbx_page_advanced 
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.
dbx_post_advanced 
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_form_advanced 
Runs just before the "advanced" section of the post editing form in the admin menus.
edit_page_form 
Runs just before the "advanced" section of the page editing form in the admin menus.
edit_user_profile 
Runs near the end of the user profile editing screen in the admin menus.
load-(page) 
Runs when an administration menu page is loaded. This action is not usually added directly -- seeAdding Administration Menus for more details of how to add admin menus. If you do want to use it directly, the return value fromadd_options_page and similar functions gives you the(page) part of the action name.
login_form 
Runs just before the end of the login form.
login_head 
Runs just before the end of the HTML head section of the login page.
lost_password 
Runs before the "retrieve your password by email" form is printed on the login screen.
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_post 
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.
network_admin_menu 
Runs when the basic menu structure is prepared for the Network administration page. (Administration Menus)
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.
wp_loaded 
This hook is fired once WP, all plugins, and the theme are fully loaded and instantiated.
wp 
Executes after the query has been parsed and post(s) loaded, but before any template execution, inside the main WordPress functionwp. Useful if you need to have access to post data but can't use templates for output. Action function argument:WP object ($wp) by reference.

原创粉丝点击