Created
February 4, 2018 01:24
-
-
Save RadGH/5fc2c8c58a5ddc5d235b83bce25c06d8 to your computer and use it in GitHub Desktop.
WordPress: Shortcode to log in or log out of WordPress using nonces
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
<?php | |
// THIS WILL NOT WORK IN CUSTOM MENU LINKS. | |
// Fix that with this filter: | |
// https://gist.github.com/RadGH/88648b181e201b18c7b82fc3cf58ca3b | |
// Use the [rs_login_logout], [rs_logout] or [rs_login] shortcodes to create the appropriate link. | |
// If you are logged in you will always get a logout link, and vice versa. | |
// You can use the "redirect" attribute to specify where to go after logging in. | |
function rs_avada_logout_link_shortcode( $atts, $content = '' ) { | |
$redirect = isset($atts['redirect']) ? do_shortcode($atts['redirect']) : get_permalink(); | |
if ( is_user_logged_in() ) { | |
$link = wp_logout_url( $redirect ); | |
}else{ | |
$link = wp_login_url( $redirect ); | |
} | |
return $link; | |
} | |
add_shortcode( 'rs_login_logout', 'rs_avada_logout_link_shortcode' ); | |
add_shortcode( 'rs_login', 'rs_avada_logout_link_shortcode' ); | |
add_shortcode( 'rs_logout', 'rs_avada_logout_link_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment