Last active
March 31, 2019 01:39
-
-
Save carlodaniele/a144c329e4a55d32e2f9 to your computer and use it in GitHub Desktop.
This plugin allows to include a login form into the site front end with a shortcode
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 | |
/** | |
* Setup | |
*/ | |
function frontend_user_manager_init() { | |
add_shortcode( 'frontend-login-form', 'frontend_login_form' ); | |
} | |
add_action('init', 'frontend_user_manager_init'); | |
/** | |
* Print a login form or current user login | |
* | |
* @param array $atts An array of arguments | |
* @return string The form mark-up or the current user login | |
*/ | |
function frontend_login_form( $atts ){ | |
if( ! is_user_logged_in() ){ | |
$args = array( | |
'echo' => false, | |
'remember' => true, | |
'redirect' => get_permalink(), | |
'form_id' => 'loginform', | |
'id_username' => 'user_login', | |
'id_password' => 'user_pass', | |
'id_remember' => 'rememberme', | |
'id_submit' => 'wp-submit', | |
'label_username' => __( 'Username' ), | |
'label_password' => __( 'Password' ), | |
'label_remember' => __( 'Remember Me' ), | |
'label_log_in' => __( 'Log In' ), | |
'value_username' => '', | |
'value_remember' => false | |
); | |
$output = wp_login_form( $args ); | |
}else{ | |
$current_user = wp_get_current_user(); | |
$output = '<p>' . sprintf( __( 'Howdy %s' ), $current_user->user_login ) . '</p>'; | |
$output .= '<p>' . wp_loginout( get_permalink(), false ) . '</p>'; | |
} | |
return $output; | |
} | |
// Process shortcodes in text widgets | |
add_filter('widget_text', 'do_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment