uo_forgot_before_email
Fires before the forgot password email is sent, allowing for modifications.
add_action( 'uo_forgot_before_email', $callback, 10, 1 );
Description
Fires before the forgot password email is sent. Developers can use this hook to modify email content, add custom data, or perform actions before the email is dispatched, such as logging or custom validation.
Usage
add_action( 'uo_forgot_before_email', 'your_function_name', 10, 1 );
Examples
// Add a custom validation rule to check if the entered email is a valid WordPress user's email.
add_action( 'uo_forgot_before_email', 'my_custom_uo_forgot_email_validation', 10, 0 );
function my_custom_uo_forgot_email_validation() {
// Check if the form has been submitted and if the email field is set.
if ( isset( $_POST['user_login'] ) && ! empty( $_POST['user_login'] ) ) {
$email_or_username = sanitize_text_field( $_POST['user_login'] );
// Attempt to get the user by email address.
$user = get_user_by_email( $email_or_username );
// If no user is found by email, try to find by username.
if ( ! $user ) {
$user = get_user_by( 'login', $email_or_username );
}
// If still no user is found, display an error.
if ( ! $user ) {
// This part would typically involve passing an error message back to the form.
// For this example, we'll simulate setting a transient to hold the error.
// In a real scenario, you might hook into another action or directly output
// an error message if the hook context allows.
set_transient( 'uo_forgot_error_message', __( 'The entered email or username is not associated with any account.', 'your-text-domain' ), 60 );
// You might also want to prevent further processing or redirect back with an error.
// For this example, we'll just set the transient.
}
} else {
// If the email field is empty, show an error.
set_transient( 'uo_forgot_error_message', __( 'Please enter your email address or username.', 'your-text-domain' ), 60 );
}
}
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/templates/frontend-login/modern_ui-lost-pwd.php:83
src/templates/frontend-login/layout_1-lost-pwd.php:76
<div class="ult-form__container">
<form id="ult-forgot-password-form" name="lostpasswordform" action="<?php echo site_url( 'wp-login.php?action=lostpassword', 'login_post' ); ?>" method="POST">
<input type="hidden" name="redirect_to" value="<?php echo $login_page_url . ( strpos( $login_page_url, '?' ) ? '&' : '?' ); ?>action=forgot&success=1">
<?php do_action( 'uo_forgot_before_email' ); ?>
<div class="ult-form__row ult-form__row--email">
<div class="ult-form-field__header">
<div class="ult-form-field__label-container">
<label for="ult-forgot-email" class="ult-form-field__label">
<?php echo $innerText['Password-Recovery-Label']; ?>
</label>