by Bhumi // Dec 17,2012 // 4 comments
WordPress provide functionality of action hook with which you can create your own action hook too.you can create new action hooks by calling do_action() function and just need to specify the name of the new hook as $tag parameter.Whereas add_action() is used to hooks a function on to a specific action.
|
1 2 |
do_action( $tag, $arg ); |
$tag is the name of the action to be executed.
$arg is an optional arguments which are passed on to the functions hooked to the action.
|
1 2 |
add_action( $tag, $function_to_add, $priority, $accepted_args ); |
Here is add_action,same like do_action $tag is the name of the action to be executed.Next argument is the name of the function to add for an action.Third argument defines the priority of code and fourth argument is for number of argument in the function.
Here in an example, going to show how to create an action hook that customize the login functionality just before the user logged into dashboard.
First of,place below code into the wp-login.php file after post request for a form.
|
1 2 |
do_action('login_qry',$user); |
Next is use the function, which we can put in the functions.php of the theme to add an action for the login
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function login_qry_fn($user){ global $wpdb; $userid =$user->ID; $result = $wpdb->get_var("Your_qry"); if(empty($result)){ wp_redirect( site_url('wp-login.php') ); exit; }else{ return true; } } add_action('login_qry','login_qry_fn',10, 1); |
Thanks for reading and feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.
The Best E-Commerce Plugins for WordPress
Here is the new guest post by katie,here you will get idea about thw best E-Comerce plugins for WordPress. WordPress templates can make it fast READ MORE
To Delete Taxonomies from database in wordpess
Basically, Latest version of wordpress have by default 2 categories. Tags and categories. Few days back,my friend asked me ,how can i delete terms from READ MORE
Remove suffix from taxonomies in WordPress
Right, I’m back after break as I was busy in stack overflow.Today I’m a going to go over how to replace some text or suffix READ MORE
Tips to Choose Your Next WordPress Theme
In this guest post by Anny,you will get tips to Help Choose Your Next WordPress Theme WordPress templates can make it fast and simple to READ MORE
In this article, I will explain you about the fundamentals of the WordPress Cron Job.Cron is basically a task scheduler that periodically on a given READ MORE
Be a Contributor at CreativeDev.Write an article or tutorial to the community and share some of your knowledge!
Article writing is also a excitement, if you be
acquainted with after that you can write otherwise it is
complex to write.
Hi!
Thanks for the desciption for 4 columns.
In Step 3. Which one file do i need to add that code?
footer.php or function.php or sidebar.php?
Thanks
Roland
It is visible that wrote is acquainted with these issues and knows how to present it in a way easily understood for a greenhorn.
I admit that I”m very interested in this entry despite the fact that I”m not much interested in this subject-matter.
An fascinating dialogue is price comment. I feel that you need to write extra on this topic, it might not be a taboo subject but generally people are not enough to talk on such topics. To the next. Cheers