> For the complete documentation index, see [llms.txt](https://docs.stylemixthemes.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stylemixthemes.com/masterstudy-lms/developers-guide/masterstudy-lms-hooks/assignments.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
