Last active
November 24, 2022 11:47
-
-
Save denisbaranov/4078397f0e725f75ccc83d19d6672412 to your computer and use it in GitHub Desktop.
The way to use both Email verification and Admin review in Ultimate Member. This custom code works if the user role setting "Registration Status" is "Require Email Activation". This code snippet removes the default function, which handles email confirmation, and adds a new instead. Add this code to the end of the functions.php file in the active…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Set status 'awaiting_admin_review' after the Email verification | |
*/ | |
function my_activate_account_via_email_link() { | |
if ( isset( $_REQUEST['act'] ) && $_REQUEST['act'] == 'activate_via_email' && isset( $_REQUEST['hash'] ) && is_string( $_REQUEST['hash'] ) && strlen( $_REQUEST['hash'] ) == 40 && | |
isset( $_REQUEST['user_id'] ) && is_numeric( $_REQUEST['user_id'] ) ) { // valid token | |
$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' ) ) ) { | |
wp_die( __( 'This activation link is expired or have already been used.', 'ultimate-member' ) ); | |
} | |
UM()->user()->pending(); // UM()->user()->approve(); | |
$redirect = ( um_user( 'url_email_activate' ) ) ? um_user( 'url_email_activate' ) : um_get_core_page( 'login', 'pending_message' ); | |
um_reset_user(); | |
do_action( 'um_after_email_confirmation', $user_id ); | |
exit( wp_redirect( $redirect ) ); | |
} | |
} | |
add_action( 'init', 'my_activate_account_via_email_link', 1 ); | |
/** | |
* Disable default handler 'activate_account_via_email_link' | |
*/ | |
function my_disable_activate_account_via_email_link() { | |
remove_action( 'init', array( UM()->permalinks(), 'activate_account_via_email_link' ), 1 ); | |
} | |
add_action( 'after_setup_theme', 'my_disable_activate_account_via_email_link' ); | |
/** | |
* Add a message | |
* @param string $success | |
* @param string $updated | |
* @return string | |
*/ | |
function my_um_custom_pending_message( $success, $updated ) { | |
if ( 'pending_message' === $updated ) { | |
$success = __( 'Thank you for applying for membership to our site. We will review your details and send you an email letting you know whether your account has been approved or not.', 'ultimate-member' ); | |
} | |
return $success; | |
} | |
add_filter( 'um_custom_success_message_handler', 'my_um_custom_pending_message', 10, 2 ); |
Author
denisbaranov
commented
Mar 12, 2020
Thank you, it works perfectly. Is there a possibility to show somewhere in the plugin or via a tick next to the name that the email has been verified correctly?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment