do_action( 'init' )
Fires after WordPress has finished loading but before any headers are sent.
Contents
Description
Most of WP is loaded at this stage, and the user is authenticated. WP continues to load on the ‘init’ hook that follows (e.g. widgets), and many plugins instantiate themselves on it for all sorts of reasons (e.g. they need a user, a taxonomy, etc.).
If you wish to plug an action once WP is loaded, use the ‘wp_loaded’ hook below.
More Information
Examples:
Use init
to act on $_POST
data:
add_action( 'init', 'process_post' );
function process_post() {
if( isset( $_POST['unique_hidden_field'] ) ) {
// process $_POST data here
}
}
Notes:
init is useful for intercepting $_GET
or $_POST
triggers.
load_plugin_textdomain
calls should be made during init
, otherwise users cannot hook into it.
If you wish to plug an action once WP is loaded, use the wp_loaded
hook.
Source
File: wp-settings.php
.
View all references
do_action( 'init' );
Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
This hook works almost like the
admin_init
hook. The difference is theadmin_init
fires on the initialization of admin screen or scripts and thisinit
hook fires on the initialization time of the whole WordPress script. Like-Now the above code will echo “Fired on the WordPress initialization” on initialization of WordPress.
Top ↑
Feedback
if ‘init’ hook is launched more than once by page in order to avoid to run same code twice you can add a check inside your ‘init’ action hook like that:
/* avoid running code twice */ if ( did_action( 'init' ) > 1 ) return false;
— By capbussat —