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.
Edit:
I found solution for all the hooks except wp_login, In fact, I am using custom post types so I should change my hook names. in other words, publish_post will become publish_cpt.
What to do with wp_login??
function login_badge($user_login) {
global $current_user;
get_currentuserinfo();
$number_of_badges= get_user_meta($current_user->id,'user_number_of_badges2',true);
$number_of_badges= $number_of_badges +5;
update_user_meta($current_user->id, 'user_number_of_badges2', $number_of_badges);
}
add_action('wp_login', 'login_badge');
thank you for your time.