My question is pretty straightforward: how can I check whether a user's current amount of User Points is negative with the Rules module? I'd like to create an action that should be activated when the user is granted User Points. The event is set, but I don't know how I can set the condition.

Edit: I enabled the PHP filter module in order to get the 'Execute custom PHP code' option in my Rule's conditions. (I didn't know that I had to do this before...) I used this code to check whether the user's User Points are negative:

global $user;
$num_pts = userpoints_get_current_points($user->uid, 'all');
$neg_pts = $num_pts < 0;

Unfortunately, it's always evaluated as 'false', even when the amount of User Points is negative. I've also tried this:

$num_pts = userpoints_get_current_points([userpoints-transaction:user]->uid, 'all');
$neg_pts = $num_pts < 0;

But that didn't work either (same reason). I don't get any error messages in both cases.

Are these code snippets wrong? How does the correct one look like?

有帮助吗?

解决方案

I found the correct code:

global $user;
$num_pts = userpoints_get_current_points($user->uid, 'all');
if ($num_pts < 0) {return TRUE;}

Just use this snippet in an Execute custom PHP code condition. It's as simple as that!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top