According to codex.wordpress.org:
Actions: Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. Your plugin can specify that one or more of its PHP functions are executed at these points, using the Action API.
You can find more complete explanation about this hooks in http://codex.wordpress.org/Plugin_API and right now I only give simple example to create custom hook that would give us benefit if we want to build wordpress plugin.
1. Initialize Our Hook
You can put this code in any of your plugin files
// initialize hook
2. Adding Action
echo ‘This is my first hook’;
remember : ‘5’ at the end of the add_action is priority. 5 mean lower than 4 to execute and the default value is 10
3. Execute it
Now, we only need to call our function from the first Step in every your php files
This function will produce
This is my first hook
That’s all we’re finish. “Really? how about if I want to append other text to my hook?”. All you need is only create another function and call it via add_action. Here it is how to do this :
echo ‘. Append new text’;
Code above will produce
This is my first hook. Append new text
See the ‘6’? change it to lower number than 5 and your text will appear before the original one. “Cool, But how about if I want to pass argument into this hook?”. Good question, all you need is only change your code a bit. here it is
echo ‘This is my first hook with ‘.$arg;
and call it to your php files
And the code above should produce
This is my first hook with Argument
Not too complicated right?.
“How about if i want to completely remove the original text and change it with the new one?”.
There is also answer about that one. You only need to call remove_action. Here it is how to do this.
1. Remove previous action
2. Create your new brand new function
echo ‘Brand new text’;
That’s it, want to see real action in form of plugin? you can download it here Action Hook in Action | size : 4.75 kB
Thank You, hope this article is usefull for us