Skip to content

Instantly share code, notes, and snippets.

@LaxusCroco
Created September 26, 2023 14:06
Show Gist options
  • Save LaxusCroco/550f1f9ed088038df5457c07aef80304 to your computer and use it in GitHub Desktop.
Save LaxusCroco/550f1f9ed088038df5457c07aef80304 to your computer and use it in GitHub Desktop.
JetFormBuilder Check if user password matches entered password
<?php
/**
* To get all the values of the fields in the form, you can use the expression:
* jet_fb_request_handler()->get_request() or $context->get_request()
\*
* If the field is located in the middle of the repeater, then only
* jet_fb_request_handler()->get_request(), but $context->get_request()
* will return the values of all fields of the current repeater element
\*
* @param $value mixed
* @param $context \Jet_Form_Builder\Request\Parser_Context
\*
* @return bool
*/
function jet_fb_v_check_iss_pswd_unique( $value, $context ): bool {
if ( ! is_string( $value ) || empty( $value ) ) {
return false;
}
$user_id = get_current_user_id();
$user = get_user_by( 'ID', $user_id );
if ( ! ( $user instanceof \WP_User ) ) {
return false;
}
return (bool) wp_check_password( $value, $user->user_pass, $user->ID );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment