The creation of a plugin (creation of a new rule for a third component) is divided into 2 phases.
Step 1 - Inserting API in your component
This course is aimed primarily at developers or any person with a level of knowledge sufficiently advanced in PHP.
Simply insert the following API in the code component to where you want. The ideal is to follow an action that can bring items to the connected user. For example, in a component of any comments or forum, simply add the API after insertion source code of the commentary or new topic in the database.
API:
use BlackSheepResearch\Component\UserPoints\Site\UserPoints;
UserPoints::newpoints( 'rule_name' );
}
rule_name is the rule which will be used to award points to the current user (if registered and logged).
For all the rules included in UserPoints (systems), the function names are written as follows:
example: sysplgup_newregistered for awarding points to a new registered user.
When adding new integrations, choose names that are unlikely to conflict, such as:
up_componentname_function_name
Example up_new_comment or up_kunena_topic_reply to resume the example of the inclusion of this component API in a comment or Kunena forum.
The name of a function to award points when creating a new topic posted in the component Kunena could be, for example, up_kunena_topic_create.
Step 2 - Add the new rule(s) in the rules manager
With UserPoints version 4.0 and later for Joomla 4.x, all developers of third extensions for Joomla! can add directly at the root of their frontend components or plugins an unique xml file containing all the rules for a single component. The file structure is almost similar but you have to respect the ordering and tags:
<userpoints>
<component>com_remository</component>
<rules>
<rule>
<name>Remository Upload</name>
<description>Give points when a new file is uploaded</description>
<plugin_function>up_up_remository</plugin_function>
<fixed_points>true</fixed_points>
<category>ot</category>
<display_message>1</display_message>
<email_notification>1</email_notification>
</rule>
<rule>
<name>Remository Download</name>
<description>Take points when a file is downloaded</description>
<plugin_function>up_down_remository</plugin_function>
<fixed_points>true</fixed_points>
<category>ot</category>
<display_message>1</display_message>
<email_notification>1</email_notification>
</rule>
</rules>
</userpoints>
Tag 'component' is the name of the third component like 'com_kunena' or other. As it is the same component, it is worth repeating for each rule in the tag 'rule'
Administrator of the website which install a third component with this xml file can auto-detect directly from the button 'auto-detect plugins' in control panel of UserPoints.
This xml file has to be utf-8 encoded (required) but not be zipped! Just put this file at the root of frontend component folder or plugin or module and include this file in your installer extension . This file must be named exactly as follows: userpoints_rule.xml
Note to developers
You can find the complete documentation to insert and use this API in your components or plugin here.