• Resolved adamgonz

    (@adamgonz)


    After a course is completed, I hook into the sensei_user_course_end action that displays a course completion message.

    my code basically looks like:
    function check_courses_completion( $user_id, $course_id ){
    echo “congratulations…”
    }

    add_action( ‘sensei_user_course_end’,’check_courses_completion’, 10, 2 );

    The initial display shows the message only once but if I refresh the page, it will show the same message a second time.

    Any idea why?

Viewing 1 replies (of 1 total)
  • Hi @adamgonz ,

    My apologies for the delay in responding!

    My understanding is that you want to show the message a first time, but not after the refresh.

    That hook is fired again after the refresh because the page still contains the $_POST from the submit, which is used to trigger that hook. If you want to show the message only in the first time, I’d recommend making a control direct in your function (maybe with a transient?).

    Also, that hook is not the best one to echo a message because that is not part of a template. It will write the message before writing the HTML. You can use that to control when show the message, but I’d recommend to use another hook to echo the message. Maybe the the_content?

    If instead you mean you are having a duplicated message after the refresh. I’m not able to reproduce it, but the same solution applies here. You should use that hook only to control if you’ll show the message or not, and show the message in something like the_content.

    That said, we can’t provide support for customizations like this, but hopefully that will get you pointed in the right direction.

    Best,

Viewing 1 replies (of 1 total)
  • The topic ‘Action sensei_user_course_end runs twice on page refresh’ is closed to new replies.