# Assignments

The [**Assignments**](/masterstudy-lms/lms-pro-addons/assignments.md) addon exposes actions and filters that let you plug custom logic into key moments of the assignment lifecycle. Use these hooks to send notifications, change pagination, or integrate with external systems.

## Actions

1. `stm_lms_assignment_before_drafting`

**Type:** action

**When it runs:** right before a learner starts an assignment for the first time

**Parameters:**

* `$assignment_id` (int)

**Example:**

```php
add_action( 'stm_lms_assignment_before_drafting', 'mslms_assignment_before_drafting', 10, 1 );

function mslms_assignment_before_drafting( $assignment_id ) {
    $response = wp_remote_post(
        'https://demo-website.com/',
        array( 'body' => 'Assignment with ID ' . $assignment_id . ' has been started.' )
    );

    if ( is_wp_error( $response ) ) {
        error_log( 'Request error while sending assignment start notice for ID ' . $assignment_id );
        return;
    }
}
```

2. `stm_lms_assignment_`*`{status}`*

**Type:** action\
**Concrete hooks:** stm\_lms\_assignment\_*passed*, stm\_lms\_assignment\_*not\_passed*

**When it runs:** whenever an assignment status changes

**Signature used by MasterStudy:**

```php
do_action( 'stm_lms_assignment_' . $status, $student_id, $assignment_id );
```

**Statuses:**

* passed
* not\_passed

**Parameters:**

* `$status` (string)
* `$student_id` (int)
* `$assignment_id` (int)

**Important note:** the dynamic action passes two arguments. Set accepted args to 2 in `add_action`. Do not expect a status argument in the callback for the concrete hooks.

**Example notify on not passed:**

```php
add_action( 'stm_lms_assignment_not_passed', 'stm_lms_assignment_not_passed_function', 10, 3 );

function stm_lms_assignment_not_passed_function( $status, $student_id, $assignment_id ) {
	$admin_email   = get_option( 'admin_email' );
	$student       = STM_LMS_User::get_current_user( $student_id );
	$student_email = $student['email'];

	$subject = 'Alert: Failed Assignment - ' . $assignment_id;
	$message = "Dear Admin,\n\n$student_email has not passed the assignment: $assignment_id .\n\nPlease take necessary action.";

	wp_mail( $admin_email, $subject, $message );
}
```

## Filters

1. `stm_lms_single_assignment_per_page`

**Type:** filter

**What it does:** controls how many assignment items appear per page for learners

**Parameters:**

* `$per_page` (int)

**Return:** int updated per page count

**Example:**

```php
add_filter( 'stm_lms_single_assignment_per_page', 'stm_lms_single_assignment_per_page_function', 10, 1 );

function stm_lms_single_assignment_per_page_function( $per_page ) {
	$user_id = get_current_user_id();
	if ( $user_id == 1 ) {
		$per_page = 25;
	}
	return $per_page;
}
```

***

2. `stm_lms_instructor_assignments`

**Type:** filter

**What it does:** controls how many submissions appear on the instructor assignment review screen

**Parameters:**

* `$per_page` (int)

**Return:** int updated per page count

**Example:**

```php
add_filter( 'stm_lms_instructor_assignments', 'stm_lms_instructor_assignments_function', 10, 1 );
function stm_lms_instructor_assignments_function( $per_page ) {
	if ( $per_page == 9 ) {
		return 10;
	}
	return $per_page;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stylemixthemes.com/masterstudy-lms/developers-guide/masterstudy-lms-hooks/assignments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
