I have a dev and prod versions of my D7 site. On dev I developed some functionality based on User Points module and plan to roll out it on prod. But it requires some initial number of user points for every user.

What is the best way to add user points to existing users: SQL query, Rules etc?

  • There's no "best" way, only different ways. Yes you can do it with an SQL query, not sure how you'd do it with rules, or you could probably set something up with VBO. Which one is best for you depends on what you already know and how quickly you pick up new things. Have a go, and if you get stuck, ask a more specific question and you'll surely get a good answer
    – Clive
    Jul 4 '15 at 8:48

One method here is to use the Userpoints API and execute a code snippet that will add the points for you. You can reference the userpoints API here. You can do something like this...

$initial_value = 10;
//@TODO: Build a list of all $uids in an array
foreach($uids as $uid) { =
    'uid' => $uid,
    'points' => $initial_value,
    'operation' => "Add Initial User Point Value",

I think User Points Contributed modules is a possible alternative to consider. I. e. submodule userpoints_retroactive. Excerpt from that project page:

Award users points for their nodes, comments and votes that they have created so far, before userpoints was enabled on the site.

However, the port of this module to D7 still needs work. Maybe you can/want to somehow contriute to the finishing touch of that issue?

Another approach to consider: create a rule with specs like so:

  • Event = a user logging in
  • Condition like "if user points is 0"
  • Action to set the initial number of user points.

Haven't actually created such rule (yet), but pretty sure that's fairly easy to do.

PS: there is also Berdir's Api documentation about this submodule ... (maybe that helps somehow).

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.