uo_reset_before_captcha
Fires just before the captcha is displayed during the user reset process.
add_action( 'uo_reset_before_captcha', $callback, 10, 1 );
Description
Fires before the password confirmation field is displayed in the reset password form. Developers can use this hook to add custom content or modify the form structure before the confirmation input and CAPTCHA are rendered.
Usage
add_action( 'uo_reset_before_captcha', 'your_function_name', 10, 1 );
Examples
add_action( 'uo_reset_before_captcha', 'my_uo_add_recaptcha_to_reset_form', 10, 1 );
/**
* Adds reCAPTCHA to the user reset password form before the submit button.
*
* This function is hooked into the 'uo_reset_before_captcha' action.
* It checks if reCAPTCHA is enabled in plugin settings and displays
* the reCAPTCHA widget if it is.
*
* @param array $args An array of arguments passed to the action hook. (Not used in this example)
*/
function my_uo_add_recaptcha_to_reset_form( $args ) {
// Assuming you have a function or option to check if reCAPTCHA is enabled
// Replace 'my_plugin_is_recaptcha_enabled()' with your actual logic.
if ( my_plugin_is_recaptcha_enabled() ) {
$recaptcha_site_key = get_option( 'my_plugin_recaptcha_site_key' ); // Get your reCAPTCHA site key
if ( ! empty( $recaptcha_site_key ) ) {
?>
<div id="recaptcha-container" style="margin-bottom: 15px;"></div>
<script src="https://www.google.com/recaptcha/api.js?render=<?php echo esc_js( $recaptcha_site_key ); ?>"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
grecaptcha.ready(function() {
grecaptcha.execute('<?php echo esc_js( $recaptcha_site_key ); ?>', {action: 'reset_password'})
.then(function(token) {
// Add the token to a hidden input field so it can be submitted with the form
var recaptchaResponse = document.createElement('input');
recaptchaResponse.type = 'hidden';
recaptchaResponse.name = 'g-recaptcha-response';
recaptchaResponse.value = token;
document.getElementById('pass2').closest('form').appendChild(recaptchaResponse);
});
});
});
</script>
<?php
}
}
}
/**
* Placeholder function to check if reCAPTCHA is enabled.
* Replace this with your actual function to check plugin settings.
*
* @return bool True if reCAPTCHA is enabled, false otherwise.
*/
function my_plugin_is_recaptcha_enabled() {
// Example: Check an option in WordPress settings
return get_option( 'my_plugin_enable_recaptcha', false );
}
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/default-reset-pwd.php:50
src/templates/frontend-login/modern_ui-reset-pwd.php:103
src/templates/frontend-login/layout_1-reset-pwd.php:96
<p class="user-pass2-wrap">
<label for="pass2"><?php echo $innerText['Confirm-Password']; ?></label><br/>
<input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" required/>
</p>
<div class="wp-pwd">
<?php do_action( 'uo_reset_confirm_password_actions' ); ?>
</div>
<?php do_action( 'uo_reset_before_captcha' ); ?>
<!-- <p class="description indicator-hint">--><?php /*echo $innerText['Password-Indicator-Hint'];*/ ?><!--</p>-->
<br class="clear"/>
<input type="hidden" name="rp_key" value="<?php echo esc_attr( $rp_key ); ?>"/>
<?php do_action( 'uo_reset_before_submit' ); ?>
<p class="submit"><input type="submit" name="wp-submit" id="wp-submit"
class="button button-primary button-large"
value="<?php echo $innerText['Reset-Password-Button']; ?>"/></p>