- Fixed: Activate an account via email

This commit is contained in:
nikitasinelnikov
2020-09-01 23:34:17 +03:00
parent cf071563d3
commit 3f920d7ab6
2 changed files with 25 additions and 20 deletions
+16 -12
View File
@@ -182,20 +182,22 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
$user_id = absint( $_REQUEST['user_id'] );
delete_option( "um_cache_userdata_{$user_id}" );
um_fetch_user( $user_id );
if ( strtolower( $_REQUEST['hash'] ) !== strtolower( um_user( 'account_secret_hash' ) ) ) {
$account_secret_hash = get_user_meta( $user_id, 'account_secret_hash', true );
if ( empty( $account_secret_hash ) || strtolower( $_REQUEST['hash'] ) !== strtolower( $account_secret_hash ) ) {
wp_die( __( 'This activation link is expired or have already been used.', 'ultimate-member' ) );
}
um_fetch_user( $user_id );
UM()->user()->approve();
$redirect = ( um_user( 'url_email_activate' ) ) ? um_user( 'url_email_activate' ) : um_get_core_page( 'login', 'account_active' );
$login = (bool) um_user( 'login_email_activate' );
um_reset_user();
$user_role = UM()->roles()->get_priority_user_role( $user_id );
$user_role_data = UM()->roles()->role_data( $user_role );
// log in automatically
$login = ! empty( $user_role_data['login_email_activate'] ); // Role setting "Login user after validating the activation link?"
if ( ! is_user_logged_in() && $login ) {
$user = get_userdata( $user_id );
$user_id = $user->ID;
// update wp user
wp_set_current_user( $user_id, $user->user_login );
@@ -206,7 +208,6 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
ob_end_clean();
}
um_reset_user();
/**
* UM hook
*
@@ -228,6 +229,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"
$redirect = apply_filters( 'um_after_email_confirmation_redirect', $redirect, $user_id, $login );
exit( wp_redirect( $redirect ) );
}
@@ -238,10 +242,10 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
/**
* Makes an activate link for any user
*
* @return bool|mixed|string|void
* @return bool|string
*/
function activate_url() {
if ( !um_user('account_secret_hash') ) {
if ( ! um_user( 'account_secret_hash' ) ) {
return false;
}
@@ -268,8 +272,8 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
*/
$url = apply_filters( 'um_activate_url', home_url() );
$url = add_query_arg( 'act', 'activate_via_email', $url );
$url = add_query_arg( 'hash', um_user('account_secret_hash'), $url );
$url = add_query_arg( 'user_id', um_user('ID'), $url );
$url = add_query_arg( 'hash', um_user( 'account_secret_hash' ), $url );
$url = add_query_arg( 'user_id', um_user( 'ID' ), $url );
return $url;
}
@@ -375,7 +379,7 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
*/
$profile_url = apply_filters( 'um_localize_permalink_filter', $profile_url, $page_id );
if ( get_option('permalink_structure') ) {
if ( get_option( 'permalink_structure' ) ) {
$profile_url = trailingslashit( untrailingslashit( $profile_url ) );
$profile_url = $profile_url . strtolower( $slug ). '/';