| 1 |
<?php // User Submitted Posts - Custom Login & Register |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) die(); |
| 4 |
|
| 5 |
/* |
| 6 |
Function: display a form that lets users login, register, and reset their password |
| 7 |
Usage: <?php if (function_exists('usp_login_form')) usp_login_form(); ?> |
| 8 |
Ref: https://digwp.com/2010/12/login-register-password-code/ |
| 9 |
*/ |
| 10 |
if (!function_exists('usp_login_form')) : |
| 11 |
function usp_login_form() { |
| 12 |
|
| 13 |
$current_user = wp_get_current_user(); |
| 14 |
|
| 15 |
if (isset($current_user)) { |
| 16 |
$user = $current_user->user_login; |
| 17 |
$id = $current_user->ID; |
| 18 |
} |
| 19 |
|
| 20 |
$reset = false; |
| 21 |
$register = false; |
| 22 |
|
| 23 |
if (isset($_GET['reset'])) $reset = (bool) sanitize_text_field($_GET['reset']); |
| 24 |
if (isset($_GET['register'])) $register = (bool) sanitize_text_field($_GET['register']); |
| 25 |
|
| 26 |
$redirect_login = apply_filters('usp_login_redirect_login', esc_url(get_permalink())); |
| 27 |
$redirect_register = apply_filters('usp_login_redirect_register', esc_url(add_query_arg('register', 'true', get_permalink()))); |
| 28 |
$redirect_reset = apply_filters('usp_login_redirect_reset', esc_url(add_query_arg('reset', 'true', get_permalink()))); |
| 29 |
|
| 30 |
?> |
| 31 |
|
| 32 |
<style> |
| 33 |
<?php if (!get_option('users_can_register')) : ?>#usp-login li:nth-child(2) { display: none; }<?php endif; ?> |
| 34 |
|
| 35 |
.usp-login #tab2_login, .usp-login #tab3_login { display: none; } |
| 36 |
|
| 37 |
.usp-login { width: 370px; overflow: hidden; margin: 50px auto; padding: 10px; color: #333; font-size: 12px; line-height: 16px; text-shadow: 0 0 1px #fff; } |
| 38 |
.usp-login h1 { margin: 20px 0 10px 20px; font: 400 32px/32px sans-serif; -webkit-font-smoothing: antialiased; } |
| 39 |
.usp-login h3 { margin: 0; border: 0 none; font-size: 14px; line-height: 14px; } |
| 40 |
.usp-login p { margin: 10px 0; color: #333; } |
| 41 |
|
| 42 |
.usp-login .tabs_login { float: left; margin: 0; padding: 0; list-style-type: none; } |
| 43 |
.usp-login .tabs_login li { float: left; overflow: hidden; margin: 0 5px 0 0; padding: 0; } |
| 44 |
.usp-login .tabs_login li a { height: 30px; display: block; padding: 0 15px; line-height: 30px; text-decoration: none; border: none; color: #777; background: url(<?php echo plugins_url(); ?>/usp-pro/img/usp-login-bg-alt.png); } |
| 45 |
.usp-login .tabs_login li a:hover { color: #555; } |
| 46 |
.usp-login .tabs_login li.active_tab a { font-weight: bold; color: #333; background: url(<?php echo plugins_url(); ?>/user-submitted-posts/images/usp-login-bg.png); } |
| 47 |
|
| 48 |
.usp-login .tab_container { width: 100%; float: left; margin: 0 0 20px 0; background-color: #fff; border: none; } |
| 49 |
.usp-login .tab_content { padding: 20px; background: url(<?php echo plugins_url(); ?>/user-submitted-posts/images/usp-login-bg.png); } |
| 50 |
|
| 51 |
.usp-login .username, .usp-login .password, .usp-login .login_fields { width: 100%; overflow: hidden; margin: 7px 0 0 0; padding: 3px 0; } |
| 52 |
.usp-login .username label, .usp-login .password label { float: left; width: 120px; margin: 0; padding: 6px 0; color: #777; } |
| 53 |
.usp-login .username input, .usp-login .password input { float: left; width: 240px; margin: 0 0 0 3px; padding: 6px 8px; color: #777; font: 12px "Lucida Grande", "Lucida Sans Unicode", Verdana, sans-serif; } |
| 54 |
|
| 55 |
.usp-login .rememberme { margin: 0 0 15px 0; color: #777; font-size: 11px; } |
| 56 |
.usp-login .rememberme input { float: left; margin: 2px 7px 0 0; } |
| 57 |
.usp-login .user-submit { float: left; margin: 5px 0 0 0; } |
| 58 |
|
| 59 |
.usp-login .user-logged-in { width: 330px; overflow: hidden; padding: 20px; color: #333; background: url(<?php echo plugins_url(); ?>/user-submitted-posts/images/usp-login-bg.png); } |
| 60 |
|
| 61 |
.usp-login .user-icon { float: left; width: 80px; padding: 20px 0 0 0; } |
| 62 |
.usp-login .user-icon img { width: 60px; height: 60px; box-shadow: 1px 1px 3px 0 rgba(0,0,0,0.7); } |
| 63 |
.usp-login .user-info { float: left; width: 240px; padding: 20px 0 0 0; } |
| 64 |
.usp-login .user-info p:last-child { color: #777; } |
| 65 |
.usp-login .user-info a, .usp-login .user-info a:hover { text-decoration: none; } |
| 66 |
.usp-login .usp-sep { padding: 0 3px; } |
| 67 |
</style> |
| 68 |
|
| 69 |
<?php if (!is_user_logged_in()) : ?> |
| 70 |
|
| 71 |
<script> |
| 72 |
jQuery(document).ready(function($) { |
| 73 |
$('.tab_content').hide(); |
| 74 |
$('.tabs_login li:first').addClass('active_tab').show(); |
| 75 |
$('.tab_content:first').show(); |
| 76 |
$('ul.tabs_login li').click(function() { |
| 77 |
$('ul.tabs_login li').removeClass('active_tab'); |
| 78 |
$(this).addClass('active_tab'); |
| 79 |
$('.tab_content').hide(); |
| 80 |
var activeTab = $(this).find('a').attr('href'); |
| 81 |
$(activeTab).show(); |
| 82 |
return false; |
| 83 |
}); |
| 84 |
}); |
| 85 |
</script> |
| 86 |
<div id="usp-login" class="usp-login"> |
| 87 |
<ul class="tabs_login"> |
| 88 |
<li class="tabs_login_1 active_tab"><a href="#tab1_login"><?php esc_html_e('Login', 'usp'); ?></a></li> |
| 89 |
<li class="tabs_login_2"><a href="#tab2_login"><?php esc_html_e('Register', 'usp'); ?></a></li> |
| 90 |
<li class="tabs_login_3"><a href="#tab3_login"><?php esc_html_e('Forgot?', 'usp'); ?></a></li> |
| 91 |
</ul> |
| 92 |
<div class="tab_container"> |
| 93 |
<div id="tab1_login" class="tab1_login tab_content"> |
| 94 |
|
| 95 |
<?php if ($register) : ?> |
| 96 |
|
| 97 |
<h3><?php esc_html_e('Success!', 'usp'); ?></h3> |
| 98 |
<p><?php esc_html_e('Check your email for the password.', 'usp'); ?></p> |
| 99 |
|
| 100 |
<?php elseif ($reset) : ?> |
| 101 |
|
| 102 |
<h3><?php esc_html_e('Success!', 'usp'); ?></h3> |
| 103 |
<p><?php esc_html_e('Check your email to reset your password.', 'usp'); ?></p> |
| 104 |
|
| 105 |
<?php else : ?> |
| 106 |
|
| 107 |
<h3><?php esc_html_e('Have an account?', 'usp'); ?></h3> |
| 108 |
<p><?php esc_html_e('Log in or sign up! It’s fast & free!', 'usp'); ?></p> |
| 109 |
|
| 110 |
<?php endif; ?> |
| 111 |
|
| 112 |
<form method="post" action="<?php echo wp_login_url(); ?>"> |
| 113 |
<div class="username"> |
| 114 |
<label for="log"><?php esc_html_e('Username', 'usp'); ?>: </label> |
| 115 |
<input name="log" id="log" type="text" value=""> |
| 116 |
</div> |
| 117 |
<div class="password"> |
| 118 |
<label for="pwd"><?php esc_html_e('Password', 'usp'); ?>: </label> |
| 119 |
<input name="pwd" id="pwd" type="password" value="" autocomplete="off"> |
| 120 |
</div> |
| 121 |
<div class="login_fields"> |
| 122 |
<div class="rememberme"> |
| 123 |
<label for="rememberme"> |
| 124 |
<input name="rememberme" id="rememberme" type="checkbox" value="forever" checked="checked"> <?php esc_html_e('Remember me', 'usp'); ?> |
| 125 |
</label> |
| 126 |
</div> |
| 127 |
<input type="submit" name="user-submit" value="<?php esc_attr_e('Login', 'usp'); ?>" class="user-submit"> |
| 128 |
<input type="hidden" name="redirect_to" value="<?php echo $redirect_login; ?>"> |
| 129 |
<input type="hidden" name="user-cookie" value="1"> |
| 130 |
<?php do_action('login_form'); ?> |
| 131 |
</div> |
| 132 |
</form> |
| 133 |
</div> |
| 134 |
<div id="tab2_login" class="tab2_login tab_content"> |
| 135 |
<h3><?php esc_html_e('Register for this site!', 'usp'); ?></h3> |
| 136 |
<p><?php esc_html_e('Sign up now for the good stuff.', 'usp'); ?></p> |
| 137 |
<form method="post" action="<?php echo wp_registration_url(); ?>"> |
| 138 |
<div class="username"> |
| 139 |
<label for="user_login_register"><?php esc_html_e('Username', 'usp'); ?>: </label> |
| 140 |
<input name="user_login" id="user_login_register" type="text" value=""> |
| 141 |
</div> |
| 142 |
<div class="password"> |
| 143 |
<label for="user_email"><?php esc_html_e('Your Email', 'usp'); ?>: </label> |
| 144 |
<input name="user_email" id="user_email" type="text" value=""> |
| 145 |
</div> |
| 146 |
<div class="login_fields"> |
| 147 |
<input type="submit" name="user-submit" value="<?php esc_attr_e('Sign up!', 'usp'); ?>" class="user-submit"> |
| 148 |
<input type="hidden" name="redirect_to" value="<?php echo $redirect_register; ?>"> |
| 149 |
<input type="hidden" name="user-cookie" value="1"> |
| 150 |
<?php do_action('register_form'); ?> |
| 151 |
</div> |
| 152 |
</form> |
| 153 |
</div> |
| 154 |
<div id="tab3_login" class="tab3_login tab_content"> |
| 155 |
<h3><?php esc_html_e('Lose something?', 'usp'); ?></h3> |
| 156 |
<p><?php esc_html_e('Enter your username or email to reset your password.', 'usp'); ?></p> |
| 157 |
<form method="post" action="<?php echo wp_lostpassword_url(); ?>"> |
| 158 |
<div class="username"> |
| 159 |
<label for="user_login_password"><?php esc_html_e('Username or Email', 'usp'); ?>: </label> |
| 160 |
<input name="user_login" id="user_login_password" type="text" value=""> |
| 161 |
</div> |
| 162 |
<div class="login_fields"> |
| 163 |
<input type="submit" name="user-submit" value="<?php esc_attr_e('Reset my password', 'usp'); ?>" class="user-submit"> |
| 164 |
<input type="hidden" name="redirect_to" value="<?php echo $redirect_reset; ?>"> |
| 165 |
<input type="hidden" name="user-cookie" value="1"> |
| 166 |
<?php do_action('login_form', 'resetpass'); ?> |
| 167 |
</div> |
| 168 |
</form> |
| 169 |
</div> |
| 170 |
</div> |
| 171 |
</div> |
| 172 |
|
| 173 |
<?php else : ?> |
| 174 |
|
| 175 |
<div id="usp-login" class="usp-login"> |
| 176 |
<div class="user-logged-in"> |
| 177 |
<h3><?php esc_html_e('Welcome, ', 'usp'); echo $user; ?></h3> |
| 178 |
<div class="user-icon"><?php echo get_avatar($id, 60); ?></div> |
| 179 |
<div class="user-info"> |
| 180 |
<p><?php esc_html_e('Congratulations, you’re logged in.', 'usp'); ?></p> |
| 181 |
<p> |
| 182 |
<a href="<?php echo wp_logout_url(get_permalink()); ?>"><?php esc_html_e('Log out', 'usp'); ?></a><span class="usp-sep"> | </span> |
| 183 |
<?php if (current_user_can('manage_options')) echo '<a href="'. admin_url() .'">'. esc_html__('Admin', 'usp') .'</a>'; |
| 184 |
else echo '<a href="'. admin_url() .'profile.php">'. esc_html__('Profile', 'usp') .'</a>'; ?> |
| 185 |
</p> |
| 186 |
</div> |
| 187 |
</div> |
| 188 |
</div> |
| 189 |
|
| 190 |
<?php endif; ?> |
| 191 |
|
| 192 |
<?php } |
| 193 |
endif; |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
/* |
| 198 |
Shortcode: displays a form that lets users login, register, and reset their password |
| 199 |
Usage: [usp-login-form] |
| 200 |
*/ |
| 201 |
if (!function_exists('usp_login_form_shortcode')) : |
| 202 |
function usp_login_form_shortcode($attr, $content = null) { |
| 203 |
ob_start(); |
| 204 |
usp_login_form(); |
| 205 |
$form = ob_get_contents(); |
| 206 |
ob_end_clean(); |
| 207 |
return $form; |
| 208 |
} |
| 209 |
add_shortcode('usp-login-form', 'usp_login_form_shortcode'); |
| 210 |
endif; |
| 211 |
|