uo_forgot_before_error_message
Fires before an error message is displayed during the forgot password process, allowing for custom error handling.
add_action( 'uo_forgot_before_error_message', $callback, 10, 1 );
Description
Fires before the error message is displayed on the forgot password form. Use this hook to modify or add content before the actual error message output, allowing for custom error handling or additional information.
Usage
add_action( 'uo_forgot_before_error_message', 'your_function_name', 10, 1 );
Examples
add_action( 'uo_forgot_before_error_message', 'my_custom_forgot_error_message_modifier' );
/**
* Modifies the error message displayed on the forgot password form.
* This is a realistic example that might log the error or append additional context.
*
* @param object|null $forgot_password_response The response object from the forgot password process.
* This might contain a 'message' property.
*/
function my_custom_forgot_error_message_modifier( $forgot_password_response = null ) {
// In a real-world scenario, you might want to inspect the $forgot_password_response
// to determine if it's an actual error and what kind of error it is.
// For this example, we'll assume if it's set and has a message, we can do something.
if ( $forgot_password_response && isset( $forgot_password_response->message ) && ! empty( $forgot_password_response->message ) ) {
// Example: Log the error for debugging purposes.
// This would typically be done with WP_Error::add() or similar, but
// since we're hooking into the display phase, logging here is for demonstration.
error_log( 'UO Forgot Password Error: ' . $forgot_password_response->message );
// Example: Prepend some custom text to the error message.
// Note: This hook fires *before* the actual message is displayed in the span.
// To actually modify the message shown to the user, you'd typically need
// to hook into something that directly controls the output of the message,
// or if this action provides a way to pass back a modified message.
// Assuming for demonstration that we *could* modify a global or pass it back.
// A more robust solution might involve a filter hook if one existed for the message itself.
// For this example, we'll simulate prepending by printing directly, though this isn't
// the typical way to handle this with a standard action hook.
echo '<span class="custom-error-prefix">Oops! </span>';
}
}
// Note: The 'uo_forgot_before_error_message' hook, as presented in the context,
// seems designed to allow actions to *output* content before the main message.
// If the goal was to *filter* or *modify* the message string itself, a different
// hook type (filter) or hook name would be more appropriate.
// The provided 'existing example' shows the `do_action` call right before the span,
// implying that content can be injected there.
// The 'Internal usage' comment is also crucial – if this hook is designed to pass
// variables, the function signature and logic would adapt. Since no specific variables
// are documented as being passed by the hook, we'll assume it can accept an optional
// response object as shown in the function definition, which might be a global or
// passed implicitly by the WordPress context.
// The parameter count for add_action should match the number of arguments the hook passes.
// Without explicit documentation on what arguments `uo_forgot_before_error_message` passes,
// we assume it might pass the `$forgot_password_response` object or nothing.
// The example `function my_custom_forgot_error_message_modifier( $forgot_password_response = null )`
// is a safe bet, allowing for either case. If the hook passes no arguments, `null` would be used.
// If the hook passes an argument, it would be received.
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:130
src/templates/frontend-login/layout_1-lost-pwd.php:123
?>
<?php do_action( 'uo_forgot_before_error' ); ?>
<div class="ult-form__validation <?php echo implode( ' ', $notice_css_classes ); ?>">
<div class="ult-notice ult-notice--error">
<?php do_action( 'uo_forgot_before_error_message' ); ?>
<span class="ult-notice-text"><?php echo isset( $forgot_password_response->message ) ? $forgot_password_response->message : ''; ?></span>
<?php do_action( 'uo_forgot_after_error_message' ); ?>
</div>
</div>