MasterStudy LMS Hooks

MasterStudy LMS provides a wide range of hooks (actions and filters) that allow developers to extend or modify the plugin’s behavior without changing the core code. By using hooks, you can add new functionality, customize workflows, or integrate MasterStudy LMS with other plugins and third-party services.

What Are Hooks?

Hooks are points in the code where developers can “hook in” custom functions. There are two types of hooks:

  • Actions – run your custom function at a specific point in the plugin’s execution. Actions do not return values.

  • Filters – modify data before it is used or displayed. Filters must return a value.

How to Use Hooks

Hooks are added with the WordPress core functions:

  • add_action( $hook_name, $callback_function, $priority, $accepted_args )

  • add_filter( $hook_name, $callback_function, $priority, $accepted_args )

Parameters:

  • $hook_name – the name of the hook provided by MasterStudy LMS.

  • $callback_function – your custom function that will run when the hook is triggered.

  • $priority – optional. Defines the order in which functions are executed. Default is 10.

  • $accepted_args – optional. The number of parameters your function accepts.

Example: Adding an Action

add_action( 'stm_lms_assignment_before_drafting', 'my_custom_assignment_action', 10, 1 );

function my_custom_assignment_action( $assignment_id ) {
    // Your custom code here
    error_log( 'Assignment started with ID: ' . $assignment_id );
}

Example: Adding a Filter

add_filter( 'stm_lms_display_points', 'my_custom_points_filter', 10, 1 );

function my_custom_points_filter( $points ) {
    return $points . ' XP'; // Add suffix to points
}

Best Practices

  • Always use unique function names or prefixes to avoid conflicts.

  • Test custom hooks in a staging environment before deploying to production.

  • Keep hook callbacks lightweight to avoid performance issues.

  • Return values properly in filters to prevent breaking functionality.

Next Steps

Explore the addon-specific hook pages to see all available actions and filters you can use:

Last updated

Was this helpful?