Ondersteuning » Code oplossingen gezocht » Prioriteiten van hooks

  • Hi guys,

    I’m working on an E-Learning system, using Learnpress, where I did some adjustments to some plugins to improve functionality. The thing I’m trying to do now is, after a user has finished a course, the certificate that pops up using a javascript, needs to be stored on the server, and afterwards I want to attach this file to an existing mail function.

    So I worked out how to save the file on the server, but unfortunately the mail function hook is executed before the actual pop up on the website (and thus before storing the certificate on the server).

    So to make it less abstract, the code:
    After a user has finished a course the following line is given:
    do_action( 'learn_press_user_finished_course', $course_id, $user_id );

    This action has several hooks in several plugins:

    • Plugin: learnpress-certificates
    • wp-content/plugins/learnpress-certificates/incs/load.php
    • function learn_press_user_finished_course_cookie( $course_id, $user_id ){
          if( $cert_id = get_post_meta( $course_id, '_lpr_course_certificate', true ) ) {
              set_transient('learn_press_user_finished_course_' . $user_id, $course_id);
          }
      }
      add_action( 'learn_press_user_finished_course', 'learn_press_user_finished_course_cookie', 10, 2);
    • Plugin: learnpress-certificates
    • wp-content/plugins/learnpress-certificates/incs/class-lpr-certificate-frontend.php
    • class LPR_Certificate_Frontend{
          /**
           * Constructor
           */
          function __construct(){
              $this->includes();
              add_action( 'init', array( $this, 'certificate_add_rewrite_tag' ), 1000 );
              add_action( 'init', array( $this, 'certificate_add_rewrite_rule' ), 1000 );
              add_action( 'wp', array( $this, 'certificate_output' ), 1001 );
              add_action( 'learn_press_user_finished_course', array( $this, 'user_finished_course_cookie' ), 10, 2);
              add_action( 'wp_head', array( $this, 'certificate_popout' ), 99999);
              add_action( 'wp_enqueue_scripts', array( $this, 'certificate_script' ) );
              add_action( 'learn_press_after_passed_course_content', array( $this, 'user_profile_certificate' ), 10 );
          }
    • Plugin: learnpress
    • /wp-content/plugins/learnpress/inc/user/lpr-user-functions.php
    • add_action( 'learn_press_user_finished_course', 'learn_press_user_finished_course_send_email', 999, 2 );
      
      function learn_press_user_finished_course_send_email( $course_id = null, $user_id = null ){
          $course_id = learn_press_get_course_id( $course_id );
          if( ! $user_id ) $user_id = get_current_user_id();
          $user = get_user_by( 'id', $user_id );
          if( empty( $user->ID ) || ! $course_id ) return false;
          $mail_to = $user->user_email;
      
          $assessment = get_post_meta( $course_id, '_lpr_course_final', true );
          if( 'yes' == $assessment ){
              $quiz_id = lpr_get_final_quiz( $course_id );
              $quiz_result = learn_press_get_quiz_result( $user_id, $quiz_id );
              $course_result = $quiz_result['mark_percent'] * 100;
          } else{
              $course_result = 100;
          }
          $args = apply_filters(
              'learn_press_vars_passed_course',
              array(
                  'user_name'     => ! empty( $user->display_name ) ? $user->display_name : $user->user_nicename,
                  'course_name'   => get_the_title( $course_id ),
                  'course_link'   => get_permalink( $course_id ),
                  'course_result' => sprintf( __( '%d%% of total' ), intval( $course_result ) )
              )
          );
      
          learn_press_send_mail(
              $mail_to,
              'passed_course',
              $args
          );
      }

      So how do I reorder the functions, where I want the mail to be send as last. I have tried changing the priorities of the hooks, but that didn’t work. Above the default values can be found.

      Thanks in advance.

      Jeroen Overdevest

  • Het onderwerp ‘Prioriteiten van hooks’ is gesloten voor nieuwe reacties.