uo_course_certificate_email_subject
Filters the email subject line for course completion certificate notifications.
add_filter( 'uo_course_certificate_email_subject', $callback, 10, 3 );
Description
Filters the email subject line sent to users upon course certificate generation. Developers can modify the subject, allowing for dynamic content or custom messaging based on the user or course. This hook fires just before the email is sent.
Usage
add_filter( 'uo_course_certificate_email_subject', 'your_function_name', 10, 3 );
Parameters
-
$email_subject(mixed) - The subject line for the certificate email.
-
$user(mixed) - This parameter contains the current subject line of the email being sent for a course certificate.
-
$course_id(mixed) - This parameter contains the user object for whom the certificate is being generated.
Return Value
The filtered value.
Examples
/**
* Modify the course certificate email subject to include the course title.
*
* @param string $email_subject The original email subject.
* @param WP_User $user The user object for whom the certificate was generated.
* @param int $course_id The ID of the course.
*
* @return string The modified email subject.
*/
add_filter( 'uo_course_certificate_email_subject', function( $email_subject, $user, $course_id ) {
// Check if the user and course IDs are valid.
if ( ! $user instanceof WP_User || ! $course_id || ! absint( $course_id ) ) {
return $email_subject; // Return original subject if data is invalid.
}
// Get the course title.
$course_title = get_the_title( $course_id );
// If a course title exists, prepend it to the email subject.
if ( $course_title ) {
// You might want to add a separator like a colon or hyphen.
$email_subject = sprintf( '%s: %s', $course_title, $email_subject );
}
// Optionally, you could add the user's display name as well.
// $email_subject = sprintf( '%s - %s', $email_subject, $user->display_name );
return $email_subject;
}, 10, 3 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/course-completion-certificate.php:358
$is_group_admin = self::get_settings_value( 'uncanny-course-certificate-group-leader', __CLASS__ );
$email_message = self::get_settings_value( 'uncanny-course-certificate-email-body', __CLASS__ );
$non_user_body = self::get_settings_value( 'uncanny-course-certificate-non-user-email-body', __CLASS__ );
$email_subject = self::get_settings_value( 'uncanny-course-certificate-subject-line', __CLASS__ );
$email_subject_user = self::get_settings_value( 'uncanny-course-certificate-user-subject-line', __CLASS__ );
$cc_emails = self::get_settings_value( 'uncanny-course-certificate-cc-emails', __CLASS__ );
$email_subject = apply_filters( 'uo_course_certificate_email_subject', $email_subject, $user, $course_id );
$email_message = apply_filters( 'uo_course_certificate_email_message', $email_message, $user, $course_id );
$from_name = self::get_settings_value( 'uncanny-course-certificate-from-name', __CLASS__ );
$from_email = self::get_settings_value( 'uncanny-course-certificate-from-email', __CLASS__ );
$from_name = empty( $from_name ) ? get_bloginfo( 'name' ) : $from_name;
$from_email = empty( $from_email ) ? get_bloginfo( 'admin_email' ) : $from_email;