profile-builder
/
admin
/
advanced-settings
/
includes
/
fields
/
automatically-generate-password.php
automatically-generate-password.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.7.0, at admin/advanced-settings/includes/fields/automatically-generate-password.php
| 1 | <?php |
| 2 | |
| 3 | $wppb_general_settings = get_option( 'wppb_general_settings' ); |
| 4 | |
| 5 | if ( isset( $wppb_general_settings ) && $wppb_general_settings['emailConfirmation'] == 'yes' ) { |
| 6 | add_filter( 'wppb_register_user_email_message_with_admin_approval', 'wppb_toolbox_ec_generate_password', 20, 5 ); |
| 7 | add_filter( 'wppb_register_user_email_message_without_admin_approval', 'wppb_toolbox_ec_generate_password', 20, 5 ); |
| 8 | } |
| 9 | |
| 10 | add_filter( 'wppb_check_form_field_default-password', 'wppb_toolbox_check_password_value', 20, 4 ); |
| 11 | add_filter( 'wppb_check_form_field_default-repeat-password', 'wppb_toolbox_check_password_value', 20, 4 ); |
| 12 | function wppb_toolbox_check_password_value( $message, $field, $request_data, $form_location ){ |
| 13 | if ( $form_location == 'register' ) |
| 14 | return; |
| 15 | |
| 16 | return $message; |
| 17 | } |
| 18 | |
| 19 | add_filter( 'wppb_register_password', '__return_empty_string', 10, 6 ); |
| 20 | add_filter( 'wppb_register_repeat_password', '__return_empty_string', 10, 6 ); |
| 21 | add_filter( 'wppb_send_password_in_default_email_message', '__return_true' ); |
| 22 | |
| 23 | add_filter('wppb_send_credentials_checkbox_logic', 'wppb_toolbox_send_credentials', 10, 2); |
| 24 | function wppb_toolbox_send_credentials($requestdata, $form){ |
| 25 | return '<input id="send_credentials_via_email" type="hidden" name="send_credentials_via_email" value="sending" />'; |
| 26 | } |
| 27 | |
| 28 | add_filter( 'wppb_build_userdata', 'wppb_toolbox_generate_password', 20, 2 ); |
| 29 | function wppb_toolbox_generate_password( $userdata, $global_request ) { |
| 30 | if ( $global_request['action'] == 'register' ) { |
| 31 | $userdata['user_pass'] = wp_generate_password(); |
| 32 | |
| 33 | return $userdata; |
| 34 | } |
| 35 | |
| 36 | return $userdata; |
| 37 | } |
| 38 | |
| 39 | function wppb_toolbox_ec_generate_password( $content, $email, $password, $user_message_subject, $context ) { |
| 40 | if ( empty( $email ) ) return $content; |
| 41 | |
| 42 | $user = get_user_by( 'email', $email ); |
| 43 | |
| 44 | if ( $user === false ) return $content; |
| 45 | |
| 46 | $password = wp_generate_password(); |
| 47 | |
| 48 | wp_set_password( $password, $user->ID ); |
| 49 | |
| 50 | $content = str_replace( 'Your selected password at signup', $password, $content ); |
| 51 | |
| 52 | return $content; |
| 53 | } |
| 54 |