Last active
October 29, 2023 18:47
-
-
Save yuriinalivaiko/577c57fa70e6c632078faff41263c7b2 to your computer and use it in GitHub Desktop.
This code overrides the "URL redirect after e-mail activation" setting. After activation the user will be redirected to the page used for registration. This may be helpful if the registration page is placed in a popup or sidebar.
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
<?php | |
// Save the page URL on registration. | |
add_action( 'um_registration_set_extra_data', 'um_registration_set_extra_data_custom', 10, 3 ); | |
function um_registration_set_extra_data_custom( $user_id, $args, $form_data ) { | |
if ( isset( $_SERVER['HTTP_REFERER'] ) ) { | |
$url = esc_url( wp_unslash( $_SERVER['HTTP_REFERER'] ) ); | |
update_user_meta( $user_id, 'um_registration_page_url', $url ); | |
} elseif ( isset( $_SERVER['REQUEST_URI'] ) ) { | |
$url = esc_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ); | |
update_user_meta( $user_id, 'um_registration_page_url', $url ); | |
} | |
} | |
// Redirect to the saved registration page URL after e-mail activation. | |
add_filter( 'um_after_email_confirmation_redirect', 'um_after_email_confirmation_redirect_custom', 10, 3 ); | |
function um_after_email_confirmation_redirect_custom( $redirect, $user_id, $login ) { | |
$url = get_user_meta( $user_id, 'um_registration_page_url', true ); | |
if ( ! empty( $url ) ) { | |
$redirect = add_query_arg( 'umuid', uniqid(), $url ); | |
} | |
return $redirect; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is a part of the article Redirect to the previous page after e-mail activation.
Documentation: https://docs.ultimatemember.com/
Support forum: https://wordpress.org/support/plugin/ultimate-member/