diff --git a/includes/class-config.php b/includes/class-config.php index 2b570c3b..27e2f6e6 100644 --- a/includes/class-config.php +++ b/includes/class-config.php @@ -334,8 +334,8 @@ if ( ! class_exists( 'um\Config' ) ) { 'subject' => 'Welcome to {site_name}!', 'body' => 'Hi {display_name},

' . 'Thank you for signing up with {site_name}! Your account is now active.

' . - 'To login please visit the following url:

' . - '{login_url}

' . + '{action_title}:

' . + '{action_url}

' . 'Your account e-mail: {email}
' . 'Your account username: {username}

' . 'If you have any problems, please contact us at {admin_email}

' . diff --git a/includes/core/class-mail.php b/includes/core/class-mail.php index add641e5..a056888e 100644 --- a/includes/core/class-mail.php +++ b/includes/core/class-mail.php @@ -623,6 +623,8 @@ if ( ! class_exists( 'um\core\Mail' ) ) { $placeholders[] = '{login_url}'; $placeholders[] = '{password}'; $placeholders[] = '{account_activation_link}'; + $placeholders[] = '{action_url}'; + $placeholders[] = '{action_title}'; return $placeholders; } @@ -641,6 +643,16 @@ if ( ! class_exists( 'um\core\Mail' ) ) { $replace_placeholders[] = um_get_core_page( 'login' ); $replace_placeholders[] = esc_html__( 'Your set password', 'ultimate-member' ); $replace_placeholders[] = um_user( 'account_activation_link' ); + + $set_password_required = get_user_meta( um_user( 'ID' ), 'um_set_password_required', true ); + if ( empty( $set_password_required ) || 'pending' === um_user( 'status' ) ) { + $replace_placeholders[] = um_get_core_page( 'login' ); + $replace_placeholders[] = esc_html__( 'Login to our site', 'ultimate-member' ); + } else { + $replace_placeholders[] = um_user( 'password_reset_link' ); + $replace_placeholders[] = esc_html__( 'Set your password', 'ultimate-member' ); + } + return $replace_placeholders; } } diff --git a/includes/core/class-password.php b/includes/core/class-password.php index a5e1c882..77f4c5cb 100644 --- a/includes/core/class-password.php +++ b/includes/core/class-password.php @@ -155,6 +155,7 @@ if ( ! class_exists( 'um\core\Password' ) ) { if ( false !== $this->change_password ) { // then COOKIE are valid then get data from them and populate hidden fields for the password reset form + $args['rp_mode'] = 'pw_change'; $args['template'] = 'password-change'; $args['rp_key'] = ''; $rp_cookie = 'wp-resetpass-' . COOKIEHASH; @@ -163,6 +164,14 @@ if ( ! class_exists( 'um\core\Password' ) ) { $args['login'] = $rp_login; $args['rp_key'] = $rp_key; + + $rp_user_obj = get_user_by( 'login', $rp_login ); + if ( false !== $rp_user_obj ) { + $set_password_required = get_user_meta( $rp_user_obj->ID, 'um_set_password_required', true ); + if ( ! empty( $set_password_required ) ) { + $args['rp_mode'] = 'pw_set'; + } + } } } @@ -599,6 +608,11 @@ if ( ! class_exists( 'um\core\Password' ) ) { } $this->setcookie( $rp_cookie, false ); + $set_password_required = get_user_meta( $user->ID, 'um_set_password_required', true ); + if ( ! empty( $set_password_required ) ) { + delete_user_meta( $user->ID, 'um_set_password_required' ); + } + /** * UM hook * diff --git a/includes/core/class-permalinks.php b/includes/core/class-permalinks.php index 48779ce8..5d66a799 100644 --- a/includes/core/class-permalinks.php +++ b/includes/core/class-permalinks.php @@ -125,8 +125,14 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) { wp_die( __( 'This activation link is expired.', 'ultimate-member' ) ); } + $redirect = um_get_core_page( 'login', 'account_active' ); + $set_password_required = get_user_meta( $user_id, 'um_set_password_required', true ); + um_fetch_user( $user_id ); UM()->user()->approve(); + if ( ! empty( $set_password_required ) ) { + $redirect = um_user( 'password_reset_link' ); + } um_reset_user(); $user_role = UM()->roles()->get_priority_user_role( $user_id ); @@ -167,7 +173,9 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) { */ do_action( 'um_after_email_confirmation', $user_id ); - $redirect = empty( $user_role_data['url_email_activate'] ) ? um_get_core_page( 'login', 'account_active' ) : trim( $user_role_data['url_email_activate'] ); // Role setting "URL redirect after e-mail activation" + if ( empty( $set_password_required ) ) { + $redirect = empty( $user_role_data['url_email_activate'] ) ? um_get_core_page( 'login', 'account_active' ) : trim( $user_role_data['url_email_activate'] ); // Role setting "URL redirect after e-mail activation" + } $redirect = apply_filters( 'um_after_email_confirmation_redirect', $redirect, $user_id, $login ); exit( wp_redirect( $redirect ) ); diff --git a/includes/core/class-user.php b/includes/core/class-user.php index d4725da2..9a96da1f 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 ) { + public function approve( $repeat = true ) { $user_id = um_user( 'ID' ); if ( ! $repeat ) { @@ -1702,7 +1702,7 @@ if ( ! class_exists( 'um\core\User' ) ) { delete_option( "um_cache_userdata_{$user_id}" ); - if ( um_user( 'account_status' ) == 'awaiting_admin_review' ) { + if ( 'awaiting_admin_review' === um_user( 'account_status' ) ) { $userdata = get_userdata( $user_id ); $this->maybe_generate_password_reset_key( $userdata ); diff --git a/includes/core/um-actions-core.php b/includes/core/um-actions-core.php index 9c195a81..8779fafc 100644 --- a/includes/core/um-actions-core.php +++ b/includes/core/um-actions-core.php @@ -100,10 +100,11 @@ function um_action_request_process() { wp_die( esc_html__( 'You do not have permission to make this action.', 'ultimate-member' ) ); } + um_fetch_user( $uid ); + add_filter( 'um_template_tags_patterns_hook', array( UM()->password(), 'add_placeholder' ), 10, 1 ); add_filter( 'um_template_tags_replaces_hook', array( UM()->password(), 'add_replace_placeholder' ), 10, 1 ); - um_fetch_user( $uid ); UM()->user()->approve(); exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) ); break; diff --git a/includes/core/um-actions-register.php b/includes/core/um-actions-register.php index 5f8a8404..5d4bf6ac 100644 --- a/includes/core/um-actions-register.php +++ b/includes/core/um-actions-register.php @@ -417,8 +417,10 @@ function um_submit_form_register( $args, $form_data ) { $user_email = $args['user_email']; } + $generate_password = false; if ( ! isset( $args['user_password'] ) ) { - $user_password = UM()->validation()->generate( 8 ); + $generate_password = true; + $user_password = UM()->validation()->generate( 8 ); } else { $user_password = $args['user_password']; } @@ -520,6 +522,10 @@ function um_submit_form_register( $args, $form_data ) { return; } + if ( true === $generate_password ) { + update_user_meta( $user_id, 'um_set_password_required', true ); + } + /** * Fires after complete UM user registration. * diff --git a/templates/email/welcome_email.php b/templates/email/welcome_email.php index b9807834..b81eb789 100644 --- a/templates/email/welcome_email.php +++ b/templates/email/welcome_email.php @@ -5,7 +5,7 @@ * * This template can be overridden by copying it to {your-theme}/ultimate-member/email/welcome_email.php * - * @version 2.6.1 + * @version 2.8.3 */ if ( ! defined( 'ABSPATH' ) ) { exit; @@ -21,9 +21,9 @@ if ( ! defined( 'ABSPATH' ) ) {
-
Thank you for signing up!Your account is now active.
+
Thank you for signing up! Your account is now active.
-
Login to our site
+
{action_title}
If you have any problems, please contact us at {admin_email}
diff --git a/templates/password-change.php b/templates/password-change.php index 46bf34a6..6ad5b9c1 100644 --- a/templates/password-change.php +++ b/templates/password-change.php @@ -6,19 +6,18 @@ * * Call: function ultimatemember_password() * - * @version 2.7.0 + * @version 2.8.3 * - * @var string $mode - * @var string $rp_key - * @var int $form_id - * @var array $args + * @var string $rp_mode 'pw_set' or 'pw_change' for display it differently. + * @var string $rp_key Reset password key. + * @var array $args Change password arguments */ if ( ! defined( 'ABSPATH' ) ) { exit; } ?> -
+
@@ -29,23 +28,18 @@ if ( ! defined( 'ABSPATH' ) ) { Add hidden field at the start of the change password form. + * function my_custom_change_password_page_hidden_fields( $cp_args ) { + * echo '' * } - * ?> + * add_action( 'um_change_password_page_hidden_fields', 'my_custom_change_password_page_hidden_fields' ); */ do_action( 'um_change_password_page_hidden_fields', $args ); @@ -57,38 +51,37 @@ if ( ! defined( 'ABSPATH' ) ) { foreach ( $fields as $key => $data ) { $output .= UM()->fields()->edit_field( $key, $data ); } - echo $output; ?> + if ( $output ) { + echo wp_kses( $output, UM()->get_allowed_html( 'templates' ) ); + } + ?>
-
- + + + + +
-
Add hidden field at the start of the change password form. + * function my_custom_change_password_form( $cp_args ) { + * echo '' * } - * ?> + * add_action( 'um_change_password_form', 'my_custom_change_password_form' ); */ do_action( 'um_change_password_form', $args ); /** This action is documented in includes/core/um-actions-profile.php */