I need to add a check to a function in Ultimate Member:
function um_submit_form_login( $args )
You can find this function in this file here:
https://github.com/ultimatemember/ultimatemember/blob/master/includes/core/um-actions-login.php#L202
In this function I need to add following check around the do_action:
$current_user_id = get_current_user_id();
$encrypted_secret = get_user_meta( $current_user_id, 'encrypted_secret', true );
$verify_login_url = get_permalink( 1345 );
//If user has two way auth enabled redirect to verify auth page and skip login for now
if ( $encrypted_secret && ! empty( $encrypted_secret ) ) {
wp_redirect( $verify_login_url );
exit;
} else {
do_action( 'um_user_login', $args ); //Do normal login if no two way auth enabled
}
So I did this in my functions.php:
add_filter( 'um_submit_form_login', 'two_way_auth_redirect', 10, 1 );
function two_way_auth_redirect( $args ) {
$current_user_id = get_current_user_id();
$encrypted_secret = get_user_meta( $current_user_id, 'encrypted_secret', true );
$verify_login_url = get_permalink( 1345 );
//If user has two way auth enabled redirect to verify auth page and skip login for now
if ( $encrypted_secret && ! empty( $encrypted_secret ) ) {
wp_redirect( $verify_login_url );
exit;
} else {
do_action( 'um_user_login', $args ); //Do normal login if no two way auth enabled
}
}
But when I try it out it don't works. How can I implement this the correct way?
It's not 100% clear from your question since your link points to um_user_login
function code, but looks like you want to extend um_submit_form_login
function with your logic before it fires.
If you need to add your hook before default action 'um_submit_form_login', 'um_submit_form_login', 10 is called. Ie
add_action( 'um_submit_form_login', 'my_um_submit_form_login', 1 );
function my_um_submit_form_login( $args ) {
if ( /* your_special_redirect_required */ ) {
wp_redirect( $verify_login_url );
exit;
}
// if nothing special required - execution will continue and default
// UM code called
}
But may be you want to change um_user_login
functionality (to hook before login form posted), in that case you can do it similarly. ie via add_action( 'um_user_login', 'my_um_user_login', 1 );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.