We want to set the password for the user and all the password will be the same. The default password for all our users is [edit].
I tried this but it gave me the error message. However, the user was created.
add_action( 'cred_save_data', 'tssupp_cred_autologin', 10, 2 );
function tssupp_cred_autologin( $post_id, $form_data ){
if ( 1908 == $form_data['id'] ) {
if ( !empty( $_POST['user_email'] ) ) {
// Get new user based on email
$user = get_user_by( 'email', $_POST['user_email'] );
// Login with new password
$user_data = array(
'user_login' => $user->data->user_login,
'user_password' => $user->data->user_pass, // I tried replacing this with required password but it doesn't work too
'remember' => true
);
$login = wp_signon( $user, false );
if ( is_wp_error( $login ) ) {
error_log( $login->get_error_message() );
}
}
}
}
I thought the form settings were that the password is auto-generated?
That means WordPress will create a random password.
If you want all the users to have the same password of your choice then you should not specify that the password is auto-generated. The form submission needs to include the password fields to be able to successfully create the user. You could hide them with CSS and populate them with JS, or it may be possible to omit them from the form and add them using an API filter.
But, probably the easiest solution would be to persist with auto-generating the password together with the code that I shared in my last reply, and simply replace the new random password with your chosen password, i.e. change the line $new_pass = wp_generate_password( 10, false ); to $new_pass = 'chosen password';