Last active
August 18, 2022 07:40
-
-
Save champsupertramp/51763fa171d35a839ff92d7c3ad8d7b4 to your computer and use it in GitHub Desktop.
Ultimate Member - Shortcode for Login URL with redirect in Global Access Message
This file contains hidden or 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
/** | |
* 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; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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,