Skip to content

Instantly share code, notes, and snippets.

@jmarreros
Last active April 12, 2021 17:29
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 jmarreros/90cd2c52ee53b95909793c2a86feb95b to your computer and use it in GitHub Desktop.
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]
<?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