diff --git a/includes/admin/post-types/meta-boxes/class.llms.meta.box.engagement.php b/includes/admin/post-types/meta-boxes/class.llms.meta.box.engagement.php index a182935e73..dce7c276ae 100644 --- a/includes/admin/post-types/meta-boxes/class.llms.meta.box.engagement.php +++ b/includes/admin/post-types/meta-boxes/class.llms.meta.box.engagement.php @@ -112,6 +112,12 @@ public function get_fields() { 'label' => __( 'Select a Section', 'lifterlms' ), ), + 'llms_certificate' => array( + 'controller_value' => array( 'user_earned_certificate' ), + 'id' => '_faux_engagement_trigger_post_llms_certificate', + 'label' => __( 'Select a Certificate', 'lifterlms' ), + ), + ); foreach ( $trigger_post_fields as $post_type => $data ) { @@ -324,6 +330,10 @@ public function save( $post_id ) { $var = 'track'; break; + case 'user_earned_certificate': + $var = 'llms_certificate'; + break; + default: $var = false; diff --git a/includes/class.llms.engagements.php b/includes/class.llms.engagements.php index 9c44b485e2..842c9c1bb8 100644 --- a/includes/class.llms.engagements.php +++ b/includes/class.llms.engagements.php @@ -151,7 +151,7 @@ private function get_engagements( $trigger_type, $related_post_id = '' ) { $related_select = ', relation_meta.meta_value AS related_post_id'; $related_join = "LEFT JOIN $wpdb->postmeta AS relation_meta ON triggers.ID = relation_meta.post_id"; - $related_where = $wpdb->prepare( "AND relation_meta.meta_key = '_llms_engagement_trigger_post' AND relation_meta.meta_value = %d", $related_post_id ); + $related_where = $wpdb->prepare( "AND relation_meta.meta_key = '_llms_engagement_trigger_post' AND ( relation_meta.meta_value IS NULL OR relation_meta.meta_value = %d )", $related_post_id ); } @@ -232,6 +232,7 @@ protected function get_trigger_hooks() { 'llms_rest_student_registered', 'llms_user_added_to_membership_level', 'llms_user_enrolled_in_course', + 'llms_user_earned_certificate', ); // If there are any actions registered to this deprecated hook, add it to the list. @@ -443,6 +444,10 @@ private function parse_hook_find_trigger_type( $action, $related_post_id ) { case 'lifterlms_product_purchased': $trigger_type = str_replace( 'llms_', '', get_post_type( $related_post_id ) ) . '_purchased'; break; + + case 'llms_user_earned_certificate': + $trigger_type = str_replace( 'llms_', '', $action ); + break; } return $trigger_type; diff --git a/includes/llms.functions.core.php b/includes/llms.functions.core.php index ebd4babb1e..6688b2f5d4 100644 --- a/includes/llms.functions.core.php +++ b/includes/llms.functions.core.php @@ -455,20 +455,21 @@ function llms_get_engagement_triggers() { return apply_filters( 'lifterlms_engagement_triggers', array( - 'user_registration' => __( 'Student creates a new account', 'lifterlms' ), - 'access_plan_purchased' => __( 'Student Purchases an Access Plan', 'lifterlms' ), - 'course_enrollment' => __( 'Student enrolls in a course', 'lifterlms' ), - 'course_purchased' => __( 'Student purchases a course', 'lifterlms' ), - 'course_completed' => __( 'Student completes a course', 'lifterlms' ), + 'user_registration' => __( 'Student creates a new account', 'lifterlms' ), + 'access_plan_purchased' => __( 'Student Purchases an Access Plan', 'lifterlms' ), + 'course_enrollment' => __( 'Student enrolls in a course', 'lifterlms' ), + 'course_purchased' => __( 'Student purchases a course', 'lifterlms' ), + 'course_completed' => __( 'Student completes a course', 'lifterlms' ), // 'days_since_login' => __( 'Days since user last logged in', 'lifterlms' ), // @todo. - 'lesson_completed' => __( 'Student completes a lesson', 'lifterlms' ), - 'quiz_completed' => __( 'Student completes a quiz', 'lifterlms' ), - 'quiz_passed' => __( 'Student passes a quiz', 'lifterlms' ), - 'quiz_failed' => __( 'Student fails a quiz', 'lifterlms' ), - 'section_completed' => __( 'Student completes a section', 'lifterlms' ), - 'course_track_completed' => __( 'Student completes a course track', 'lifterlms' ), - 'membership_enrollment' => __( 'Student enrolls in a membership', 'lifterlms' ), - 'membership_purchased' => __( 'Student purchases a membership', 'lifterlms' ), + 'lesson_completed' => __( 'Student completes a lesson', 'lifterlms' ), + 'quiz_completed' => __( 'Student completes a quiz', 'lifterlms' ), + 'quiz_passed' => __( 'Student passes a quiz', 'lifterlms' ), + 'quiz_failed' => __( 'Student fails a quiz', 'lifterlms' ), + 'section_completed' => __( 'Student completes a section', 'lifterlms' ), + 'course_track_completed' => __( 'Student completes a course track', 'lifterlms' ), + 'membership_enrollment' => __( 'Student enrolls in a membership', 'lifterlms' ), + 'membership_purchased' => __( 'Student purchases a membership', 'lifterlms' ), + 'user_earned_certificate' => __( 'Student earns a certificate', 'lifterlms' ), ) ); } diff --git a/includes/notifications/controllers/class.llms.notification.controller.certificate.earned.php b/includes/notifications/controllers/class.llms.notification.controller.certificate.earned.php index aa6ad7883d..206160bf85 100644 --- a/includes/notifications/controllers/class.llms.notification.controller.certificate.earned.php +++ b/includes/notifications/controllers/class.llms.notification.controller.certificate.earned.php @@ -55,7 +55,6 @@ public function action_callback( $user_id = null, $certificate_id = null, $relat $this->related_post_id = $related_post_id; $this->send(); - } /** @@ -80,7 +79,6 @@ protected function get_subscriber( $subscriber ) { } return $uid; - } /** @@ -113,27 +111,15 @@ protected function set_subscriber_options( $type ) { $options[] = $this->get_subscriber_option_array( 'student', 'yes' ); break; + case 'email': + $options[] = $this->get_subscriber_option_array( 'student', 'no' ); + $options[] = $this->get_subscriber_option_array( 'custom', 'no' ); + break; + } return $options; - } - - /** - * Determine what types are supported - * Extending classes can override this function in order to add or remove support - * 3rd parties should add support via filter on $this->get_supported_types() - * - * @return array associative array, keys are the ID/db type, values should be translated display types - * @since 3.8.0 - * @version 3.8.0 - */ - protected function set_supported_types() { - return array( - 'basic' => __( 'Basic', 'lifterlms' ), - ); - } - } return LLMS_Notification_Controller_Certificate_Earned::instance(); diff --git a/includes/notifications/views/class.llms.notification.view.certificate.earned.php b/includes/notifications/views/class.llms.notification.view.certificate.earned.php index 3bfadaa2ab..f63bee208a 100644 --- a/includes/notifications/views/class.llms.notification.view.certificate.earned.php +++ b/includes/notifications/views/class.llms.notification.view.certificate.earned.php @@ -82,6 +82,10 @@ private function get_mini_html( $title ) { * @return string */ protected function set_body() { + if ( 'email' === $this->notification->get( 'type' ) ) { + // Translators: %1$s - student name, %2$s - Certificate title. + return sprintf( __( 'Congratulations! %1$s earned a certificate: %2$s.', 'lifterlms' ) . "\n\n{{MINI_CERTIFICATE}}\n\n" . $this->set_footer(), '{{STUDENT_NAME}}', '{{CERTIFICATE_TITLE}}' ); + } return '{{MINI_CERTIFICATE}}'; } @@ -213,7 +217,7 @@ private function set_merge_data_student_name( $cert ) { * @return string */ protected function set_subject() { - return ''; + return 'Certificate Earned: {{CERTIFICATE_TITLE}}'; } /** @@ -226,21 +230,4 @@ protected function set_subject() { protected function set_title() { return __( 'You\'ve earned a certificate!', 'lifterlms' ); } - - /** - * Defines field support for the view. - * - * @since 3.8.0 - * - * @return array - */ - protected function set_supported_fields() { - return array( - 'basic' => array( - 'body' => true, - 'title' => true, - 'icon' => true, - ), - ); - } }