Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save denisbaranov/4078397f0e725f75ccc83d19d6672412 to your computer and use it in GitHub Desktop.
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…
/**
* 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 );
@denisbaranov
Copy link
Author

UM User Roles, Edit Role + Registration Options (Email)

@tax1112
Copy link

tax1112 commented Nov 24, 2022

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