I am creating a referral program on Drupal. I have almost everything working right except awarding userpoints to users. I want to award userpoints to users after the person they refer to the site becomes a paid member. I have tried severally with Rules but no success.

I am using these modules:

What I want is to create a rule using Rules that automatically awards userpoints to a user once the person that a user refers to the site becomes a paid member of the site.

Anyone with better knowledge able to help me out here?


3 Answers 3


Add a field to user registration form that collects the uid of the referring user. Then ask current users to invite other people to the site using a custom URL to user registration form and this URL should include as query parameter the uid of the referring user. Hook the user registration form and fill in the uid of the referrer based on the query parameter. You should hide the referrer field completely. Then you do counts in the database for how many paid users a given uid had invited. The referrer uid in regard to each user is kept in the custom user profile field and becomes meaningful in your situation if the user becomes a paid member.

  • How would the actual userpoints get awarded? Apr 7, 2016 at 10:31
  • You would hook user_presave function or any other function that manages the move from normal account to paid account. In that function you would pass the uid of the original referrer (of this new paid account user) to a function / system that should update the referrer's profile (say a custom integer field) and add to it award point.
    – W.M.
    Apr 7, 2016 at 10:35

Part 1 - Clarification

Here is part of what you wrote in your own comment (below the question now):

Event: after user becomes a member

Condition: user was referred by another user

Action: award points to user ( this is where I have issue....I can't find the 'referring-user' from data selector)

Refer to the feature request (not bug ...) "Rules Action: Fetch Referring User", which states the following:

Referral's Rules integration doesn't have a way to do that natively - the 'referring_user' variable only exists when the new account is being created. It would be very nice to have a Rules action that could fetch the referring user.

This issue, in status "needs review", does have a patch via which you may get it to work.

Part 2 - As-good-as-it-gets alternative

Here is the rule (in Rules export format) that you can use as a prototype, to partially answer your question:

{ "rules_award_userpoints_to_referring_users" : {
    "LABEL" : "Award userpoints to referring users",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "userpoints_rules", "referral" ],
    "ON" : { "referral_recorded" : [] },
    "DO" : [
      { "userpoints_action_grant_points" : {
          "user" : [ "referring-user" ],
          "points" : "50",
          "tid" : "0",
          "entity" : [ "new-user" ],
          "description" : "You earned some points because user [referring-user:name] just registered using referral link [referring-user:referral-link].",
          "operation" : "New referral occured",
          "display" : "1",
          "moderate" : "default"

I've selected an (arbitrary) amount of 50 points. If you tune that to fit your own requirement, then these points will be rewarded (already) when that new account is created (with no relationship/dependency about becoming a member).

Be aware that the Rules / User Points integration has way more facilities you can take advantage of (that's why I consider this sample rule as a prototype only).

You should be able to use the Rules UI to perform an import of the above (exported) rule, provided you first enabled these modules (as indicated also within the REQUIRES section of the exported rule above):

  • Rules, and the Rules UI sub-module, to further tune this rule if needed.
  • User Points, and its sub-module "Userpoints rules integration".
  • User Referral ... of course ...

Part 3 - Heading for the golden cradle

If you'd add an entity reference field to your user accounts (for entity type = user), you could replace the Rules Action from Part 2 by adding a reference to the "Referring user" (and not yet grant those user points).

Next you could create an additional rule based on an event like "After saving a new membership" (which you get from the Membership Entity module). And possibly you may want to add a Rules Condition to that rule to perform a Data Comparison about the membership-entity:type, to check if it matches the membership type for which you want to grant the user points.

Finally you could use a Rules Action to grant the user points, similar to the Rules action as in part 2. But with the referring-user (within the Rules Action from Part 2) replaced by the user indicated via the user reference indicated in the user profile.

If you're not familiar (enough/yet) with Rules, then checkout the 32 (!!!) great, and free, video tutorials Learn the Rules framework.


As per your question you have managed everything except assigning points to user. Then I suggest you to have a rule with execute custom php code. The code for assigning points to user is as follow. (Do your necessary changes accordingly.)

$params = array(
    'uid' => $user->uid,
    'moderate' => 0,
    'points' => 15,
    'tid' => 0,
    'entity_id' => $user->uid,
    'entity_type' => 'user',
    'operation' => 'Vote Added',


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