init WordPress Action Hook

The init hook is one of the most important hooks in WordPress. It is called after the WordPress core has been loaded and initialized. This hook is used to add new functionality to WordPress.

do_action( 'init' ) #

Fires after WordPress has finished loading but before any headers are sent.


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.


Top ↑

More Information

Top ↑

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
     }
}

Top ↑

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.


Top ↑

Source

File: wp-settings.php

View on Trac


Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.