akcjaod 1.5.0
init
Opis
Odpala się po załadowaniu większości rdzenia WordPressa, ale zanim nagłówki HTTP zostaną wysłane. Idealne miejsce na rejestrację niestandardowych typów treści, taksonomii i shortcodeów.
Przykład użycia
add_action( 'init', ... )php
add_action( 'init', 'wpdocs_register_book_post_type' );
function wpdocs_register_book_post_type() {
register_post_type( 'book', array(
'labels' => array( 'name' => __( 'Książki', 'wpdocs' ) ),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
) );
}
add_action( 'init', 'wpdocs_register_book_post_type' );
function wpdocs_register_book_post_type() {
register_post_type( 'book', array(
'labels' => array( 'name' => __( 'Książki', 'wpdocs' ) ),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
) );
}Wskazówka — Rejestruj typy treści i taksonomie tutaj — są dostępne we wszystkich kontekstach, łącznie z REST API i WP-CLI.
Most of WP is loaded at this stage, and the user is authenticated. WP continues to load on the {@see '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 {@see 'wp_loaded'} hook below.
Wywołanie
Rejestracja callbackaphp
// rejestracja funkcji zwrotnej
add_action( 'init', 'twoja_funkcja' );
function twoja_funkcja($param_1) {
// Twój kod
}
// rejestracja funkcji zwrotnej
add_action( 'init', 'twoja_funkcja' );
function twoja_funkcja($param_1) {
// Twój kod
}Popularne w tej kategorii