Assignments

The Assignments 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:

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;
    }
}
  1. 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:

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:

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:

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;
}

  1. 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:

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;
}

Last updated

Was this helpful?