Last active
April 12, 2021 17:29
-
-
Save jmarreros/90cd2c52ee53b95909793c2a86feb95b to your computer and use it in GitHub Desktop.
Formulario simple de login a través de código en WordPress, usando el shortcode [dcms_form_login]
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 // No copiar esta línea | |
function dcms_form_login_config() { | |
$redirect_login = get_home_url(); | |
$redirect_logout = get_home_url(); | |
if ( ! is_user_logged_in() ): | |
$args = array( | |
'echo' => false, | |
'redirect' => $redirect_login, | |
); | |
return wp_login_form( $args ); | |
else: | |
$current_user = wp_get_current_user(); | |
$url_logout = wp_logout_url( $redirect_logout ); | |
$str = get_avatar($current_user->user_email, 24).' '; | |
$str .= 'Hola '.$current_user->display_name.'<br>'; | |
$str .= '<a href="' . $url_logout . '">Desconectarse</a>'; | |
return $str; | |
endif; | |
} | |
function dcms_add_shortcode_login(){ | |
add_shortcode( 'dcms_form_login', 'dcms_form_login_config' ); | |
} | |
add_action( 'init', 'dcms_add_shortcode_login' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment