do_action( string $tag, mixed $arg )
Execute functions hooked on a specific action hook.
Description #Description
This function invokes all functions attached to action hook $tag
. It is possible to create new action hooks by simply calling this function, specifying the name of the new hook using the $tag
parameter.
You can pass extra arguments to the hooks, much like you can with apply_filters()
.
Example usage:
// The action callback function
function example_callback( $arg1, $arg2 ) {
// (maybe) do something with the args
}
add_action( 'example_action', 'example_callback', 10, 2 );
/*
* Trigger the actions by calling the 'example_callback()' function that's
* hooked onto `example_action` above.
*
* - 'example_action' is the action hook
* - $arg1 and $arg2 are the additional arguments passed to the callback.
$value = do_action( 'example_action', $arg1, $arg2 );
Parameters #Parameters
- $tag
-
(string) (Required) The name of the action to be executed.
- $arg
-
(mixed) (Optional) Additional arguments which are passed on to the functions hooked to the action. Default empty.
Source #Source
File: wp-includes/plugin.php
function do_action( $tag, ...$arg ) { global $wp_filter, $wp_actions, $wp_current_filter; if ( ! isset( $wp_actions[ $tag ] ) ) { $wp_actions[ $tag ] = 1; } else { ++$wp_actions[ $tag ]; } // Do 'all' actions first if ( isset( $wp_filter['all'] ) ) { $wp_current_filter[] = $tag; $all_args = func_get_args(); _wp_call_all_hook( $all_args ); } if ( ! isset( $wp_filter[ $tag ] ) ) { if ( isset( $wp_filter['all'] ) ) { array_pop( $wp_current_filter ); } return; } if ( ! isset( $wp_filter['all'] ) ) { $wp_current_filter[] = $tag; } if ( empty( $arg ) ) { $arg[] = ''; } elseif ( is_array( $arg[0] ) && 1 === count( $arg[0] ) && isset( $arg[0][0] ) && is_object( $arg[0][0] ) ) { // Backward compatibility for PHP4-style passing of `array( &$this )` as action `$arg`. $arg[0] = $arg[0][0]; } $wp_filter[ $tag ]->do_action( $arg ); array_pop( $wp_current_filter ); }
Expand full source code Collapse full source code View on Trac
Changelog #Changelog
Version | Description |
---|---|
5.3.0 | Formalized the existing and already documented ...$arg parameter by adding it to the function signature. |
1.2.0 | Introduced. |
Related #Related
Uses #Uses
Uses | Description |
---|---|
wp-includes/plugin.php: _wp_call_all_hook() |
Call the ‘all’ hook, which will process the functions hooked into it. |
Used By #Used By
Used By | Description |
---|---|
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php: WP_REST_Attachments_Controller::insert_attachment() |
Inserts the attachment post in the database. Does not update the attachment meta. |
wp-admin/includes/class-wp-ms-sites-list-table.php: WP_MS_Sites_List_Table::extra_tablenav() |
Extra controls to be displayed between bulk actions and pagination. |
wp-includes/class-wp-recovery-mode-key-service.php: WP_Recovery_Mode_Key_Service::generate_and_store_recovery_mode_key() |
Creates a recovery mode key. |
wp-includes/general-template.php: wp_body_open() |
Fire the wp_body_open action. |
wp-includes/ms-site.php: wp_maybe_transition_site_statuses_on_update() |
Triggers actions on site status updates. |
wp-includes/ms-site.php: wp_prepare_site_data() |
Prepares site data for insertion or update in the database. |
wp-includes/ms-site.php: wp_insert_site() |
Inserts a new site into the database. |
wp-includes/ms-site.php: wp_update_site() |
Updates a site in the database. |
wp-includes/ms-site.php: wp_delete_site() |
Deletes a site from the database. |
wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php: WP_REST_Autosaves_Controller::create_post_autosave() |
Creates autosave for the specified post. |
wp-includes/script-loader.php: wp_common_block_scripts_and_styles() |
Handles the enqueueing of block scripts and styles that are common to both the editor and the front-end. |
wp-admin/includes/post.php: the_block_editor_meta_box_post_form_hidden_fields() |
Renders the hidden form required for the meta boxes form. |
wp-admin/includes/meta-boxes.php: register_and_do_post_meta_boxes() |
Registers the default post meta boxes, and runs the |
wp-admin/includes/privacy-tools.php: wp_privacy_process_personal_data_export_page() |
Intercept personal data exporter page Ajax responses in order to assemble the personal data export file. |
wp-admin/includes/privacy-tools.php: wp_privacy_generate_personal_data_export_file() |
Generate the personal data export file. |
wp-admin/includes/privacy-tools.php: wp_privacy_process_personal_data_erasure_page() |
Mark erasure requests as completed after processing is finished. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::trash_changeset_post() |
Trash or delete a changeset post. |
wp-includes/taxonomy.php: clean_taxonomy_cache() |
Clean the caches for a taxonomy. |
wp-includes/general-template.php: wp_enqueue_code_editor() |
Enqueue assets needed by the code editor for the given settings. |
wp-includes/class-wp-roles.php: WP_Roles::init_roles() |
Initializes all of the available roles. |
wp-includes/class-wp-editor.php: _WP_Editors::print_default_editor_scripts() |
Print (output) all editor scripts and default settings. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::_publish_changeset_values() |
Publish changeset values. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::save_changeset_post() |
Save the post for the loaded changeset. |
wp-includes/theme.php: _wp_customize_publish_changeset() |
Publishes a snapshot’s changes. |
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::delete_item() |
Deletes a single user. |
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::create_item() |
Creates a single user. |
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::update_item() |
Updates a single user. |
wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php: WP_REST_Revisions_Controller::delete_item() |
Deletes a single revision. |
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php: WP_REST_Attachments_Controller::create_item() |
Creates a single attachment. |
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php: WP_REST_Attachments_Controller::update_item() |
Updates a single attachment. |
wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php: WP_REST_Terms_Controller::delete_item() |
Deletes a single term from a taxonomy. |
wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php: WP_REST_Terms_Controller::create_item() |
Creates a single term in a taxonomy. |
wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php: WP_REST_Terms_Controller::update_item() |
Updates a single term from a taxonomy. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::create_item() |
Creates a single post. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::update_item() |
Updates a single post. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php: WP_REST_Posts_Controller::delete_item() |
Deletes a single post. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::update_item() |
Updates a comment. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::delete_item() |
Deletes a comment. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::create_item() |
Creates a comment. |
wp-includes/class-wp-locale-switcher.php: WP_Locale_Switcher::change_locale() |
Changes the site’s locale to the given one. |
wp-includes/class-wp-locale-switcher.php: WP_Locale_Switcher::switch_to_locale() |
Switches the translations according to the given locale. |
wp-includes/class-wp-locale-switcher.php: WP_Locale_Switcher::restore_previous_locale() |
Restores the translations according to the previous locale. |
wp-includes/comment.php: wp_check_comment_flood() |
Checks whether comment flooding is occurring. |
wp-includes/class-wp-term-query.php: WP_Term_Query::get_terms() |
Get terms, based on query_vars. |
wp-includes/class-wp-term-query.php: WP_Term_Query::parse_query() |
Parse arguments passed to the term query with default query parameters. |
wp-includes/ms-network.php: clean_network_cache() |
Removes a network from the object cache. |
wp-includes/functions.php: _deprecated_hook() |
Marks a deprecated action or filter hook as deprecated and throws a notice. |
wp-includes/ms-load.php: ms_load_current_site_and_network() |
Identifies the network and site of a requested domain and path and populates the corresponding network and site global objects as part of the multisite bootstrap process. |
wp-includes/rest-api.php: rest_get_server() |
Retrieves the current REST server instance. |
wp-includes/class-wp-metadata-lazyloader.php: WP_Metadata_Lazyloader::queue_objects() |
Adds objects to the metadata lazy-load queue. |
wp-includes/taxonomy.php: unregister_taxonomy() |
Unregisters a taxonomy. |
wp-includes/post.php: unregister_post_type() |
Unregisters a post type. |
wp-includes/customize/class-wp-customize-selective-refresh.php: WP_Customize_Selective_Refresh::handle_render_partials_request() |
Handles the Ajax request to return the rendered partials for the requested placements. |
wp-includes/embed.php: enqueue_embed_scripts() |
Enqueue embed iframe default CSS and JS & fire do_action(‘enqueue_embed_scripts’) |
wp-includes/user.php: get_password_reset_key() |
Creates, stores, then returns a password reset key for user. |
wp-includes/comment.php: wp_handle_comment_submission() |
Handles the submission of a comment, usually posted to wp-comments-post.php via a comment form. |
wp-includes/option.php: update_network_option() |
Update the value of a network option that was already added. |
wp-includes/option.php: add_network_option() |
Add a new network option. |
wp-includes/option.php: delete_network_option() |
Removes a network option by name. |
wp-admin/includes/ajax-actions.php: wp_ajax_delete_inactive_widgets() |
Ajax handler for removing inactive widgets. |
wp-includes/functions.php: _deprecated_constructor() |
Marks a constructor as deprecated and informs when it has been used. |
wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::column_default() |
Handles the default column output. |
wp-admin/includes/class-wp-links-list-table.php: WP_Links_List_Table::column_default() |
Handles the default column output. |
wp-admin/includes/class-wp-ms-themes-list-table.php: WP_MS_Themes_List_Table::column_default() |
Handles default column output. |
wp-admin/includes/ajax-actions.php: wp_ajax_crop_image() |
Ajax handler for cropping an image. |
wp-admin/includes/class-wp-ms-sites-list-table.php: WP_MS_Sites_List_Table::column_default() |
Handles output for the default column. |
wp-admin/includes/class-wp-ms-sites-list-table.php: WP_MS_Sites_List_Table::column_plugins() |
Handles the plugins column output. |
wp-admin/includes/class-wp-media-list-table.php: WP_Media_List_Table::column_default() |
Handles output for the default column. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::set_post_value() |
Override a setting’s value in the current customized state. |
wp-includes/class-wp-customize-panel.php: WP_Customize_Panel::maybe_render() |
Check capabilities and render the panel. |
wp-login.php: login_footer() |
Outputs the footer for the login page. |
wp-login.php: retrieve_password() |
Handles sending password retrieval email to user. |
wp-login.php: login_header() |
Output the login page header. |
wp-signup.php: show_user_form() |
Display user registration form |
wp-signup.php: signup_another_blog() |
Allow returning users to sign up for another site |
wp-signup.php: confirm_another_blog_signup() |
Confirm a new site signup. |
wp-signup.php: signup_user() |
Setup the new user signup process |
wp-signup.php: confirm_user_signup() |
New user signup confirmation |
wp-signup.php: signup_blog() |
Setup the new site signup |
wp-signup.php: confirm_blog_signup() |
New site signup confirmation |
wp-signup.php: do_signup_header() |
Prints signup_header via wp_head |
wp-signup.php: show_blog_form() |
Generates and displays the Signup and Create Site forms |
wp-admin/install.php: display_setup_form() |
Display installer setup form. |
wp-admin/includes/class-wp-automatic-updater.php: WP_Automatic_Updater::update() |
Update an item, if appropriate. |
wp-admin/includes/class-wp-automatic-updater.php: WP_Automatic_Updater::run() |
Kicks off the background update process, looping through all pending updates. |
wp-admin/includes/class-language-pack-upgrader.php: Language_Pack_Upgrader::bulk_upgrade() |
Bulk upgrade language packs. |
wp-admin/includes/class-core-upgrader.php: Core_Upgrader::upgrade() |
Upgrade WordPress core. |
wp-admin/includes/class-theme-upgrader.php: Theme_Upgrader::bulk_upgrade() |
Upgrade several themes at once. |
wp-admin/includes/class-plugin-upgrader.php: Plugin_Upgrader::bulk_upgrade() |
Bulk upgrade several plugins at once. |
wp-admin/includes/class-wp-upgrader.php: WP_Upgrader::run() |
Run an upgrade/installation. |
wp-admin/includes/class-wp-screen.php: WP_Screen::set_current_screen() |
Makes the screen object the current screen. |
wp-admin/includes/class-wp-plugins-list-table.php: WP_Plugins_List_Table::single_row() | |
wp-admin/includes/export.php: export_wp() |
Generates the WXR export file for download. |
wp-includes/capabilities.php: grant_super_admin() |
Grants Super Admin privileges. |
wp-includes/capabilities.php: revoke_super_admin() |
Revokes Super Admin privileges. |
wp-admin/includes/ms.php: wpmu_delete_user() |
Delete a user from the network and remove from all sites. |
wp-includes/ms-deprecated.php: update_user_status() |
Update the status of a user in the database. |
wp-admin/includes/class-wp-ms-themes-list-table.php: WP_MS_Themes_List_Table::single_row() | |
wp-admin/includes/schema.php: populate_options() |
Create WordPress options and set the default values. |
wp-admin/includes/class-wp-theme-install-list-table.php: WP_Theme_Install_List_Table::display() |
Displays the theme install table. |
wp-admin/includes/update.php: wp_plugin_update_row() |
Displays update information for a plugin. |
wp-admin/includes/update.php: wp_theme_update_row() |
Displays update information for a theme. |
wp-admin/includes/dashboard.php: wp_dashboard_right_now() |
Dashboard widget that displays some basic stats about the site. |
wp-admin/includes/dashboard.php: wp_network_dashboard_right_now() | |
wp-admin/includes/dashboard.php: wp_dashboard_setup() |
Registers dashboard widgets. |
wp-admin/includes/upgrade.php: wp_upgrade() |
Runs WordPress Upgrade functions. |
wp-admin/includes/upgrade.php: wp_install() |
Installs the site. |
wp-admin/includes/plugin.php: uninstall_plugin() |
Uninstall a single plugin. |
wp-admin/includes/plugin.php: activate_plugin() |
Attempts activation of plugin in a “sandbox” and redirects on success. |
wp-admin/includes/plugin.php: deactivate_plugins() |
Deactivate a single plugin or multiple plugins. |
wp-admin/includes/plugin.php: delete_plugins() |
Remove directory and files of a plugin for a list of plugins. |
wp-admin/includes/user.php: edit_user() |
Edit user settings based on contents of $_POST |
wp-admin/includes/user.php: wp_delete_user() |
Remove user and optionally reassign posts and links to another user. |
wp-admin/includes/class-wp-plugin-install-list-table.php: WP_Plugin_Install_List_Table::display_tablenav() | |
wp-admin/includes/template.php: _wp_admin_html_begin() | |
wp-admin/includes/template.php: iframe_header() |
Generic Iframe header for use with Thickbox |
wp-admin/includes/template.php: iframe_footer() |
Generic Iframe footer for use with Thickbox |
wp-admin/includes/template.php: get_inline_data() |
Adds hidden fields with the data for use in the inline editor for posts and pages. |