# Point System

## Actions

**Dynamic Hook:** `do_action( "stm_lms_score_charge_{$action_id}", $user_id, $action_id, $action['score'], time() )`

This dynamic action hook is triggered whenever a point-related action occurs. Depending on the action type (`$action_id`), the user can be awarded points.

**Available `$action_id` values:**

* `user_registered`
* `course_purchased`
* `assignment_passed`
* `certificate_received`
* `quiz_passed`
* `perfect_quiz`
* `lesson_passed`
* `group_joined`
* `friends_friendship_accepted`
* `course_bought`

**Parameters:**

* `$user_id` (integer) — The ID of the user receiving points.
* `$action_id` (string) — The action identifier.&#x20;
* `$time` (integer) — The timestamp when the action occurred.

**Example: `stm_lms_score_charge_course_purchased`**

**Description:** \
Triggered when a course is purchased. Allows developers to modify or add to the points awarded for this specific action.

**Example usage:**

```php
add_action( 'stm_lms_score_charge_course_purchased', 'stm_lms_score_charge_course_purchased_function', 10, 4 );

function stm_lms_score_charge_course_purchased( $user_id, $action_id, $score, $time ) {
	global $wpdb;
	$table_name = $wpdb->prefix . 'stm_lms_user_points';

	// Adding custom points
	$score      += 10;
	$user_points = array(
		'user_id'   => $user_id,
		'action_id' => $action_id,
		'score'     => $score,
		'timestamp' => $time,
		'completed' => false,
	);

	$wpdb->insert(
		$table_name,
		$user_points
	);

}
```

## Filters

1. `stm_lms_display_points`

**Description:**\
Filters the way user points are displayed. You can modify the default points output and return a custom format.

**Parameters:**

* `$points` (string) — The current points string.

**Example usage:**

```php
add_filter( 'stm_lms_display_points', 'stm_lms_display_points_function', 10, 1 );

function stm_lms_display_points_function( $points ) {
	$user_id = get_current_user_id();

	if ( $user_id == 1 ) {
		$points = '4.5 Gpa';
	}
	return $points;
}
```

**Explanation:**\
This example overrides the points display for a specific user (ID = 1) and shows **4.5 GPA** instead of the regular score.
