Skip to content

Instantly share code, notes, and snippets.

@yuriinalivaiko
Last active October 29, 2023 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuriinalivaiko/577c57fa70e6c632078faff41263c7b2 to your computer and use it in GitHub Desktop.
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.
<?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;
}
@yuriinalivaiko
Copy link
Author

yuriinalivaiko commented Oct 29, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment