What is add_action ('init

Why are we using this type of thing in wordpress.can, can someone please explain to me.? why do we use init in wordpress funtions.or, what is init?

+7
php wordpress themes
source share
2 answers

Add action instead of hard coding features in WordPress. The advantage of using add_action is that you allow the core wordpress functions to keep track of what has been added, and thereby can override previously added functions, canceling them later.

For example:

Download the plugin with a specific action / method named

add_action( 'init', 'crappy_method' ); 

You need to override the crappy function with yours:

 remove_action('init', 'crappy_method' ); add_action( 'init', 'my_even_crappier_method' ); 

In doing so, you can copy the original method and configure it without changing the source files. This is very useful for plugins, so you can update them later without losing your changes.

+15
source share

APPLICATION: add_action ($ hook, $ function_to_add, $ priority, $ accepted_args);

Parameters: $ hook (string) (required) The name of the action to which $ function_to_add is connected. There may also be an action name inside a theme or a plugin file or a special "all" tag, in which case the function will be called for all intercepts) Default: None

INIT HOOK: Runs after WordPress download is complete, but before any headers are sent. Useful for catching $ _GET or $ _POST triggers.

For example, to act on $ _POST data:

 add_action('init', 'process_post'); function process_post(){ if(isset($_POST['unique_hidden_field'])) { // process $_POST data here } } 
+6
source share

All Articles