Action
uncanny-automator-pro
automator_pro_llms_user_enrollment_update
Fires when a user's enrollment status changes for a LifterLMS product.
add_action( 'automator_pro_llms_user_enrollment_update', $callback, 10, 4 );
Description
Fires after a user's LifterLMS enrollment status is updated. Developers can use this hook to perform custom actions, such as sending notifications or updating external systems, based on changes to a user's enrollment for a specific course or membership. The user ID, product ID, post type, and new status are passed as arguments.
Usage
add_action( 'automator_pro_llms_user_enrollment_update', 'your_function_name', 10, 4 );
Parameters
-
$user_id(mixed) - The ID of the user who has been enrolled or unenrolled from a LifterLMS product.
-
$product_id(mixed) - The ID of the WordPress user for whom the enrollment status has been updated.
-
$post_type(mixed) - This parameter contains the ID of the LifterLMS product the user's enrollment is associated with.
-
$status(mixed) - This parameter specifies the post type of the LifterLMS product.
Examples
add_action( 'automator_pro_llms_user_enrollment_update', 'my_custom_llms_enrollment_update_handler', 10, 4 );
/**
* Handles LifterLMS user enrollment updates triggered by Uncanny Automator Pro.
*
* This function can be used to perform custom actions when a user's enrollment
* status changes for a LifterLMS product. For example, you might want to
* send a custom email, update another plugin's data, or log the event.
*
* @param int $user_id The ID of the user whose enrollment was updated.
* @param int $product_id The ID of the LifterLMS product involved.
* @param string $post_type The post type of the LifterLMS product (e.g., 'llms_course', 'llms_membership').
* @param string $status The new enrollment status (e.g., 'enrolled', 'completed', 'expired').
*/
function my_custom_llms_enrollment_update_handler( $user_id, $product_id, $post_type, $status ) {
// Check if the enrollment status is 'completed'.
if ( 'completed' === $status ) {
// Get the user object.
$user = get_user_by( 'id', $user_id );
// Get the product object.
$product = get_post( $product_id );
// Ensure both user and product exist.
if ( ! $user || ! $product ) {
return;
}
// Example: Send a custom notification to the site administrator.
$admin_email = get_option( 'admin_email' );
$subject = sprintf( 'LifterLMS Enrollment Completed: %s for %s', $product->post_title, $user->user_login );
$message = sprintf( 'User "%s" has completed the LifterLMS product "%s".', $user->user_login, $product->post_title );
wp_mail( $admin_email, $subject, $message );
// Example: Log the event for debugging or auditing.
error_log( sprintf( 'LifterLMS enrollment completed for user ID %d (product ID %d).', $user_id, $product_id ) );
} elseif ( 'enrolled' === $status ) {
// Example: Perform an action when a user is newly enrolled.
// For instance, you might grant them access to a specific forum or tag them in your CRM.
error_log( sprintf( 'User ID %d has been enrolled in product ID %d.', $user_id, $product_id ) );
}
}
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/integrations/lifterlms/helpers/lifterlms-pro-helpers.php:207
public function user_product_enrollment_update( $user_id, $product_id, $trigger = null, $new_status = null ) {
$hook = current_filter();
// Validate the hook.
$hooks = $this->enrollment_action_hooks;
if ( ! key_exists( $hook, $hooks ) ) {
return;
}
// Validate the post type of the product ID.
$post_type = get_post_type( $product_id );
if ( ! $post_type || ! key_exists( $post_type, $this->get_product_post_types() ) ) {
return;
}
// Get defined statuses.
$statuses = $this->get_enrollment_statuses();
if ( is_wp_error( $statuses ) ) {
return;
}
$is_removal = strpos( $hook, 'llms_user_removed_from_' ) === 0;
$status = $is_removal ? $new_status : $this->get_user_product_enrollment_status( $user_id, $product_id );
// Validate the status.
if ( empty( $status ) || ! key_exists( $status, $statuses ) ) {
return;
}
// Trigger custom action.
do_action( 'automator_pro_llms_user_enrollment_update', $user_id, $product_id, $post_type, $status );
}
Internal Usage
Found in uncanny-automator-pro/src/integrations/lifterlms/triggers/lf-enrollment-status-changed.php:35:
$this->add_action( 'automator_pro_llms_user_enrollment_update' );