diff --git a/includes/core/class-mail.php b/includes/core/class-mail.php index 8bd1acd7..af429cf2 100644 --- a/includes/core/class-mail.php +++ b/includes/core/class-mail.php @@ -423,6 +423,9 @@ if ( ! class_exists( 'um\core\Mail' ) ) { add_filter( 'um_template_tags_patterns_hook', array( UM()->mail(), 'add_placeholder' ) ); add_filter( 'um_template_tags_replaces_hook', array( UM()->mail(), 'add_replace_placeholder' ) ); + if ( array_key_exists( 'generated_pass', $args ) && 1 === absint( $args['generated_pass'] ) ) { + add_filter( 'um_template_tags_replaces_hook', array( UM()->mail(), 'add_replace_placeholder_set_password' ) ); + } /** * Filters email notification subject. @@ -621,6 +624,7 @@ if ( ! class_exists( 'um\core\Mail' ) ) { $placeholders[] = '{admin_email}'; $placeholders[] = '{submitted_registration}'; $placeholders[] = '{login_url}'; + $placeholders[] = '{login_button}'; $placeholders[] = '{password}'; $placeholders[] = '{account_activation_link}'; return $placeholders; @@ -639,9 +643,27 @@ if ( ! class_exists( 'um\core\Mail' ) ) { $replace_placeholders[] = um_admin_email(); $replace_placeholders[] = um_user_submitted_registration_formatted(); $replace_placeholders[] = um_get_core_page( 'login' ); + $replace_placeholders[] = esc_html__( 'Login to our site', 'ultimate-member' ); $replace_placeholders[] = esc_html__( 'Your set password', 'ultimate-member' ); $replace_placeholders[] = um_user( 'account_activation_link' ); return $replace_placeholders; } + + + public function add_replace_placeholder_set_password( $replace_placeholders ) { + $key = array_search( um_get_core_page( 'login' ), $replace_placeholders, true ); + if ( false !== $key ) { + $url = UM()->password()->reset_url(); + $replace_placeholders[ $key ] = add_query_arg( array( 'set_pass' => 'new_user' ), $url ); + } + + $button = esc_html__( 'Login to our site', 'ultimate-member' ); + $button_key = array_search( $button, $replace_placeholders , true ); + if ( false !== $key ) { + $url = UM()->password()->reset_url(); + $replace_placeholders[ $button_key ] = esc_html__( 'Set your password', 'ultimate-member' ); + } + return $replace_placeholders; + } } } diff --git a/includes/core/class-user.php b/includes/core/class-user.php index d4725da2..c47690f3 100644 --- a/includes/core/class-user.php +++ b/includes/core/class-user.php @@ -1690,7 +1690,7 @@ if ( ! class_exists( 'um\core\User' ) ) { ?> * */ - function approve( $repeat = true ) { + function approve( $repeat = true, $args = array() ) { $user_id = um_user( 'ID' ); if ( ! $repeat ) { @@ -1712,7 +1712,13 @@ if ( ! class_exists( 'um\core\User' ) ) { } else { //$userdata = get_userdata( $user_id ); //get_password_reset_key( $userdata ); - UM()->mail()->send( um_user( 'user_email' ), 'welcome_email' ); + $welcome_email_args = array(); + if ( true === (bool) $args['generated_pass'] ) { + $welcome_email_args = array( + 'generated_pass' => 1, + ); + } + UM()->mail()->send( um_user( 'user_email' ), 'welcome_email', $welcome_email_args ); } $this->set_status( 'approved' ); diff --git a/includes/core/um-actions-register.php b/includes/core/um-actions-register.php index 5f8a8404..f85c4ad4 100644 --- a/includes/core/um-actions-register.php +++ b/includes/core/um-actions-register.php @@ -8,12 +8,12 @@ if ( ! defined( 'ABSPATH' ) ) { * * @param int $user_id */ -function um_post_registration_approved_hook( $user_id ) { +function um_post_registration_approved_hook( $user_id, $args ) { um_fetch_user( $user_id ); - UM()->user()->approve(); + UM()->user()->approve( true, $args ); } -add_action( 'um_post_registration_approved_hook', 'um_post_registration_approved_hook' ); +add_action( 'um_post_registration_approved_hook', 'um_post_registration_approved_hook', 10, 2 ); /** * Account needs email validation. @@ -456,6 +456,9 @@ function um_submit_form_register( $args, $form_data ) { 'user_password' => $user_password, 'user_email' => trim( $user_email ), ); + if ( ! isset( $args['user_password'] ) ) { + $credentials['generated_pass'] = true; + } // @todo test when ready maybe remove if ( ! empty( $args['submitted'] ) ) { diff --git a/templates/email/welcome_email.php b/templates/email/welcome_email.php index b9807834..ac4ab960 100644 --- a/templates/email/welcome_email.php +++ b/templates/email/welcome_email.php @@ -23,7 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) {
Thank you for signing up!Your account is now active.
-
Login to our site
+
{login_button}
If you have any problems, please contact us at {admin_email}