wp_load_classic_theme_block_styles_on_demand()wp-includes/script-loader.php |
Adds hooks to load block styles on demand in classic themes.
|
wp_hoist_late_printed_styles()wp-includes/script-loader.php |
Adds the hooks needed for CSS output to be delayed until after the content of the page has been established.
|
WP_Interactivity_API::data_wp_router_region_processor()wp-includes/interactivity-api/class-wp-interactivity-api.php |
Processes the data-wp-router-region directive.
|
WP_Script_Modules::add_hooks()wp-includes/class-wp-script-modules.php |
Adds the hooks to print the import map, enqueued script modules and script module preloads.
|
WP_Textdomain_Registry::init()wp-includes/class-wp-textdomain-registry.php |
Initializes the registry.
|
wp_initialize_theme_preview_hooks()wp-includes/theme-previews.php |
Add filters and actions to enable Block Theme Previews in the Site Editor.
|
WP_Rewrite::refresh_rewrite_rules()wp-includes/class-wp-rewrite.php |
Refreshes the rewrite rules, saving the fresh value to the database.
|
wp_delete_all_temp_backups()wp-includes/update.php |
Schedules the removal of all contents in the temporary backup directory.
|
_wp_get_iframed_editor_assets()wp-includes/block-editor.php |
Collect the block editor assets that need to be loaded into the editor’s iframe.
|
wp_enqueue_block_support_styles()wp-includes/script-loader.php |
Hooks inline styles in the proper place, depending on the active theme.
|
_wp_theme_json_webfonts_handler()wp-includes/deprecated.php |
Runs the theme.json webfonts handler.
|
_add_template_loader_filters()wp-includes/block-template.php |
Adds necessary hooks to resolve ‘_wp-find-template’ requests.
|
wp_enqueue_block_style()wp-includes/script-loader.php |
Enqueues a stylesheet for a specific block.
|
locate_block_template()wp-includes/block-template.php |
Finds a block template with equal or higher specificity than a given PHP template file.
|
WP_Sitemaps::init()wp-includes/sitemaps/class-wp-sitemaps.php |
Initiates all sitemap functionality.
|
WP_Recovery_Mode::initialize()wp-includes/class-wp-recovery-mode.php |
Initialize recovery mode for the current request.
|
WP_Site_Health::__construct()wp-admin/includes/class-wp-site-health.php |
WP_Site_Health constructor.
|
wp_is_site_initialized()wp-includes/ms-site.php |
Checks whether a site is initialized.
|
register_and_do_post_meta_boxes()wp-admin/includes/meta-boxes.php |
Registers the default post meta boxes, and runs the do_meta_boxes actions.
|
WP_Privacy_Policy_Content::text_change_check()wp-admin/includes/class-wp-privacy-policy-content.php |
Performs a quick check to determine whether any privacy info has changed.
|
WP_Roles::get_roles_data()wp-includes/class-wp-roles.php |
Gets the available roles data.
|
WP_Widget_Text::_register_one()wp-includes/widgets/class-wp-widget-text.php |
Adds hooks for enqueueing assets when registering all widget instances of this widget class.
|
WP_Widget_Custom_HTML::_register_one()wp-includes/widgets/class-wp-widget-custom-html.php |
Add hooks for enqueueing assets when registering all widget instances of this widget class.
|
WP_Widget_Media::_register_one()wp-includes/widgets/class-wp-widget-media.php |
Add hooks while registering all widget instances of this widget class.
|
_WP_Editors::enqueue_default_editor()wp-includes/class-wp-editor.php |
Enqueue all editor scripts.
|
_wp_delete_customize_changeset_dependent_auto_drafts()wp-includes/nav-menu.php |
Deletes auto-draft posts associated with the supplied changeset.
|
WP_Customize_Manager::import_theme_starter_content()wp-includes/class-wp-customize-manager.php |
Imports theme starter content into the customized state.
|
WP_Post_Type::register_meta_boxes()wp-includes/class-wp-post-type.php |
Registers the post type meta box if a custom callback was specified.
|
WP_Post_Type::add_hooks()wp-includes/class-wp-post-type.php |
Adds the future post hook action for the post type.
|
WP_Customize_Widgets::selective_refresh_init()wp-includes/class-wp-customize-widgets.php |
Adds hooks for selective refresh.
|
WP_Customize_Selective_Refresh::init_preview()wp-includes/customize/class-wp-customize-selective-refresh.php |
Initializes the Customizer preview.
|
WP_Customize_Selective_Refresh::enqueue_preview_scripts()wp-includes/customize/class-wp-customize-selective-refresh.php |
Enqueues preview scripts.
|
WP_Customize_Selective_Refresh::__construct()wp-includes/customize/class-wp-customize-selective-refresh.php |
Plugin bootstrap for Partial Refresh functionality.
|
rest_api_default_filters()wp-includes/rest-api.php |
Registers the default REST API filters.
|
WP_Customize_Setting::aggregate_multidimensional()wp-includes/class-wp-customize-setting.php |
Set up the setting for aggregated multidimensional values.
|
wp_admin_bar_customize_menu()wp-includes/admin-bar.php |
Adds the “Customize” link to the Toolbar.
|
WP_Widget_Factory::__construct()wp-includes/class-wp-widget-factory.php |
PHP5 constructor.
|
WP_Customize_Site_Icon_Control::__construct()wp-includes/customize/class-wp-customize-site-icon-control.php |
Constructor.
|
WP_Customize_Nav_Menu_Item_Setting::__construct()wp-includes/customize/class-wp-customize-nav-menu-item-setting.php |
Constructor.
|
WP_Customize_Nav_Menus::customize_preview_init()wp-includes/class-wp-customize-nav-menus.php |
Adds hooks for the Customizer preview.
|
WP_Customize_Nav_Menus::__construct()wp-includes/class-wp-customize-nav-menus.php |
Constructor.
|
WP_Site_Icon::__construct()wp-admin/includes/class-wp-site-icon.php |
Registers actions and filters.
|
print_emoji_detection_script()wp-includes/formatting.php |
Prints the inline Emoji detection script if it is not already printed.
|
login_header()wp-login.php |
Outputs the login page header.
|
Language_Pack_Upgrader::bulk_upgrade()wp-admin/includes/class-language-pack-upgrader.php |
Upgrades several language packs at once.
|
Theme_Upgrader::install()wp-admin/includes/class-theme-upgrader.php |
Install a theme package.
|
Theme_Upgrader::upgrade()wp-admin/includes/class-theme-upgrader.php |
Upgrades a theme.
|
Plugin_Upgrader::install()wp-admin/includes/class-plugin-upgrader.php |
Install a plugin package.
|
Plugin_Upgrader::upgrade()wp-admin/includes/class-plugin-upgrader.php |
Upgrades a plugin.
|
WP_Upgrader::run()wp-admin/includes/class-wp-upgrader.php |
Runs an upgrade/installation.
|
WP_List_Table::__construct()wp-admin/includes/class-wp-list-table.php |
Constructor.
|
WP_Theme_Install_List_Table::prepare_items()wp-admin/includes/class-wp-theme-install-list-table.php |
|
wp_plugin_update_rows()wp-admin/includes/update.php |
Adds a callback to display update information for plugins with updates available.
|
wp_theme_update_rows()wp-admin/includes/update.php |
Adds a callback to display update information for themes with updates available.
|
uninstall_plugin()wp-admin/includes/plugin.php |
Uninstalls a single plugin.
|
add_menu_page()wp-admin/includes/plugin.php |
Adds a top-level menu page.
|
add_submenu_page()wp-admin/includes/plugin.php |
Adds a submenu page.
|
WP_Plugin_Install_List_Table::prepare_items()wp-admin/includes/class-wp-plugin-install-list-table.php |
|
WP_Internal_Pointers::enqueue_scripts()wp-admin/includes/class-wp-internal-pointers.php |
Initializes the new feature pointers.
|
Custom_Image_Header::__construct()wp-admin/includes/class-custom-image-header.php |
Constructor – Registers administration header callback.
|
Custom_Image_Header::init()wp-admin/includes/class-custom-image-header.php |
Sets up the hooks for the Custom Header admin page.
|
Custom_Background::__construct()wp-admin/includes/class-custom-background.php |
Constructor – Registers administration header callback.
|
Custom_Background::init()wp-admin/includes/class-custom-background.php |
Sets up the hooks for the Custom Background admin page.
|
WP_Customize_Manager::customize_preview_init()wp-includes/class-wp-customize-manager.php |
Prints JavaScript settings.
|
WP_Customize_Manager::setup_theme()wp-includes/class-wp-customize-manager.php |
Starts preview and customize theme.
|
WP_Customize_Manager::__construct()wp-includes/class-wp-customize-manager.php |
Constructor.
|
wp_cron()wp-includes/cron.php |
Registers _wp_cron() to run on the ‘shutdown’ action.
|
_custom_header_background_just_in_time()wp-includes/theme.php |
Registers the internal custom header and background routines.
|
add_thickbox()wp-includes/general-template.php |
Enqueues the default ThickBox js and css.
|
wp_auth_check_load()wp-includes/functions.php |
Loads the auth check for monitoring whether the user is still logged in.
|
wp_maybe_load_widgets()wp-includes/functions.php |
Determines if Widgets library should be loaded.
|
WP_Widget_Recent_Comments::__construct()wp-includes/widgets/class-wp-widget-recent-comments.php |
Sets up a new Recent Comments widget instance.
|
WP_Embed::__construct()wp-includes/class-wp-embed.php |
Constructor
|
WP_Admin_Bar::add_menus()wp-includes/class-wp-admin-bar.php |
Adds menus to the admin bar.
|
WP_Admin_Bar::initialize()wp-includes/class-wp-admin-bar.php |
Initializes the admin bar.
|
register_activation_hook()wp-includes/plugin.php |
Set the activation hook for a plugin.
|
register_deactivation_hook()wp-includes/plugin.php |
Sets the deactivation hook for a plugin.
|
WP_Customize_Setting::preview()wp-includes/class-wp-customize-setting.php |
Add filters to supply the setting’s value when accessed.
|
wp_enqueue_media()wp-includes/media.php |
Enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs.
|
wp_playlist_scripts()wp-includes/media.php |
Outputs and enqueues default scripts and styles for playlists.
|
WP_Rewrite::flush_rules()wp-includes/class-wp-rewrite.php |
Removes rewrite rules and then recreate rewrite rules.
|
add_feed()wp-includes/rewrite.php |
Adds a new feed type like /atom1/.
|
WP_Scripts::__construct()wp-includes/class-wp-scripts.php |
Constructor.
|
WP_Customize_Header_Image_Control::prepare_control()wp-includes/customize/class-wp-customize-header-image-control.php |
|
WP_Customize_Widgets::customize_preview_init()wp-includes/class-wp-customize-widgets.php |
Adds hooks for the Customizer preview.
|
WP_Customize_Widgets::__construct()wp-includes/class-wp-customize-widgets.php |
Initial loader.
|
WP_Customize_Widgets::schedule_customize_register()wp-includes/class-wp-customize-widgets.php |
Ensures widgets are available for all types of previews.
|
wp_set_comment_status()wp-includes/comment.php |
Sets the status of a comment.
|
_WP_Editors::editor_settings()wp-includes/class-wp-editor.php |
|
wp_print_media_templates()wp-includes/media-template.php |
Prints the templates used in the media manager.
|
Skip to note 11 content
Codex
Using with a Class
To use
add_action()when your plugin or theme is built using classes, you need to use the array callable syntax. You would pass the function toadd_action()as an array, with$thisas the first element, then the name of the class method, like so:/** * Class WP_Docs_Class. */ class WP_Docs_Class { /** * Constructor */ public function __construct() { add_action( 'save_post', array( $this, 'wpdocs_save_posts' ) ); } /** * Handle saving post data. */ public function wpdocs_save_posts() { // do stuff here... } } $wpdocsclass = new WP_Docs_Class();Skip to note 12 content
Codex
Using with static functions in a class
If the class is called staticly the approach has to be like below as
$thisis not available. This also works if class is extended. Use the following:/** * Class WP_Docs_Static_Class. */ class WP_Docs_Static_Class { /** * Initializer for setting up action handler */ public static function init() { add_action( 'save_post', array( get_called_class(), 'wpdocs_save_posts' ) ); } /** * Handler for saving post data. */ public static function wpdocs_save_posts() { // do stuff here... } } WP_Docs_Static_Class::init();add_action( 'save_post', array( Classname::class, 'wpdocs_save_posts' ) );Skip to note 13 content
mkormendy
To pass a variable to the called function of the action, you can use closures (since PHP 5.3+) when the argument is not available in the original coded do_action. For example:
add_action('wp_footer', function($arguments) use ($myvar) { echo $myvar; }, $priority_integer, $accepted_arguments_integer);$myvar = 'Hello World'; $action_wp_footer = function($arguments) use ($myvar) { echo $myvar; }; add_action('wp_footer', $action_wp_footer, 100, 1);which can be removed with:remove_action('wp_footer', $action_wp_footer, 100);with the advantage that typos in the closure name will yeild a helpfull Undfined variable error on typos.Skip to note 14 content
Codex
Simple Hook
To email some friends whenever an entry is posted on your blog:
/** * Send email to my friends. * * @param int $post_id Post ID. * @return int Post ID. */ function wpdocs_email_friends( $post_id ) { $friends = 'bob@example.org, <a href="mailto:susie@example.org">susie@example.org</a>'; wp_mail( $friends, "sally's blog updated", 'I just put something on my blog: <a href="http://blog.example.com" rel="nofollow ugc">http://blog.example.com</a>' ); return $post_id; } add_action( 'publish_post', 'wpdocs_email_friends' );Skip to note 15 content
Anthony Hortin
Related:
do_action()
remove_action()
Skip to note 16 content
Bartek
I urge you, don’t attach your hook callbacks inside class’ constructor.
Instead of implementing official example most upvoted in this thread, opt for decoupled solution. You have one more line of code to write, but objects become more reusable and less error-prone (consider, what would happen if you call
new WP_Docs_Class()twice in your code, following Codex example)./** * Class WP_Docs_Class. */ class WP_Docs_Class { /** * Initiate all hooks' callbacks in a separate method. */ public function hooks() { add_action( 'save_post', array( $this, 'wpdocs_save_posts' ) ); } /** * Handle saving post data. */ public function wpdocs_save_posts() { // do stuff here... } } $wpdocsclass = new WP_Docs_Class(); $wpdocsclass->hooks();Skip to note 17 content
lucasbustamante
Passing parameters while using in a Class
To pass parameters to your method in a Class while calling it with add_action, you can do as following:
public function __construct() { // Actions add_action('init', array($this, 'call_somefunction')); } /** * Intermediate function to call add_action with parameters */ public function call_somefunction() { $this->somefunction('Hello World'); } /** * Actual function that does something */ public function somefunction($text) { echo $text; }Skip to note 18 content
Christian Saborio
How to add an action that calls a function (with parameters) from an instantiated class:
$admin_menu_hider = new AdminMenuHider( UserManagement::get_internal_users() ); add_action( 'wp_before_admin_bar_render', function () use ( $admin_menu_hider ) { $admin_menu_hider->change_greeting_message( 'Hello' ); } );Skip to note 19 content
Codex
Accepted Arguments
A hooked function can optionally accept arguments from the action call, if any are set to be passed. In this simplistic example, the
echo_comment_idfunction takes the$comment_idargument, which is automatically passed to when thedo_action()call using thecomment_id_not_foundfilter hook is run./** * Warn about comment not found * * @param int $comment_id Comment ID. */ function echo_comment_id( $comment_id ) { printf( 'Comment ID %s could not be found', esc_html( $comment_id ) ); } add_action( 'comment_id_not_found', 'echo_comment_id', 10, 1 );Skip to note 20 content
theking2
To prevent runtime errors due to easy typo errors (defensive programming) and prevent pollution of the global namespace use closures instead of function names. The sample code adjusted:
/** * add a save post hook */ add_action( 'save_post', function( $post_ID, $post, $update ) { // do stuff here }, 10, 3 );