- finished with UM Forms validations;

This commit is contained in:
Mykyta Synelnikov
2023-06-30 16:58:12 +03:00
parent 71f2360694
commit 246de13726
4 changed files with 583 additions and 568 deletions
+8
View File
@@ -456,6 +456,13 @@ if ( ! class_exists( 'um\core\Form' ) ) {
// The '_um_last_login' cannot be updated through UM form.
$cf_metakeys = array_values( array_diff( $cf_metakeys, array( 'role_select', 'role_radio', 'role', '_um_last_login' ) ) );
// Column names from wp_users table.
$cf_metakeys = array_values( array_diff( $cf_metakeys, UM()->user()->update_user_keys ) );
// Remove restricted fields when edit profile.
if ( 'profile' === $this->form_data['mode'] ) {
$cf_metakeys = array_values( array_diff( $cf_metakeys, UM()->fields()->get_restricted_fields_for_edit() ) );
}
// Add required usermeta for register.
if ( 'register' === $this->form_data['mode'] ) {
$cf_metakeys[] = 'submitted';
}
@@ -659,6 +666,7 @@ if ( ! class_exists( 'um\core\Form' ) ) {
var_dump( '------------------------------------------------------------' );
var_dump( $all_cf_metakeys );
var_dump( $cf_metakeys );
var_dump( UM()->form()->errors );
exit;
}
/* Continue based on form mode - store data. */
File diff suppressed because it is too large Load Diff
+8 -6
View File
@@ -586,16 +586,18 @@ add_action( 'um_user_edit_profile', 'um_user_edit_profile', 10 );
/**
* @param array $post_form
* Validate nonce when profile form submit.
*
* @param array $submitted_data
*/
function um_profile_validate_nonce( $post_form ) {
$user_id = isset( $post_form['user_id'] ) ? $post_form['user_id'] : '';
$nonce = isset( $post_form['profile_nonce'] ) ? $post_form['profile_nonce'] : '';
function um_profile_validate_nonce( $submitted_data ) {
$user_id = isset( $submitted_data['user_id'] ) ? $submitted_data['user_id'] : '';
$nonce = isset( $submitted_data['profile_nonce'] ) ? $submitted_data['profile_nonce'] : '';
if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'um-profile-nonce' . $user_id ) ) {
wp_die( __( 'This is not possible for security reasons.', 'ultimate-member' ) );
wp_die( esc_html__( 'This is not possible for security reasons.', 'ultimate-member' ) );
}
}
add_action( 'um_submit_form_errors_hook__profile', 'um_profile_validate_nonce', 10, 1 );
add_action( 'um_submit_form_errors_hook__profile', 'um_profile_validate_nonce', 1 );
add_filter( 'um_user_pre_updating_files_array', array( UM()->validation(), 'validate_files' ), 10, 1 );
+8 -3
View File
@@ -267,13 +267,18 @@ function um_check_user_status( $user_id, $args ) {
}
add_action( 'um_registration_complete', 'um_check_user_status', 100, 2 );
function um_submit_form_errors_hook__registration( $args ) {
/**
* Validate user password field on registration.
*
* @param array $submitted_data
*/
function um_submit_form_errors_hook__registration( $submitted_data ) {
// Check for "\" in password.
if ( array_key_exists( 'user_password', $args ) && false !== strpos( wp_unslash( trim( $args['user_password'] ) ), '\\' ) ) {
if ( array_key_exists( 'user_password', $submitted_data ) && false !== strpos( wp_unslash( trim( $submitted_data['user_password'] ) ), '\\' ) ) {
UM()->form()->add_error( 'user_password', __( 'Passwords may not contain the character "\\".', 'ultimate-member' ) );
}
}
add_action( 'um_submit_form_errors_hook__registration', 'um_submit_form_errors_hook__registration', 10, 1 );
add_action( 'um_submit_form_errors_hook__registration', 'um_submit_form_errors_hook__registration' );
/**
* Registration form submit handler.