Title: Give certificate programmatically
Last modified: August 31, 2016

---

# Give certificate programmatically

 *  Resolved [adamkowalski](https://wordpress.org/support/users/adamkowalski/)
 * (@adamkowalski)
 * [10 years ago](https://wordpress.org/support/topic/give-certificate-programmatically/)
 * When trying to give a student a certificate using Engagements you need to specify
   the engagement type to be Give Certificate, and then you must select an Event
   Trigger. You have the following options:
    - Lesson Completed
    - Section Completed
    - Course Completed
    - New User Registration
    - Days since user last logged in
    - Course Track Completed
 * What if none of these fit your use case? How can I bypass this? Ideally I would
   be able to trigger the giving of a certificate from within my code base after
   my own custom criteria have been met.
 * I have tried to look through the source, but I am not seeing a way where given
   a user id and the post id of the certificate I can give that user that certificate.
 * Any help would be greatly appreciated!
 * [https://wordpress.org/plugins/lifterlms/](https://wordpress.org/plugins/lifterlms/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [Thomas Patrick Levy](https://wordpress.org/support/users/thomasplevy/)
 * (@thomasplevy)
 * [10 years ago](https://wordpress.org/support/topic/give-certificate-programmatically/#post-7452806)
 * [@adamkowalski](https://wordpress.org/support/users/adamkowalski/),
 * Really stoked to see a developer looking to extend our existing functionality—
 * to programmatically award a certificate you’ll want to checkout our LLMS_Engagements
   class (includes/class.llms.engagements.php). Access the class itself via `LLMS()-
   >engagements()`
 * You can then use the “handle_certificate() method to award the certificate.
 * I don’t have the method documented online anywhere but look at the inline docblock
   on the function for description of arguments you should pass to the function.
 * Finally, if you look at the function’s constructor, there’s a handful of filters
   you can hook into which would allow you to hook directly into our achievement’s
   engine so you can add your custom trigger to the list of available triggers, 
   should you wish to go down that road.
 * In your scenario you’d create a Cert and award it however you see fit, but if
   you hook into our filters you’d need to simply call the action and our engagements
   class would take care of the rest. Then you could create an Engagement post and
   select your engagement from the list of engagements.
 * This requires a bit more work on your part though but would create a more complete
   integration.
 * Please let me know if you have any further questions or need anything else and
   have a great day,
 *  Thread Starter [adamkowalski](https://wordpress.org/support/users/adamkowalski/)
 * (@adamkowalski)
 * [10 years ago](https://wordpress.org/support/topic/give-certificate-programmatically/#post-7453017)
 * [@thomasplevy](https://wordpress.org/support/users/thomasplevy/),
 * Thanks for the quick reply!
 * So there is a bit of a hiccup in the project we are working on, as we already
   have a deployed project with version 1.4.3 Of LifterLMS. After looking through
   your reply and comparing the code on GitHub with our local version it seems as
   if the API has changed quite a bit in terms of engagements and certificates.
 * We are going to discuss as a team the implications of migrating to a newer version,
   however, I am wondering if you could help me figure out how to approach this 
   problem using the older version of the API.
 *  Thread Starter [adamkowalski](https://wordpress.org/support/users/adamkowalski/)
 * (@adamkowalski)
 * [10 years ago](https://wordpress.org/support/topic/give-certificate-programmatically/#post-7453019)
 * I have found a function called `custom_certificate_earned` in v1.4.3
 *     ```
       function custom_certificate_earned( $person_id, $certificate_id, $engagement_id ) {
         if ( ! $person_id )
           return;
   
         $certificate = $this->emails['LLMS_Certificate_User'];
   
         $certificate->trigger( $person_id, $certificate_id, $engagement_id );
       }
       ```
   
 * Which seems to be analogous to `trigger_engagement` in v2.7.4
 *     ```
       function trigger_engagement( $person_id, $certificate_id, $related_post_id ) {
         $certificate = $this->certs['LLMS_Certificate_User'];
         $certificate->trigger( $person_id, $certificate_id, $related_post_id );
       }
       ```
   
 * I have a person_id and a certificate_id to give it, but what would you use for
   an engagement_id if the certificate should be given regardless of whether or 
   not the engagement has fired?
 *  [Thomas Patrick Levy](https://wordpress.org/support/users/thomasplevy/)
 * (@thomasplevy)
 * [10 years ago](https://wordpress.org/support/topic/give-certificate-programmatically/#post-7453023)
 * [@adamkowalski](https://wordpress.org/support/users/adamkowalski/),
 * Disclaimer: There were some *major* problems with our codebase as related to 
   engagements which were resolved in our 2.3.0 release where we refactored everything
   engagements related to ensure things were working the way they were supposed 
   to be working.
 * In both cases, the $engagement_id should be the WordPress post id of whatever
   post completed the engagement. We actually have a backlogged task to figure out
   how to make this 3rd parameter unnecessary. If you look through a bit further
   you’ll find an [@todo](https://wordpress.org/support/users/todo/) noting this
   exact issue in relation to our user registration events (which has no related
   post).
 * At this very moment we pass the engagement_id twice. In your case it would be
   the certificate_id.
 * I think that should work but please please please thoroughly test this before
   putting anything into production. We’ll be resolving this internally at some 
   point in the future and giving some method to record the action if it has no 
   related post id.
 * Take care,
 *  Thread Starter [adamkowalski](https://wordpress.org/support/users/adamkowalski/)
 * (@adamkowalski)
 * [10 years ago](https://wordpress.org/support/topic/give-certificate-programmatically/#post-7453036)
 * [@thomasplevy](https://wordpress.org/support/users/thomasplevy/),
 * Thank you for letting me know!
 * After playing around with the code above it seems that I had to change one line:
 *     ```
       $certificate = $this->emails['LLMS_Certificate_User'];
       // to
       $certificate = $this->certs['LLMS_Certificate_User'];
       ```
   
 * As `$this->emails` wasn’t in scope. After making that change and calling the 
   function with the parameters you suggested (person_id, cert_id, cert_id) I was
   able to give a student a certificate!
 * However, unfortunately the template did not correctly render and all the tags
   such as {first_name} and {last_name} do not get replaced with the students information
   and are instead blank. Is there a good way to solve this problem? Right now I
   am thinking about running a sql query to find the actual certificate and parse
   the generated certificate placing the correct information where it belongs.
 *  Thread Starter [adamkowalski](https://wordpress.org/support/users/adamkowalski/)
 * (@adamkowalski)
 * [10 years ago](https://wordpress.org/support/topic/give-certificate-programmatically/#post-7453038)
 * The strange thing is, that when I started drilling around in the database it 
   seems like it is stored as just a WordPress post and it has a field called post_content.
 * I extracted that data out and just looked at it as a regular html document and
   it looks correct, with the names and dates as intended. I will try to dig around
   and see what the code looks like where the template string is replaced with the
   actual data.
 *  [Thomas Patrick Levy](https://wordpress.org/support/users/thomasplevy/)
 * (@thomasplevy)
 * [10 years ago](https://wordpress.org/support/topic/give-certificate-programmatically/#post-7453040)
 * Hey [@adamkowalski](https://wordpress.org/support/users/adamkowalski/),
 * You’re absolutely right, there’s issues in the codebase you’re using. That’s 
   why we released updates!
 * I don’t really know how to resolve those for you as my answer to resolving those
   bugs come in the form of the codebase at 2.3.0 when we overhauled the system.
 * Take care,
 *  Thread Starter [adamkowalski](https://wordpress.org/support/users/adamkowalski/)
 * (@adamkowalski)
 * [10 years ago](https://wordpress.org/support/topic/give-certificate-programmatically/#post-7453054)
 * [@thomasplevy](https://wordpress.org/support/users/thomasplevy/),
 * Thank you for all your help, I will mark this as resolved as I think I know how
   to finish up from here. I will definitely try to get us onto a path where we 
   can upgrade the version relatively soon. It seems like you guys have implemented
   a lot of exciting features that would be nice to incorporate into our project.
 *  [Thomas Patrick Levy](https://wordpress.org/support/users/thomasplevy/)
 * (@thomasplevy)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/give-certificate-programmatically/#post-7453056)
 * [@adamkowalski](https://wordpress.org/support/users/adamkowalski/),
 * I’d very much recommend upgrading but I understand the way projects go. Upgrading(
   especially from that far back) is often more difficult than it needs to be. Especially
   when things start to get heavily customized or modified.
 * Anyways, good luck and please let me know if you need anything else related to
   this or otherwise.
 * Take care,

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Give certificate programmatically’ is closed to new replies.

 * ![](https://ps.w.org/lifterlms/assets/icon.svg?rev=2034507)
 * [LifterLMS - WP LMS for eLearning, Online Courses, & Quizzes](https://wordpress.org/plugins/lifterlms/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/lifterlms/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/lifterlms/)
 * [Active Topics](https://wordpress.org/support/plugin/lifterlms/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/lifterlms/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/lifterlms/reviews/)

## Tags

 * [Certificate](https://wordpress.org/support/topic-tag/certificate/)
 * [lifter](https://wordpress.org/support/topic-tag/lifter/)
 * [lms](https://wordpress.org/support/topic-tag/lms/)

 * 9 replies
 * 2 participants
 * Last reply from: [Thomas Patrick Levy](https://wordpress.org/support/users/thomasplevy/)
 * Last activity: [9 years, 12 months ago](https://wordpress.org/support/topic/give-certificate-programmatically/#post-7453056)
 * Status: resolved