Skip to content

[Basics] Actions

picasso edited this page Jan 13, 2021 · 3 revisions

Plugin/Theme Action Hooks

Plugin/theme can add hooks that the WordPress core launches at specific points during execution, using the Action API. For some events, you can use class methods.

Init

The plugin/theme does not need to add action to the init and admin_init events - you just need to override the methods with such names and perform the necessary initializations in them. Within these methods, you can safely refer to options helpers.

public function init() {
    if($this->is_option('add_category')) {
        register_taxonomy_for_object_type('category', 'attachment');
    }
}

public function admin_init() {
    if(!session_id()) session_start();
}

Enqueue Scripts

It is also possible to override methods for loading scripts that are bound to the wp_enqueue_scripts and admin_enqueue_scripts events - but this is strongly discouraged. To work with scripts, it is better to use the mechanisms that are described in detail in the Scripts & Styles.

Translations

Usually translations are loaded with a hook that is bound to the after_setup_theme event. This is done inside the framework and you can customize work with translations by following the instructions from Translations.

Clone this wiki locally