Filter uncanny-learndash-groups

retrieve_password_title

Filters the subject of the password reset email. Filters the subject of the password reset email sent to users for customization.

add_filter( 'retrieve_password_title', $callback, 10, 3 );

Description

This filter hook, `retrieve_password_title`, fires just before the password reset email subject is finalized. Developers can use it to customize the email subject line sent to users requesting a password reset. The hook provides the default title, the user's login, and their `WP_User` object for dynamic customization.


Usage

add_filter( 'retrieve_password_title', 'your_function_name', 10, 3 );

Parameters

$title (mixed)
The title for the password reset email.
$user_login (mixed)
This parameter contains the current title of the password reset email, which can be filtered to customize it.
$user_data (mixed)
This parameter holds the login username for the user who requested the password reset.

Return Value

The filtered value.


Examples

<?php
/**
 * Customizes the subject line of the password reset email.
 *
 * This example adds a site-specific prefix to the password reset email subject
 * for better organization and identification in the inbox.
 *
 * @param string $title      The default email title.
 * @param string $user_login The username of the user requesting the reset.
 * @param WP_User $user_data The WP_User object for the user.
 * @return string The modified email title.
 */
add_filter( 'retrieve_password_title', function( $title, $user_login, $user_data ) {
    // Get the site name to use in the subject.
    $site_name = get_bloginfo( 'name' );

    // Prepend the site name and a separator to the default title.
    $custom_title = '[' . $site_name . '] ' . $title;

    // You could also add logic based on the user or site settings.
    // For example, if you wanted a different subject for administrators:
    // if ( user_can( $user_data->ID, 'manage_options' ) ) {
    //     $custom_title = '[ADMIN] ' . $custom_title;
    // }

    return $custom_title;
}, 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/helpers/rest-api-end-points.php:1665

$message .= sprintf( __( 'Username: %s', 'uncanny-learndash-groups' ), $user_login ) . "rnrn";
				$message .= __( 'If this was a mistake, just ignore this email and nothing will happen.', 'uncanny-learndash-groups' ) . "rnrn";
				$message .= __( 'To reset your password, visit the following address:', 'uncanny-learndash-groups' ) . "rnrn";
				$message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . "rn";

				/* translators: Password reset notification email subject. %s: Site title */
				$title = sprintf( __( '[%s] Password Reset', 'uncanny-learndash-groups' ), $site_name );
				$title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data );

				$message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
				$mail    = SharedFunctions::wp_mail( $user_email, wp_specialchars_decode( $title ), $message );
				if ( $message && ! $mail ) {
					$data['message'] = __( 'The email could not be sent. Possible reason: your host may have disabled the mail() function.', 'uncanny-learndash-groups' );
					wp_send_json_error( $data );
				}


Scroll to Top