WordPress.org

Forums

BadgeOS LearnDash Add-on
How to Add a Trigger for Completing a Lesson Topic (13 posts)

  1. Christian Freeman (codelion)
    Member
    Posted 8 months ago #

    Hi,

    After installing the Learndash Add-on, I noticed that there's no trigger that will allow users to receive a badge for completing a Learndash Lesson Topic. I figured that this may be because the Lesson Topic feature was added fairly recently.

    I'm in the process of adding the trigger now using the code provided by LearnDash:

    add_action(“learndash_topic_completed”, function($data) {
    //Called when topic is completed.
    }, 5, 1);

    I took a look at the plugin files for this BadgeOS LearnDash Add-on, and I do see where to add the trigger in the step-ui.php file, but I don't see where the code that actually hooks into this funtion is located.

    I went through the Developer documentation, and once I can get a full understanding of which files/functions need to be modified, I know I can get this done. Can you point me in the right direction on this one?

    https://wordpress.org/plugins/badgeos-learndash-add-on/

  2. Michael Beckwith
    Member
    Posted 8 months ago #

    Hrm, This is one of the extensions I don't have a lot of familiarity with out of the box, but I imagine the code that executes the awarding is in the /inc/rules-engine.php file.

    I've been a part of this for a year and a half, and I still don't fully understand parts :D I always strive to learn more though.

  3. Christian Freeman (codelion)
    Member
    Posted 8 months ago #

    Alright,

    I was successful in adding the Lesson Topic Action/Trigger. Testing went very smoothly. This is what I changed:

    badgeos-learndash.php
    Added Lesson Topic Trigger to Action Hooks On Line 85

    includes/rules-engine.php
    Added Lesson Topic Action Hook (learndash_topic_completed) On Line 151

    includes/steps-ui.php
    Added Lesson Topic Trigger to Actions Dropdown List () On Lines 148 - 170
    Added Lesson Topic Default Step Titles On Lines 287 - 299
    Added Lesson Topic to Form Toggle One Lines 405, 424, 444 – 446, & 470 - 471

    Pastebin is down at the moment, but if you'd like to download the files and use the code to update the plugin, here it is:

    teamupmovement.com/badgeos-learndash-add-on.zip

  4. Michael Beckwith
    Member
    Posted 8 months ago #

    Are you a GitHub user at all? It may be worth trying a gist. I'm having trouble getting the zip to download at the moment.

    Or better yet, you could always fork and pull request if you are a GitHub user.

    https://github.com/opencredit/BadgeOS-LearnDash-Add-on

  5. Christian Freeman (codelion)
    Member
    Posted 7 months ago #

    I did setup a GitHub account, but I don't really have the time to find out how to use it just yet. lol

    Pastebin is back up now, so here are the files:

    badgeos-learndash.php
    http://pastebin.com/ryNQESWp

    includes/rules-engine.php
    http://pastebin.com/4hhpUSBT

    includes/steps-ui.php
    http://pastebin.com/MfQ7Z91D

  6. Michael Beckwith
    Member
    Posted 7 months ago #

    Noted, thanks :)

  7. Christian Freeman (codelion)
    Member
    Posted 2 months ago #

    Ok, I've finally gotten around to learning how to use GitHub. I've forked and submitted a pull request, as you suggested.

    Here's the link to my version:

    https://github.com/codelion7/BadgeOS-LearnDash-Add-on

    Enjoy

  8. Michael Beckwith
    Member
    Posted 2 months ago #

    Received, thanks :)

  9. giantjack
    Member
    Posted 2 months ago #

    Hi Christian, and thank you for your work :)

    I've installed your modifications, because I really need to get a badge for every completed topic. When I add a badge, in steps options, indeed I get the LearnDash activity > Completed Topic menu.

    So I select the relevant topic for this badge, I click "save the steps", and then the WordPress blue button "Update".

    Problem is, when I edit the badge again, I can see it gets back to "any Lesson Topic" each time, so I can't award a badge for a specific topic.

    Is this a known issue ?

    Thank you :)
    Laurent

  10. Michael Beckwith
    Member
    Posted 2 months ago #

    It may be a case of it's just not visually selecting the correct select option again, but the value saved in the db is accurate still. If that's the case, you'd need to make sure to re-set the value before saving anything, or get the selected() working properly.

  11. giantjack
    Member
    Posted 2 months ago #

    Thanks Michael :)

    I forgot to add that I noticed this problem because it's not working for the user.
    I set up 4 different badges for completing topics 1, 2, 3, 4, and when a user marks as complete the first topic, he gets the 4 badges straight away. Every one of them seems set to "any lesson topic".
    So the value in the db is the one displayed in my admin I guess.

  12. Michael Beckwith
    Member
    Posted 1 month ago #

    Any changes here?

  13. giantjack
    Member
    Posted 1 month ago #

    Nothing for now, but I'll hire someone to solve the problem.

Reply

You must log in to post.

About this Plugin

  • BadgeOS LearnDash Add-on
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic