Skip to content

Instantly share code, notes, and snippets.

@actual-saurabh
Created September 24, 2019 17:50
Show Gist options
  • Save actual-saurabh/b25b0f62abbb4af846d48b68c4ad91fb to your computer and use it in GitHub Desktop.
Save actual-saurabh/b25b0f62abbb4af846d48b68c4ad91fb to your computer and use it in GitHub Desktop.
Award a Certificate associated with a trigger and an engagement to a user
<?php
/**
* Award a certificate engagement attached to a unit (course, quiz, etc) to a user
* @param int $user_id The ID of the user to award the certificate to.
* @param int $engagement_id The post ID of the engagement
* @param int $trigger_id The post ID of the trigger post (course, lesson, quiz, etc)
*/
function llms_award_certificate( $user_id, $engagement_id, $trigger_id ){
// See: https://github.com/gocodebox/lifterlms/blob/master/includes/class.llms.engagements.php#L100
// https://github.com/gocodebox/lifterlms/blob/master/includes/class.llms.engagements.php#L379
// https://github.com/gocodebox/lifterlms/blob/master/includes/class.llms.engagements.php#L158
$certificates = LLMS()->certificates();
// See: https://github.com/gocodebox/lifterlms/blob/master/includes/class.llms.certificates.php#L71-L85
// https://github.com/gocodebox/lifterlms/blob/master/includes/class.llms.certificate.php#L186-L238
$certificates->trigger_engagement( $user_id, $engagement_id, $trigger_id );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment