Validate Current Password

Require users to confirm their current password before changing their password.

Instructions

Code

Filename: gw-validate-current-password.php

<?php
/**
 * Gravity Wiz // Gravity Forms // Validate Current Password
 * https://gravitywiz.com/
 *
 * Instruction Video: https://www.loom.com/share/118994cfff0f4441a519116bbc3ed0c7
 *
 * Require users to confirm their current password before changing their password.
 */
// Update "123" to your form ID and "4" to your Password field ID.
add_filter( 'gform_field_validation_123_4', function( $result, $value ) {
	$user = wp_get_current_user();
	if ( $user && ! wp_check_password( $value, $user->data->user_pass, $user->ID ) ) {
		$result['is_valid'] = false;
		$result['message']  = 'Invalid current password. Please try again.';
	}
	return $result;
}, 10, 2 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.