Here is an example module that demonstrates how to use the new Userpoints API, currently available in 4.7.x-2.x.
This is a simple module that shows how a module can act on points gained/lost.
The site admin define a threshold of points, if it is reached, then the user will get a custom email message. The message can be customized, for example, they can get a free gift or something like that.
This module demonstrates the following:
- Adding configuration options to the settings of userpoints.
- Acting on points being awarded (in this case, check points, and send an email).
To actually award points in a module, you need to call the function:
userpoints_userpointsapi('points', $number_of_points, $uid, $event);
The userpoints_basic.module (part of the standard userpoints 2.0 package) demonstrates how to award points, as well as provides points for the most common actions (posting a node, posting a comment, ...etc.)
If your module provides a hook, i.e. uses module_invoke_all('modulename', ...) then you can award the points in that hook too.
Attachment | Size |
---|---|
userpoints_email.module.txt | 3.06 KB |
Comments
Visitor (not verified)
message customization
Wed, 2007/03/14 - 05:00How the message can be customized?
Khalid
Feature request
Wed, 2007/03/14 - 09:06Please create a feature request for the userpoints project on drupal.org to add a theme function. This will allow the message to be customized.
--
2bits -- Drupal and Backdrop CMS consulting