Sunday, 2 June 2013

action hooks not working

action hooks not working

I have spent many time looking for a solution to my issue, but in vain. Your help is invaluable.
I am creating a simplified badge system. The goal is to increment the number of badges for a user if he performs some things on the website. For example, for each post published, I give a user one badge.
To do so, I opted for user meta data, and the use of publish_post action hook.
in my functions.php, I put:
function publish_badge($post_ID) {

global $current_user;
get_currentuserinfo();

$number_of_badges= get_user_meta($current_user->id,'user_number_of_badges',true);

$number_of_badges= $number_of_badges + 1;

update_user_meta($current_user->id, 'user_number_of_badges', $number_of_badges);

return $post_ID;               
}

add_action('publish_post', 'publish_badge');
I am new in using Wordpress action hooks, and I spent a lot of time making it work. I know I am missing something, since for other hooks, the problem remains.
Note I have in total 4 actions for which I want to give users more badges: publish_post,edit_post,wp_login,comment_post.
Your usual help is always appreciated.

No comments:

Post a Comment