-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
164 lines (140 loc) · 4.9 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
// Login Link Shortcode
function aione_login_link_shortcode( $atts ) {
// Attributes
extract( shortcode_atts(
array(
'class' => '',
'text' => 'Login'
), $atts )
);
$output = "";
if ( !is_user_logged_in() ) {
$output .= '<div id="login_link" class="user-links login-link '.$class.'">';
$output .= '<a href="'.wp_login_url().'" title="' . $text . '">' . $text . '</a>';
$output .= '</div>';
}
return $output;
}
add_shortcode( 'aione-login-link', 'aione_login_link_shortcode' );
// Register Link Shortcode
function aione_register_link_shortcode( $atts ) {
// Attributes
extract( shortcode_atts(
array(
'class' => '',
'text' => 'Sign up'
), $atts )
);
$output = "";
if ( !is_user_logged_in() ) {
$output .= '<div id="login_link" class="user-links login-link '.$class.'">';
$output .= '<a href="'.wp_registration_url().'" title="' . $text . '">' . $text . '</a>';
$output .= '</div>';
}
return $output;
}
add_shortcode( 'aione-register-link', 'aione_register_link_shortcode' );
// Logout Link Shortcode
function aione_logout_link_shortcode( $atts ) {
// Attributes
extract( shortcode_atts(
array(
'class' => '',
'text' => 'Logout'
), $atts )
);
$output = "";
if ( is_user_logged_in() ) {
$output .= '<div id="logout_link" class="user-links logout-link '.$class.'">';
$output .= '<a href="'.wp_logout_url().'" title="' . $text . '">' . $text . '</a>';
$output .= '</div>';
}
return $output;
}
add_shortcode( 'aione-logout-link', 'aione_logout_link_shortcode' );
// Logout Link Shortcode
function aione_user_welcome_shortcode( $atts ) {
// Attributes
extract( shortcode_atts(
array(
'class' => '',
'text' => 'Welcome'
), $atts )
);
$output = "";
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
if( $current_user->display_name != ""){
$user_welcome = $current_user->display_name;
} elseif($current_user->user_firstname != '' && $current_user->user_lastname != ''){
$user_welcome = $current_user->user_firstname . ' ' . $current_user->user_lastname;
} else {
$user_welcome = $current_user->user_login;
}
$output .= '<div id="user_welcome" class="user-links user-welcome '.$class.'">';
$output .= $text . ' <a href="' . get_edit_user_link( $current_user->ID ) . '" title="' . $text . ' ' . $user_welcome . '">' . $user_welcome . '</a>';
$output .= '</div>';
}
return $output;
}
add_shortcode( 'aione-user-welcome', 'aione_user_welcome_shortcode' );
// Logout Link Shortcode
function aione_login_form_shortcode( $attr, $content = null ) {
// Attributes
extract( shortcode_atts(
array(
'echo' => false,
'redirect' => get_option('admin_login_redirect_page'),
'form_id' => 'loginform',
'label_username' => __( 'Username' ),
'label_password' => __( 'Password' ),
'label_remember' => __( 'Remember Me' ),
'label_log_in' => __( 'Login' ),
'id_username' => 'user_login',
'id_password' => 'user_pass',
'id_remember' => 'rememberme',
'id_submit' => 'wp-submit',
), $atts )
);
$output = "";
$login = $_GET['login'];
$errors = array();
if(isset($login) && $login == 'failed' ){
$errors[] = 'Invalid username or password';
$output .= aione_show_errors($errors);
}
//print_r($_POST);
//print_r($_GET);
$args = array(
'echo' => $echo,
'redirect' => $redirect,
'form_id' => $form_id,
'label_username' => $label_username,
'label_password' => $label_password,
'label_remember' => $label_remember,
'label_log_in' => $label_log_in,
'id_username' => $id_username,
'id_password' => $id_password,
'id_remember' => $id_remember,
'id_submit' => $id_submit,
'remember' => empty( $instance['remember'] ) ? true : false,
'value_username' => esc_attr( $instance['value_username'] ),
'value_remember' => !empty( $instance['value_remember'] ) ? true : false,
);
$output .= wp_login_form( $args );
return $output;
}
add_shortcode( 'aione-login-form', 'aione_login_form_shortcode' );
//
add_action( 'wp_login_failed', 'aione_login_fail_redirect' ); // hook failed login
function aione_login_fail_redirect( $username ) {
$referrer = $_SERVER['HTTP_REFERER']; // where did the post submission come from?
//$post = serialize($_POST);
// if there's a valid referrer, and it's not the default log-in screen
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
wp_redirect( $referrer . '?login=failed' ); // let's append some information (login=failed) to the URL for the theme to use
exit;
}
}
?>