Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ultimate Member - Shortcode for Login URL with redirect in Global Access Message
/**
* Add a shortcode to display the Login URL with redirection URL
* e.g. http://www.yoursite.com/login/?redirect_to=http://www.yoursite.com/content-restriction/
* www.champ.ninja
*/
add_shortcode("um_login_redirect","um_login_redirect",10, 2 );
function um_login_redirect( $atts, $content ){
global $wp;
$current_url = home_url(add_query_arg(array(), $wp->request));
$login_url = um_get_core_page("login");
$login_url = add_query_arg("redirect_to", $current_url, $login_url );
$html = '<a href="'.$login_url.'">'.$content.'</a>';
return $html;
}
add_filter("um_get_option_filter__restricted_access_message",function( $value ){
if( is_admin() ) return $value;
if ( version_compare( get_bloginfo('version'),'5.4', '<' ) ) {
return do_shortcode( $value );
} else {
return apply_shortcodes( $value );
}
return $value;
});
@champsupertramp

This comment has been minimized.

Copy link
Owner Author

@champsupertramp champsupertramp commented Dec 15, 2020

You can now add a shortcode in the Global Access Message:
WP Admin > Ultimate Member > Settings > Access > Restriction Content > Restricted Access Message.

Shortcode: [um_login_redirect]Click here to Login[/um_login_redirect]

The above shortcode will render the following:
e.g. <a href="https://yoursite.com/redirect_to=http://www.yoursite.com/content-restriction/">Click here to Login</a>

The generated URL pattern would look like this:
http://www.yoursite.com/login/?redirect_to=http://www.yoursite.com/content-restriction/

Regards,

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