Hi Jose,
I haven’t written much documentation for the plugin yet, unfortunately. I do plan to write up some docs soon. If you are fluent in PHP, you can probably figure out what is needed by looking at the source code. Specifically, you will want to take a look at /components/points/includes/hooks.php, which is where the code for the default points hooks is.
Basically, a hook is an extension of the WordPoints_Points_Hook
class. It is registered with WordPoints_Points_Hooks::register()
. This child class displays the settings form on the administration panel, saves the new settings when that form is submitted, hooks into an action or filter to award the points, and generates the description of the transaction for the logs.
So for example, the registration hook hooks into the 'user_register'
action with this line in the class constructor (the constructor is called automatically by the plugin):
add_action( 'user_register', array( $this, 'hook' ) );
The 'user_register'
hook is called by WordPress each time that a new user registers. Then the class’s hook()
function awards the points.
For your custom code, you will likely create a custom action:
do_action( 'my_custom_action' );
And then you will hook into that in your points hook’s constructor:
add_action( 'my_custom_action', array( $this, 'hook' ) );
Right now there is no built-in way to add/get points via AJAX. I plan to add something like that in the near future though. For now, you can create your own custom AJAX callbacks. The function to get the number of points that a user has is wordpoints_get_points( $user_id, $type )
, and the one to add points is wordpoints_alter_points()
. (That function can also subtract points when passed a negative number.)
If you don’t care about having settings for your custom hooks in the admin, you could just call the add points function directly, wherever you need to add points for a user. However, I would encourage you to use the points hook class instead.
I hope that helps. If you have more questions, or need clarification, leave a reply and I’ll be happy to help.
I’m sorry there isn’t any online documentation yet, that is on my to-do list.