uo_forgot_before_submit
Fires before the user forgot password form is submitted, allowing customization of the process.
add_action( 'uo_forgot_before_submit', $callback, 10, 1 );
Description
Fires before the forgot password form is submitted. Allows developers to add custom validation or modify data before processing the password reset request, potentially adding custom error messages or logic.
Usage
add_action( 'uo_forgot_before_submit', 'your_function_name', 10, 1 );
Examples
<?php
/**
* Example of how to use the 'uo_forgot_before_submit' action hook.
* This example demonstrates adding a custom validation check before the password reset form is submitted.
*
* The 'uo_forgot_before_submit' hook fires just before the submit button of the forgot password form.
* It does not pass any arguments by default.
*/
add_action( 'uo_forgot_before_submit', 'my_custom_forgot_password_validation', 10 );
/**
* Custom validation function for the forgot password form.
* This function adds a custom check to ensure a specific condition is met before submission.
* In a real-world scenario, you might check for specific user roles, site configurations, etc.
*
* Note: This hook typically does not receive arguments. If the form submission logic
* relies on JavaScript to intercept and potentially modify data before sending,
* this PHP hook might not be the primary place for pre-submission validation that
* modifies form data directly. However, it's useful for performing server-side checks
* that can influence the form's behavior or add messages before the actual submission.
*/
function my_custom_forgot_password_validation() {
// For demonstration purposes, let's imagine we want to prevent submission
// if a specific site option is disabled.
// In a real plugin, you'd likely access options or global variables
// related to the form or user context.
// Let's assume there's a global variable or a way to check if a certain feature is active.
// For this example, we'll use a hypothetical check.
$is_custom_feature_enabled = false; // Set to true to see the message change
if ( ! $is_custom_feature_enabled ) {
// You could dynamically add an error message to the form.
// The 'uo_forgot_after_error_message' hook might be a better place
// to display this, but this hook allows pre-submission logic.
// For instance, you might want to use JavaScript to show a message
// based on this hook's execution.
// In a real scenario, you might set a transient or session variable
// that your JavaScript can read.
// set_transient( 'uo_forgot_pre_submit_warning', __( 'Custom feature is currently disabled. Please contact support.', 'your-text-domain' ), 60 );
// Alternatively, if this hook is used in conjunction with AJAX submission,
// you could potentially output an error directly here if the context allows.
// However, for a standard form submission, this is less direct.
// For this example, we'll just echo a conceptual message.
// In a practical application, you'd manage this more gracefully,
// perhaps by enqueueing a script that listens for this hook.
?>
<script type="text/javascript">
// This is a conceptual example. In a real scenario, you'd enqueue a JS file
// and use a more robust method to communicate between PHP and JS.
document.addEventListener('DOMContentLoaded', function() {
var submitButton = document.getElementById('ult-forgot-password-submit-btn');
if (submitButton) {
// In a real scenario, you'd check for a specific condition passed from PHP.
// For this example, we'll just show a console message.
console.log("UO Forgot Before Submit hook fired. Performing custom validation...");
// Example: Preventing submission if a certain condition is met.
// if (true) { // Replace 'true' with your actual condition check
// alert("Your custom validation failed. Please check the conditions.");
// submitButton.disabled = true;
// }
}
});
</script>
<?php
}
// If you had any arguments to process, you would do it here.
// The 'uo_forgot_before_submit' hook is generally considered to have 0 arguments.
// If you were to add arguments, you would specify them in add_action.
}
?>
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:138
src/templates/frontend-login/layout_1-lost-pwd.php:131
src/templates/frontend-login/default-lost-pwd.php:44
<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>
<?php do_action( 'uo_forgot_before_submit' ); ?>
<div class="ult-form__row ult-form__row--submit">
<button type="submit" id="ult-forgot-password-submit-btn" class="ult-form__submit-btn">
<?php echo $innerText['Get-New-Password']; ?>
</button>
</div>