wp_loaded
This is a WordPress - wp_loaded hook. The plugin just uses it.
Fires after WordPress is fully loaded, when the environment is completely ready to execute code for any request type.
Fires after init.
Fires once, when WordPress, all plugins, and the active theme are fully loaded. This is a late initialization point for code that waits until the environment is ready.
Unlike the init hook, in Multisite it does not fire if the current site is marked as deleted, archived, or spam. In that case, after init, the corresponding file, such as blog-deleted.php, is invoked and PHP execution terminates before this hook is called, so WordPress never finishes loading.
This event is declared in wp-settings.php.
Usage
add_action( 'wp_loaded', 'wp_kama_loaded_action' );
/**
* Function for `wp_loaded` action-hook.
*
* @return void
*/
function wp_kama_loaded_action(){
// action...
}
Examples
#1 Early bootstrap after everything is loaded
Suitable for initializing services and connections that require the plugins and theme to have been loaded.
<?php
// Register the handler as early as possible on this event.
add_action( 'wp_loaded', 'my_project_bootstrap', 0 );
function my_project_bootstrap() {
// Initialize the service locator, containers, and subscriptions to plugin and theme hooks.
// All third-party code is now available and can be safely relied upon.
}Changelog
| Since 3.0.0 | Introduced. |
Where the hook is called
do_action( 'wp_loaded' );