In certain cases, it is preferable for no message to be displayed to the user although points have been assigned. Previously, the only way to modify this behavior was by editing USERPOINTS_DISPLAY_MESSAGE. This patch adds a 'mute' parameter which, when true, suppresses that message.

Also, there are minor documentation stylistic improvements.

Usage:

userpoints_userpointsapi(array(
  'points' => 10,
  'mute' => true, // stealth gift!
));
CommentFileSizeAuthor
#3 userpoints-display.patch3.76 KBezyang
userpoints-mute.patch3.64 KBezyang

Comments

jredding’s picture

Can other post if this is a useful addition OR would it be more useful to change this to a display setting.
Example
display => NULL (adhere to administrative settings)
display => false (override administrative settings and suppress output)
display => true (override administrative settings and display out)

If the change was made to do it like this then it would fall more in line with the other settings as if they are null they adhere to administrative settings otherwise its overrides.

ezyang’s picture

jredding: I considered that, and I can easily extend the patch to do that. However, because the default setting is to display the message, I don't know when any application would explicitly set display => true. Advise?

ezyang’s picture

StatusFileSize
new3.76 KB

Updated patch that implements display, allowing true false or null.

jredding’s picture

kbahey: can you chime in? Code looks good and it is a very simple update to the API.

jredding’s picture

Status: Needs review » Reviewed & tested by the community

There are some very, very minor things that I would change but its pretty much RBTC.

kbahey: you've got the final answer, yay or nay?

kbahey’s picture

I think this is a good thing to have.

However, I don't want the name to be "mute". It should be something like "message" (defaults to true) or "silent" (defaults to false).

How do we make this a site wide setting? e.g. someone wants every points operation on their site to be silent? We don't want every caller to specify that, we want a global setting. We can have a module called "userpoints_silent" that does just that. In it, we use the 'points before' operation to "inject" a silent = true when this is set.

Go ahead with this.

kbahey’s picture

Status: Reviewed & tested by the community » Needs work

Changing to CNW so the name can be changed.

jredding’s picture

Title: Add mute option to API » Add display option to API

A few things.

I guess I snuck it in but a while back I coded in a feature request which was to have a global userpoints setting to show/hide the userpoints messages. In the administrative settings an admin can display/hide all point messages.

The call for this, as coded, is "display" not mute like the, now former, title said (title changed).

Thus the code would be..

$params = array(
'points' => 5,
'display' => true
);
userpoints_userpointsapi($params);

If display is NULL the site settings (show/hide) are used. If display is explicitly set then the site settings are overridden. Thus you do not have specify the display property in the call.

jredding’s picture

Status: Needs work » Closed (fixed)

commited