0

I want to give points to users to their activities like writing posts, writing comments, etc.

I thought to use user meta to store points.

I know that I can use add_user_meta...

But the problem is, there are many ways to register a user for my site like normal reg form, buddypress reg form, Admins can add via admin panel and many more.

So it is hard to add add_user_meta to every where.

Is they any way to add a user meta for all current users and future uses with a default value?

  • I actually don't get the problem. Why having many forms of registration have an impact on how you use an API? – Mark Kaplun Apr 9 '16 at 17:22
  • @Mark Thanks for the comment. I have to call add_user_meta functions in every registration options.. Even I have to call it when users are added via admin panel. Because of I have more than 7 registration options it is little bit hard to add it every where. That is my problem. – Sugantha Apr 9 '16 at 17:40
  • also worth checking out some of the mycred and other points plugin code to see where they hook into for awarding points. – majick Apr 10 '16 at 9:18
3

Trying to detect when a UI was triggered, is indeed the wrong general approach (unless you want to tie to the UI). A proper one will be to hook on the user_register action.

add_action( 'user_register', 'wpse223196_registration_save', 10, 1 );

function wpse223196_registration_save( $user_id ) {

   add_user_meta($user_id, 'score', 5);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.