author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress User Page |
|
4 |
* |
|
5 |
* Handles authentication, registering, resetting passwords, forgot password, |
|
6 |
* and other user handling. |
|
7 |
* |
|
8 |
* @package WordPress |
|
9 |
*/ |
|
10 |
||
11 |
/** Make sure that the WordPress bootstrap has run before continuing. */ |
|
12 |
require( dirname(__FILE__) . '/wp-load.php' ); |
|
13 |
||
14 |
// Redirect to https login if forced to use SSL |
|
15 |
if ( force_ssl_admin() && ! is_ssl() ) { |
|
16 |
if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
wp_safe_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) ); |
0 | 18 |
exit(); |
19 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
wp_safe_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
0 | 21 |
exit(); |
22 |
} |
|
23 |
} |
|
24 |
||
25 |
/** |
|
26 |
* Output the login page header. |
|
27 |
* |
|
5 | 28 |
* @param string $title Optional. WordPress login Page title to display in the `<title>` element. |
29 |
* Default 'Log In'. |
|
30 |
* @param string $message Optional. Message to display in header. Default empty. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
* @param WP_Error $wp_error Optional. The error to pass. Default is a WP_Error instance. |
0 | 32 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
function login_header( $title = 'Log In', $message = '', $wp_error = null ) { |
5 | 34 |
global $error, $interim_login, $action; |
0 | 35 |
|
36 |
// Don't index any of these forms |
|
37 |
add_action( 'login_head', 'wp_no_robots' ); |
|
38 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
add_action( 'login_head', 'wp_login_viewport_meta' ); |
0 | 40 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
if ( ! is_wp_error( $wp_error ) ) { |
0 | 42 |
$wp_error = new WP_Error(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
} |
0 | 44 |
|
45 |
// Shake it! |
|
46 |
$shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password' ); |
|
47 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
* Filters the error codes array for shaking the login form. |
0 | 49 |
* |
50 |
* @since 3.0.0 |
|
51 |
* |
|
52 |
* @param array $shake_error_codes Error codes that shake the login form. |
|
53 |
*/ |
|
54 |
$shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes ); |
|
55 |
||
56 |
if ( $shake_error_codes && $wp_error->get_error_code() && in_array( $wp_error->get_error_code(), $shake_error_codes ) ) |
|
57 |
add_action( 'login_head', 'wp_shake_js', 12 ); |
|
58 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
$login_title = get_bloginfo( 'name', 'display' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
/* translators: Login screen title. 1: Login screen name, 2: Network or site name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
$login_title = sprintf( __( '%1$s ‹ %2$s — WordPress' ), $title, $login_title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
* Filters the title tag content for login page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
* @param string $login_title The page title, with extra context added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
* @param string $title The original page title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
$login_title = apply_filters( 'login_title', $login_title, $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
|
0 | 74 |
?><!DOCTYPE html> |
5 | 75 |
<!--[if IE 8]> |
76 |
<html xmlns="http://www.w3.org/1999/xhtml" class="ie8" <?php language_attributes(); ?>> |
|
77 |
<![endif]--> |
|
78 |
<!--[if !(IE 8) ]><!--> |
|
79 |
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> |
|
80 |
<!--<![endif]--> |
|
0 | 81 |
<head> |
82 |
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
<title><?php echo $login_title; ?></title> |
0 | 84 |
<?php |
85 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
wp_enqueue_style( 'login' ); |
0 | 87 |
|
5 | 88 |
/* |
89 |
* Remove all stored post data on logging out. |
|
90 |
* This could be added by add_action('login_head'...) like wp_shake_js(), |
|
91 |
* but maybe better if it's not removable by plugins |
|
92 |
*/ |
|
0 | 93 |
if ( 'loggedout' == $wp_error->get_error_code() ) { |
94 |
?> |
|
95 |
<script>if("sessionStorage" in window){try{for(var key in sessionStorage){if(key.indexOf("wp-autosave-")!=-1){sessionStorage.removeItem(key)}}}catch(e){}};</script> |
|
96 |
<?php |
|
97 |
} |
|
98 |
||
99 |
/** |
|
100 |
* Enqueue scripts and styles for the login page. |
|
101 |
* |
|
102 |
* @since 3.1.0 |
|
103 |
*/ |
|
104 |
do_action( 'login_enqueue_scripts' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
|
0 | 106 |
/** |
107 |
* Fires in the login page header after scripts are enqueued. |
|
108 |
* |
|
109 |
* @since 2.1.0 |
|
110 |
*/ |
|
111 |
do_action( 'login_head' ); |
|
112 |
||
113 |
if ( is_multisite() ) { |
|
114 |
$login_header_url = network_home_url(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
$login_header_title = get_network()->site_name; |
0 | 116 |
} else { |
5 | 117 |
$login_header_url = __( 'https://wordpress.org/' ); |
0 | 118 |
$login_header_title = __( 'Powered by WordPress' ); |
119 |
} |
|
120 |
||
121 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
* Filters link URL of the header logo above login form. |
0 | 123 |
* |
124 |
* @since 2.1.0 |
|
125 |
* |
|
126 |
* @param string $login_header_url Login header logo URL. |
|
127 |
*/ |
|
128 |
$login_header_url = apply_filters( 'login_headerurl', $login_header_url ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
|
0 | 130 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
* Filters the title attribute of the header logo above login form. |
0 | 132 |
* |
133 |
* @since 2.1.0 |
|
134 |
* |
|
135 |
* @param string $login_header_title Login header logo title attribute. |
|
136 |
*/ |
|
137 |
$login_header_title = apply_filters( 'login_headertitle', $login_header_title ); |
|
138 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
* To match the URL/title set above, Multisite sites have the blog name, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
* while single sites get the header title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
if ( is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
$login_header_text = get_bloginfo( 'name', 'display' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
145 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
$login_header_text = $login_header_title; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
|
0 | 149 |
$classes = array( 'login-action-' . $action, 'wp-core-ui' ); |
150 |
if ( is_rtl() ) |
|
151 |
$classes[] = 'rtl'; |
|
152 |
if ( $interim_login ) { |
|
153 |
$classes[] = 'interim-login'; |
|
154 |
?> |
|
155 |
<style type="text/css">html{background-color: transparent;}</style> |
|
156 |
<?php |
|
157 |
||
158 |
if ( 'success' === $interim_login ) |
|
159 |
$classes[] = 'interim-login-success'; |
|
160 |
} |
|
5 | 161 |
$classes[] =' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) ); |
0 | 162 |
|
163 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
164 |
* Filters the login page body classes. |
0 | 165 |
* |
166 |
* @since 3.5.0 |
|
167 |
* |
|
168 |
* @param array $classes An array of body classes. |
|
169 |
* @param string $action The action that brought the visitor to the login page. |
|
170 |
*/ |
|
171 |
$classes = apply_filters( 'login_body_class', $classes, $action ); |
|
172 |
||
173 |
?> |
|
174 |
</head> |
|
175 |
<body class="login <?php echo esc_attr( implode( ' ', $classes ) ); ?>"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
* Fires in the login page header after the body tag is opened. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
do_action( 'login_header' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
?> |
0 | 184 |
<div id="login"> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
<h1><a href="<?php echo esc_url( $login_header_url ); ?>" title="<?php echo esc_attr( $login_header_title ); ?>" tabindex="-1"><?php echo $login_header_text; ?></a></h1> |
0 | 186 |
<?php |
187 |
||
188 |
unset( $login_header_url, $login_header_title ); |
|
189 |
||
190 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
* Filters the message to display above the login form. |
0 | 192 |
* |
193 |
* @since 2.1.0 |
|
194 |
* |
|
195 |
* @param string $message Login message text. |
|
196 |
*/ |
|
197 |
$message = apply_filters( 'login_message', $message ); |
|
198 |
if ( !empty( $message ) ) |
|
199 |
echo $message . "\n"; |
|
200 |
||
201 |
// In case a plugin uses $error rather than the $wp_errors object |
|
202 |
if ( !empty( $error ) ) { |
|
203 |
$wp_error->add('error', $error); |
|
204 |
unset($error); |
|
205 |
} |
|
206 |
||
207 |
if ( $wp_error->get_error_code() ) { |
|
208 |
$errors = ''; |
|
209 |
$messages = ''; |
|
210 |
foreach ( $wp_error->get_error_codes() as $code ) { |
|
5 | 211 |
$severity = $wp_error->get_error_data( $code ); |
212 |
foreach ( $wp_error->get_error_messages( $code ) as $error_message ) { |
|
0 | 213 |
if ( 'message' == $severity ) |
5 | 214 |
$messages .= ' ' . $error_message . "<br />\n"; |
0 | 215 |
else |
5 | 216 |
$errors .= ' ' . $error_message . "<br />\n"; |
0 | 217 |
} |
218 |
} |
|
219 |
if ( ! empty( $errors ) ) { |
|
220 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
* Filters the error messages displayed above the login form. |
0 | 222 |
* |
223 |
* @since 2.1.0 |
|
224 |
* |
|
225 |
* @param string $errors Login error message. |
|
226 |
*/ |
|
227 |
echo '<div id="login_error">' . apply_filters( 'login_errors', $errors ) . "</div>\n"; |
|
228 |
} |
|
229 |
if ( ! empty( $messages ) ) { |
|
230 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
* Filters instructional messages displayed above the login form. |
0 | 232 |
* |
233 |
* @since 2.5.0 |
|
234 |
* |
|
235 |
* @param string $messages Login messages. |
|
236 |
*/ |
|
237 |
echo '<p class="message">' . apply_filters( 'login_messages', $messages ) . "</p>\n"; |
|
238 |
} |
|
239 |
} |
|
240 |
} // End of login_header() |
|
241 |
||
242 |
/** |
|
243 |
* Outputs the footer for the login page. |
|
244 |
* |
|
245 |
* @param string $input_id Which input to auto-focus |
|
246 |
*/ |
|
247 |
function login_footer($input_id = '') { |
|
248 |
global $interim_login; |
|
249 |
||
250 |
// Don't allow interim logins to navigate away from the page. |
|
251 |
if ( ! $interim_login ): ?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
<p id="backtoblog"><a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
/* translators: %s: site title */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
printf( _x( '← Back to %s', 'site' ), get_bloginfo( 'title', 'display' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
?></a></p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
<?php the_privacy_policy_link( '<div class="privacy-policy-page-link">', '</div>' ); ?> |
0 | 257 |
<?php endif; ?> |
258 |
||
259 |
</div> |
|
260 |
||
261 |
<?php if ( !empty($input_id) ) : ?> |
|
262 |
<script type="text/javascript"> |
|
263 |
try{document.getElementById('<?php echo $input_id; ?>').focus();}catch(e){} |
|
264 |
if(typeof wpOnload=='function')wpOnload(); |
|
265 |
</script> |
|
266 |
<?php endif; ?> |
|
267 |
||
268 |
<?php |
|
269 |
/** |
|
270 |
* Fires in the login page footer. |
|
271 |
* |
|
272 |
* @since 3.1.0 |
|
273 |
*/ |
|
274 |
do_action( 'login_footer' ); ?> |
|
275 |
<div class="clear"></div> |
|
276 |
</body> |
|
277 |
</html> |
|
278 |
<?php |
|
279 |
} |
|
280 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
*/ |
0 | 284 |
function wp_shake_js() { |
285 |
?> |
|
286 |
<script type="text/javascript"> |
|
287 |
addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}; |
|
288 |
function s(id,pos){g(id).left=pos+'px';} |
|
289 |
function g(id){return document.getElementById(id).style;} |
|
290 |
function shake(id,a,d){c=a.shift();s(id,c);if(a.length>0){setTimeout(function(){shake(id,a,d);},d);}else{try{g(id).position='static';wp_attempt_focus();}catch(e){}}} |
|
291 |
addLoadEvent(function(){ var p=new Array(15,30,15,0,-15,-30,-15,0);p=p.concat(p.concat(p));var i=document.forms[0].id;g(i).position='relative';shake(i,p,20);}); |
|
292 |
</script> |
|
293 |
<?php |
|
294 |
} |
|
295 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
* @since 3.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
*/ |
0 | 299 |
function wp_login_viewport_meta() { |
300 |
?> |
|
301 |
<meta name="viewport" content="width=device-width" /> |
|
302 |
<?php |
|
303 |
} |
|
304 |
||
305 |
/** |
|
306 |
* Handles sending password retrieval email to user. |
|
307 |
* |
|
308 |
* @return bool|WP_Error True: when finish. WP_Error on error |
|
309 |
*/ |
|
310 |
function retrieve_password() { |
|
311 |
$errors = new WP_Error(); |
|
312 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
if ( empty( $_POST['user_login'] ) || ! is_string( $_POST['user_login'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
$errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or email address.')); |
5 | 315 |
} elseif ( strpos( $_POST['user_login'], '@' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
$user_data = get_user_by( 'email', trim( wp_unslash( $_POST['user_login'] ) ) ); |
0 | 317 |
if ( empty( $user_data ) ) |
318 |
$errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.')); |
|
319 |
} else { |
|
320 |
$login = trim($_POST['user_login']); |
|
321 |
$user_data = get_user_by('login', $login); |
|
322 |
} |
|
323 |
||
324 |
/** |
|
325 |
* Fires before errors are returned from a password reset request. |
|
326 |
* |
|
327 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
* @since 4.4.0 Added the `$errors` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
329 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
330 |
* @param WP_Error $errors A WP_Error object containing any errors generated |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
331 |
* by using invalid credentials. |
0 | 332 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
333 |
do_action( 'lostpassword_post', $errors ); |
0 | 334 |
|
335 |
if ( $errors->get_error_code() ) |
|
336 |
return $errors; |
|
337 |
||
338 |
if ( !$user_data ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
$errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or email.')); |
0 | 340 |
return $errors; |
341 |
} |
|
342 |
||
5 | 343 |
// Redefining user_login ensures we return the right case in the email. |
0 | 344 |
$user_login = $user_data->user_login; |
345 |
$user_email = $user_data->user_email; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
$key = get_password_reset_key( $user_data ); |
5 | 347 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
if ( is_wp_error( $key ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
return $key; |
5 | 350 |
} |
0 | 351 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
352 |
if ( is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
353 |
$site_name = get_network()->site_name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
354 |
} else { |
5 | 355 |
/* |
356 |
* The blogname option is escaped with esc_html on the way into the database |
|
357 |
* in sanitize_option we want to reverse this for the plain text arena of emails. |
|
358 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
$site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
} |
0 | 361 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
362 |
$message = __( 'Someone has requested a password reset for the following account:' ) . "\r\n\r\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
/* translators: %s: site name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
364 |
$message .= sprintf( __( 'Site Name: %s'), $site_name ) . "\r\n\r\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
/* translators: %s: user login */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
$message .= sprintf( __( 'Username: %s'), $user_login ) . "\r\n\r\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
$message .= __( 'If this was a mistake, just ignore this email and nothing will happen.' ) . "\r\n\r\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
368 |
$message .= __( 'To reset your password, visit the following address:' ) . "\r\n\r\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
$message .= '<' . network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . ">\r\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
/* translators: Password reset email subject. %s: Site name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
$title = sprintf( __( '[%s] Password Reset' ), $site_name ); |
0 | 373 |
|
374 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
* Filters the subject of the password reset email. |
0 | 376 |
* |
377 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
* @since 4.4.0 Added the `$user_login` and `$user_data` parameters. |
0 | 379 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
* @param string $title Default email title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
* @param string $user_login The username for the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
* @param WP_User $user_data WP_User object. |
0 | 383 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
$title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data ); |
5 | 385 |
|
0 | 386 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
* Filters the message body of the password reset mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
* If the filtered message is empty, the password reset email will not be sent. |
0 | 390 |
* |
391 |
* @since 2.8.0 |
|
5 | 392 |
* @since 4.1.0 Added `$user_login` and `$user_data` parameters. |
0 | 393 |
* |
5 | 394 |
* @param string $message Default mail message. |
395 |
* @param string $key The activation key. |
|
396 |
* @param string $user_login The username for the user. |
|
397 |
* @param WP_User $user_data WP_User object. |
|
0 | 398 |
*/ |
5 | 399 |
$message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data ); |
0 | 400 |
|
5 | 401 |
if ( $message && !wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
wp_die( __('The email could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.') ); |
0 | 403 |
|
404 |
return true; |
|
405 |
} |
|
406 |
||
407 |
// |
|
408 |
// Main |
|
409 |
// |
|
410 |
||
411 |
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'login'; |
|
412 |
$errors = new WP_Error(); |
|
413 |
||
414 |
if ( isset($_GET['key']) ) |
|
415 |
$action = 'resetpass'; |
|
416 |
||
417 |
// validate action so as to default to the login screen |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
if ( !in_array( $action, array( 'postpass', 'logout', 'lostpassword', 'retrievepassword', 'resetpass', 'rp', 'register', 'login', 'confirmaction' ), true ) && false === has_filter( 'login_form_' . $action ) ) |
0 | 419 |
$action = 'login'; |
420 |
||
421 |
nocache_headers(); |
|
422 |
||
423 |
header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset')); |
|
424 |
||
425 |
if ( defined( 'RELOCATE' ) && RELOCATE ) { // Move flag is set |
|
426 |
if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) ) |
|
427 |
$_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] ); |
|
428 |
||
429 |
$url = dirname( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) ); |
|
430 |
if ( $url != get_option( 'siteurl' ) ) |
|
431 |
update_option( 'siteurl', $url ); |
|
432 |
} |
|
433 |
||
434 |
//Set a cookie now to see if they are supported by the browser. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
$secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) ); |
5 | 436 |
setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure ); |
0 | 437 |
if ( SITECOOKIEPATH != COOKIEPATH ) |
5 | 438 |
setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure ); |
0 | 439 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
$lang = ! empty( $_GET['wp_lang'] ) ? sanitize_text_field( $_GET['wp_lang'] ) : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
$switched_locale = switch_to_locale( $lang ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
|
0 | 443 |
/** |
444 |
* Fires when the login form is initialized. |
|
445 |
* |
|
446 |
* @since 3.2.0 |
|
447 |
*/ |
|
448 |
do_action( 'login_init' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
|
0 | 450 |
/** |
451 |
* Fires before a specified login form action. |
|
452 |
* |
|
5 | 453 |
* The dynamic portion of the hook name, `$action`, refers to the action |
0 | 454 |
* that brought the visitor to the login form. Actions include 'postpass', |
455 |
* 'logout', 'lostpassword', etc. |
|
456 |
* |
|
457 |
* @since 2.8.0 |
|
458 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
do_action( "login_form_{$action}" ); |
0 | 460 |
|
461 |
$http_post = ('POST' == $_SERVER['REQUEST_METHOD']); |
|
462 |
$interim_login = isset($_REQUEST['interim-login']); |
|
463 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
* Filters the separator used between login form navigation links. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
466 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
467 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
469 |
* @param string $login_link_separator The separator used between login form navigation links. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
471 |
$login_link_separator = apply_filters( 'login_link_separator', ' | ' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
472 |
|
0 | 473 |
switch ($action) { |
474 |
||
475 |
case 'postpass' : |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
if ( ! array_key_exists( 'post_password', $_POST ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
477 |
wp_safe_redirect( wp_get_referer() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
exit(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
479 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
|
5 | 481 |
require_once ABSPATH . WPINC . '/class-phpass.php'; |
0 | 482 |
$hasher = new PasswordHash( 8, true ); |
483 |
||
484 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
* Filters the life span of the post password cookie. |
0 | 486 |
* |
487 |
* By default, the cookie expires 10 days from creation. To turn this |
|
488 |
* into a session cookie, return 0. |
|
489 |
* |
|
490 |
* @since 3.7.0 |
|
491 |
* |
|
492 |
* @param int $expires The expiry time, as passed to setcookie(). |
|
493 |
*/ |
|
494 |
$expire = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
$referer = wp_get_referer(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
if ( $referer ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
$secure = ( 'https' === parse_url( $referer, PHP_URL_SCHEME ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
$secure = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
} |
5 | 501 |
setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure ); |
0 | 502 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
if ( $switched_locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
restore_previous_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
|
0 | 507 |
wp_safe_redirect( wp_get_referer() ); |
508 |
exit(); |
|
509 |
||
510 |
case 'logout' : |
|
511 |
check_admin_referer('log-out'); |
|
5 | 512 |
|
513 |
$user = wp_get_current_user(); |
|
514 |
||
0 | 515 |
wp_logout(); |
516 |
||
5 | 517 |
if ( ! empty( $_REQUEST['redirect_to'] ) ) { |
518 |
$redirect_to = $requested_redirect_to = $_REQUEST['redirect_to']; |
|
519 |
} else { |
|
520 |
$redirect_to = 'wp-login.php?loggedout=true'; |
|
521 |
$requested_redirect_to = ''; |
|
522 |
} |
|
523 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
if ( $switched_locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
restore_previous_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
|
5 | 528 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
* Filters the log out redirect URL. |
5 | 530 |
* |
531 |
* @since 4.2.0 |
|
532 |
* |
|
533 |
* @param string $redirect_to The redirect destination URL. |
|
534 |
* @param string $requested_redirect_to The requested redirect destination URL passed as a parameter. |
|
535 |
* @param WP_User $user The WP_User object for the user that's logging out. |
|
536 |
*/ |
|
537 |
$redirect_to = apply_filters( 'logout_redirect', $redirect_to, $requested_redirect_to, $user ); |
|
0 | 538 |
wp_safe_redirect( $redirect_to ); |
539 |
exit(); |
|
540 |
||
541 |
case 'lostpassword' : |
|
542 |
case 'retrievepassword' : |
|
543 |
||
544 |
if ( $http_post ) { |
|
545 |
$errors = retrieve_password(); |
|
546 |
if ( !is_wp_error($errors) ) { |
|
547 |
$redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?checkemail=confirm'; |
|
548 |
wp_safe_redirect( $redirect_to ); |
|
549 |
exit(); |
|
550 |
} |
|
551 |
} |
|
552 |
||
553 |
if ( isset( $_GET['error'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
554 |
if ( 'invalidkey' == $_GET['error'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
$errors->add( 'invalidkey', __( 'Your password reset link appears to be invalid. Please request a new link below.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
} elseif ( 'expiredkey' == $_GET['error'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
$errors->add( 'expiredkey', __( 'Your password reset link has expired. Please request a new link below.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
} |
0 | 559 |
} |
560 |
||
561 |
$lostpassword_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; |
|
562 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
* Filters the URL redirected to after submitting the lostpassword/retrievepassword form. |
0 | 564 |
* |
565 |
* @since 3.0.0 |
|
566 |
* |
|
567 |
* @param string $lostpassword_redirect The redirect destination URL. |
|
568 |
*/ |
|
569 |
$redirect_to = apply_filters( 'lostpassword_redirect', $lostpassword_redirect ); |
|
570 |
||
571 |
/** |
|
572 |
* Fires before the lost password form. |
|
573 |
* |
|
5 | 574 |
* @since 1.5.1 |
0 | 575 |
*/ |
576 |
do_action( 'lost_password' ); |
|
577 |
||
578 |
login_header(__('Lost Password'), '<p class="message">' . __('Please enter your username or email address. You will receive a link to create a new password via email.') . '</p>', $errors); |
|
579 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
$user_login = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
581 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
582 |
if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
$user_login = wp_unslash( $_POST['user_login'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
584 |
} |
0 | 585 |
|
586 |
?> |
|
587 |
||
5 | 588 |
<form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post"> |
0 | 589 |
<p> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
<label for="user_login" ><?php _e( 'Username or Email Address' ); ?><br /> |
0 | 591 |
<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label> |
592 |
</p> |
|
593 |
<?php |
|
594 |
/** |
|
5 | 595 |
* Fires inside the lostpassword form tags, before the hidden fields. |
0 | 596 |
* |
597 |
* @since 2.1.0 |
|
598 |
*/ |
|
599 |
do_action( 'lostpassword_form' ); ?> |
|
600 |
<input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" /> |
|
601 |
<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Get New Password'); ?>" /></p> |
|
602 |
</form> |
|
603 |
||
604 |
<p id="nav"> |
|
605 |
<a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e('Log in') ?></a> |
|
606 |
<?php |
|
607 |
if ( get_option( 'users_can_register' ) ) : |
|
608 |
$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ); |
|
5 | 609 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
610 |
echo esc_html( $login_link_separator ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
611 |
|
5 | 612 |
/** This filter is documented in wp-includes/general-template.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
echo apply_filters( 'register', $registration_url ); |
0 | 614 |
endif; |
615 |
?> |
|
616 |
</p> |
|
617 |
||
618 |
<?php |
|
619 |
login_footer('user_login'); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
if ( $switched_locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
restore_previous_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
|
0 | 625 |
break; |
626 |
||
627 |
case 'resetpass' : |
|
628 |
case 'rp' : |
|
5 | 629 |
list( $rp_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) ); |
630 |
$rp_cookie = 'wp-resetpass-' . COOKIEHASH; |
|
631 |
if ( isset( $_GET['key'] ) ) { |
|
632 |
$value = sprintf( '%s:%s', wp_unslash( $_GET['login'] ), wp_unslash( $_GET['key'] ) ); |
|
633 |
setcookie( $rp_cookie, $value, 0, $rp_path, COOKIE_DOMAIN, is_ssl(), true ); |
|
634 |
wp_safe_redirect( remove_query_arg( array( 'key', 'login' ) ) ); |
|
635 |
exit; |
|
636 |
} |
|
0 | 637 |
|
5 | 638 |
if ( isset( $_COOKIE[ $rp_cookie ] ) && 0 < strpos( $_COOKIE[ $rp_cookie ], ':' ) ) { |
639 |
list( $rp_login, $rp_key ) = explode( ':', wp_unslash( $_COOKIE[ $rp_cookie ] ), 2 ); |
|
640 |
$user = check_password_reset_key( $rp_key, $rp_login ); |
|
641 |
if ( isset( $_POST['pass1'] ) && ! hash_equals( $rp_key, $_POST['rp_key'] ) ) { |
|
642 |
$user = false; |
|
643 |
} |
|
644 |
} else { |
|
645 |
$user = false; |
|
646 |
} |
|
647 |
||
648 |
if ( ! $user || is_wp_error( $user ) ) { |
|
649 |
setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true ); |
|
650 |
if ( $user && $user->get_error_code() === 'expired_key' ) |
|
0 | 651 |
wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=expiredkey' ) ); |
652 |
else |
|
653 |
wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=invalidkey' ) ); |
|
654 |
exit; |
|
655 |
} |
|
656 |
||
657 |
$errors = new WP_Error(); |
|
658 |
||
659 |
if ( isset($_POST['pass1']) && $_POST['pass1'] != $_POST['pass2'] ) |
|
660 |
$errors->add( 'password_reset_mismatch', __( 'The passwords do not match.' ) ); |
|
661 |
||
662 |
/** |
|
663 |
* Fires before the password reset procedure is validated. |
|
664 |
* |
|
665 |
* @since 3.5.0 |
|
666 |
* |
|
667 |
* @param object $errors WP Error object. |
|
668 |
* @param WP_User|WP_Error $user WP_User object if the login and reset key match. WP_Error object otherwise. |
|
669 |
*/ |
|
670 |
do_action( 'validate_password_reset', $errors, $user ); |
|
671 |
||
672 |
if ( ( ! $errors->get_error_code() ) && isset( $_POST['pass1'] ) && !empty( $_POST['pass1'] ) ) { |
|
673 |
reset_password($user, $_POST['pass1']); |
|
5 | 674 |
setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true ); |
0 | 675 |
login_header( __( 'Password Reset' ), '<p class="message reset-pass">' . __( 'Your password has been reset.' ) . ' <a href="' . esc_url( wp_login_url() ) . '">' . __( 'Log in' ) . '</a></p>' ); |
676 |
login_footer(); |
|
677 |
exit; |
|
678 |
} |
|
679 |
||
680 |
wp_enqueue_script('utils'); |
|
681 |
wp_enqueue_script('user-profile'); |
|
682 |
||
683 |
login_header(__('Reset Password'), '<p class="message reset-pass">' . __('Enter your new password below.') . '</p>', $errors ); |
|
684 |
||
685 |
?> |
|
5 | 686 |
<form name="resetpassform" id="resetpassform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=resetpass', 'login_post' ) ); ?>" method="post" autocomplete="off"> |
687 |
<input type="hidden" id="user_login" value="<?php echo esc_attr( $rp_login ); ?>" autocomplete="off" /> |
|
0 | 688 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
<div class="user-pass1-wrap"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
<p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
<label for="pass1"><?php _e( 'New password' ) ?></label> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
</p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
<div class="wp-pwd"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
695 |
<div class="password-input-wrapper"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
696 |
<input type="password" data-reveal="1" data-pw="<?php echo esc_attr( wp_generate_password( 16 ) ); ?>" name="pass1" id="pass1" class="input password-input" size="24" value="" autocomplete="off" aria-describedby="pass-strength-result" /> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
697 |
<span class="button button-secondary wp-hide-pw hide-if-no-js"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
698 |
<span class="dashicons dashicons-hidden"></span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
699 |
</span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
</div> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
<div id="pass-strength-result" class="hide-if-no-js" aria-live="polite"><?php _e( 'Strength indicator' ); ?></div> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
</div> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
<div class="pw-weak"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
704 |
<label> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
<input type="checkbox" name="pw_weak" class="pw-checkbox" /> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
<?php _e( 'Confirm use of weak password' ); ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
</label> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
708 |
</div> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
709 |
</div> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
<p class="user-pass2-wrap"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
712 |
<label for="pass2"><?php _e( 'Confirm new password' ) ?></label><br /> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
713 |
<input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" /> |
0 | 714 |
</p> |
715 |
||
5 | 716 |
<p class="description indicator-hint"><?php echo wp_get_password_hint(); ?></p> |
717 |
<br class="clear" /> |
|
0 | 718 |
|
5 | 719 |
<?php |
720 |
/** |
|
721 |
* Fires following the 'Strength indicator' meter in the user password reset form. |
|
722 |
* |
|
723 |
* @since 3.9.0 |
|
724 |
* |
|
725 |
* @param WP_User $user User object of the user whose password is being reset. |
|
726 |
*/ |
|
727 |
do_action( 'resetpass_form', $user ); |
|
728 |
?> |
|
729 |
<input type="hidden" name="rp_key" value="<?php echo esc_attr( $rp_key ); ?>" /> |
|
0 | 730 |
<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Reset Password'); ?>" /></p> |
731 |
</form> |
|
732 |
||
733 |
<p id="nav"> |
|
734 |
<a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a> |
|
735 |
<?php |
|
736 |
if ( get_option( 'users_can_register' ) ) : |
|
737 |
$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ); |
|
5 | 738 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
echo esc_html( $login_link_separator ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
|
5 | 741 |
/** This filter is documented in wp-includes/general-template.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
echo apply_filters( 'register', $registration_url ); |
0 | 743 |
endif; |
744 |
?> |
|
745 |
</p> |
|
746 |
||
747 |
<?php |
|
748 |
login_footer('user_pass'); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
749 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
750 |
if ( $switched_locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
751 |
restore_previous_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
752 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
753 |
|
0 | 754 |
break; |
755 |
||
756 |
case 'register' : |
|
757 |
if ( is_multisite() ) { |
|
758 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
* Filters the Multisite sign up URL. |
0 | 760 |
* |
761 |
* @since 3.0.0 |
|
762 |
* |
|
763 |
* @param string $sign_up_url The sign up URL. |
|
764 |
*/ |
|
5 | 765 |
wp_redirect( apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ) ); |
0 | 766 |
exit; |
767 |
} |
|
768 |
||
769 |
if ( !get_option('users_can_register') ) { |
|
770 |
wp_redirect( site_url('wp-login.php?registration=disabled') ); |
|
771 |
exit(); |
|
772 |
} |
|
773 |
||
774 |
$user_login = ''; |
|
775 |
$user_email = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
776 |
|
0 | 777 |
if ( $http_post ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
778 |
if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
779 |
$user_login = $_POST['user_login']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
780 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
781 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
782 |
if ( isset( $_POST['user_email'] ) && is_string( $_POST['user_email'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
783 |
$user_email = wp_unslash( $_POST['user_email'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
784 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
785 |
|
0 | 786 |
$errors = register_new_user($user_login, $user_email); |
787 |
if ( !is_wp_error($errors) ) { |
|
788 |
$redirect_to = !empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : 'wp-login.php?checkemail=registered'; |
|
789 |
wp_safe_redirect( $redirect_to ); |
|
790 |
exit(); |
|
791 |
} |
|
792 |
} |
|
793 |
||
794 |
$registration_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; |
|
795 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
796 |
* Filters the registration redirect URL. |
0 | 797 |
* |
798 |
* @since 3.0.0 |
|
799 |
* |
|
800 |
* @param string $registration_redirect The redirect destination URL. |
|
801 |
*/ |
|
802 |
$redirect_to = apply_filters( 'registration_redirect', $registration_redirect ); |
|
803 |
login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>', $errors); |
|
804 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
805 |
<form name="registerform" id="registerform" action="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login_post' ) ); ?>" method="post" novalidate="novalidate"> |
0 | 806 |
<p> |
807 |
<label for="user_login"><?php _e('Username') ?><br /> |
|
808 |
<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr(wp_unslash($user_login)); ?>" size="20" /></label> |
|
809 |
</p> |
|
810 |
<p> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
811 |
<label for="user_email"><?php _e('Email') ?><br /> |
5 | 812 |
<input type="email" name="user_email" id="user_email" class="input" value="<?php echo esc_attr( wp_unslash( $user_email ) ); ?>" size="25" /></label> |
0 | 813 |
</p> |
814 |
<?php |
|
815 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
816 |
* Fires following the 'Email' field in the user registration form. |
0 | 817 |
* |
818 |
* @since 2.1.0 |
|
819 |
*/ |
|
820 |
do_action( 'register_form' ); |
|
821 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
822 |
<p id="reg_passmail"><?php _e( 'Registration confirmation will be emailed to you.' ); ?></p> |
0 | 823 |
<br class="clear" /> |
824 |
<input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" /> |
|
825 |
<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Register'); ?>" /></p> |
|
826 |
</form> |
|
827 |
||
828 |
<p id="nav"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
829 |
<a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
830 |
<?php echo esc_html( $login_link_separator ); ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a> |
0 | 832 |
</p> |
833 |
||
834 |
<?php |
|
835 |
login_footer('user_login'); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
836 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
if ( $switched_locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
restore_previous_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
839 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
840 |
|
0 | 841 |
break; |
842 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
843 |
case 'confirmaction' : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
if ( ! isset( $_GET['request_id'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
845 |
wp_die( __( 'Invalid request.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
846 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
847 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
848 |
$request_id = (int) $_GET['request_id']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
849 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
850 |
if ( isset( $_GET['confirm_key'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
851 |
$key = sanitize_text_field( wp_unslash( $_GET['confirm_key'] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
852 |
$result = wp_validate_user_request_key( $request_id, $key ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
853 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
854 |
$result = new WP_Error( 'invalid_key', __( 'Invalid key' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
855 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
856 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
857 |
if ( is_wp_error( $result ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
858 |
wp_die( $result ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
861 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
* Fires an action hook when the account action has been confirmed by the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
863 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
864 |
* Using this you can assume the user has agreed to perform the action by |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
865 |
* clicking on the link in the confirmation email. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
866 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
867 |
* After firing this action hook the page will redirect to wp-login a callback |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
868 |
* redirects or exits first. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
* @param int $request_id Request ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
871 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
do_action( 'user_request_action_confirmed', $request_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
873 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
874 |
$message = _wp_privacy_account_request_confirmed_message( $request_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
875 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
876 |
login_header( __( 'User action confirmed.' ), $message ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
877 |
login_footer(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
878 |
exit; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
879 |
|
0 | 880 |
case 'login' : |
881 |
default: |
|
882 |
$secure_cookie = ''; |
|
883 |
$customize_login = isset( $_REQUEST['customize-login'] ); |
|
884 |
if ( $customize_login ) |
|
885 |
wp_enqueue_script( 'customize-base' ); |
|
886 |
||
887 |
// If the user wants ssl but the session is not ssl, force a secure cookie. |
|
888 |
if ( !empty($_POST['log']) && !force_ssl_admin() ) { |
|
889 |
$user_name = sanitize_user($_POST['log']); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
890 |
$user = get_user_by( 'login', $user_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
891 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
892 |
if ( ! $user && strpos( $user_name, '@' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
893 |
$user = get_user_by( 'email', $user_name ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
896 |
if ( $user ) { |
0 | 897 |
if ( get_user_option('use_ssl', $user->ID) ) { |
898 |
$secure_cookie = true; |
|
899 |
force_ssl_admin(true); |
|
900 |
} |
|
901 |
} |
|
902 |
} |
|
903 |
||
904 |
if ( isset( $_REQUEST['redirect_to'] ) ) { |
|
905 |
$redirect_to = $_REQUEST['redirect_to']; |
|
906 |
// Redirect to https if user wants ssl |
|
907 |
if ( $secure_cookie && false !== strpos($redirect_to, 'wp-admin') ) |
|
908 |
$redirect_to = preg_replace('|^http://|', 'https://', $redirect_to); |
|
909 |
} else { |
|
910 |
$redirect_to = admin_url(); |
|
911 |
} |
|
912 |
||
913 |
$reauth = empty($_REQUEST['reauth']) ? false : true; |
|
914 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
915 |
$user = wp_signon( array(), $secure_cookie ); |
0 | 916 |
|
5 | 917 |
if ( empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) { |
918 |
if ( headers_sent() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
919 |
/* translators: 1: Browser cookie documentation URL, 2: Support forums URL */ |
5 | 920 |
$user = new WP_Error( 'test_cookie', sprintf( __( '<strong>ERROR</strong>: Cookies are blocked due to unexpected output. For help, please see <a href="%1$s">this documentation</a> or try the <a href="%2$s">support forums</a>.' ), |
921 |
__( 'https://codex.wordpress.org/Cookies' ), __( 'https://wordpress.org/support/' ) ) ); |
|
922 |
} elseif ( isset( $_POST['testcookie'] ) && empty( $_COOKIE[ TEST_COOKIE ] ) ) { |
|
923 |
// If cookies are disabled we can't log in even with a valid user+pass |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
924 |
/* translators: 1: Browser cookie documentation URL */ |
5 | 925 |
$user = new WP_Error( 'test_cookie', sprintf( __( '<strong>ERROR</strong>: Cookies are blocked or not supported by your browser. You must <a href="%s">enable cookies</a> to use WordPress.' ), |
926 |
__( 'https://codex.wordpress.org/Cookies' ) ) ); |
|
927 |
} |
|
928 |
} |
|
0 | 929 |
|
930 |
$requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; |
|
931 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
932 |
* Filters the login redirect URL. |
0 | 933 |
* |
934 |
* @since 3.0.0 |
|
935 |
* |
|
936 |
* @param string $redirect_to The redirect destination URL. |
|
937 |
* @param string $requested_redirect_to The requested redirect destination URL passed as a parameter. |
|
938 |
* @param WP_User|WP_Error $user WP_User object if login was successful, WP_Error object otherwise. |
|
939 |
*/ |
|
940 |
$redirect_to = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $user ); |
|
941 |
||
942 |
if ( !is_wp_error($user) && !$reauth ) { |
|
943 |
if ( $interim_login ) { |
|
944 |
$message = '<p class="message">' . __('You have logged in successfully.') . '</p>'; |
|
945 |
$interim_login = 'success'; |
|
946 |
login_header( '', $message ); ?> |
|
947 |
</div> |
|
948 |
<?php |
|
949 |
/** This action is documented in wp-login.php */ |
|
950 |
do_action( 'login_footer' ); ?> |
|
951 |
<?php if ( $customize_login ) : ?> |
|
952 |
<script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo wp_customize_url(); ?>', channel: 'login' }).send('login') }, 1000 );</script> |
|
953 |
<?php endif; ?> |
|
954 |
</body></html> |
|
955 |
<?php exit; |
|
956 |
} |
|
957 |
||
958 |
if ( ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' || $redirect_to == admin_url() ) ) { |
|
959 |
// If the user doesn't belong to a blog, send them to user admin. If the user can't edit posts, send them to their profile. |
|
960 |
if ( is_multisite() && !get_active_blog_for_user($user->ID) && !is_super_admin( $user->ID ) ) |
|
961 |
$redirect_to = user_admin_url(); |
|
962 |
elseif ( is_multisite() && !$user->has_cap('read') ) |
|
963 |
$redirect_to = get_dashboard_url( $user->ID ); |
|
964 |
elseif ( !$user->has_cap('edit_posts') ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
965 |
$redirect_to = $user->has_cap( 'read' ) ? admin_url( 'profile.php' ) : home_url(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
966 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
967 |
wp_redirect( $redirect_to ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
968 |
exit(); |
0 | 969 |
} |
970 |
wp_safe_redirect($redirect_to); |
|
971 |
exit(); |
|
972 |
} |
|
973 |
||
974 |
$errors = $user; |
|
975 |
// Clear errors if loggedout is set. |
|
976 |
if ( !empty($_GET['loggedout']) || $reauth ) |
|
977 |
$errors = new WP_Error(); |
|
978 |
||
979 |
if ( $interim_login ) { |
|
980 |
if ( ! $errors->get_error_code() ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
$errors->add( 'expired', __( 'Your session has expired. Please log in to continue where you left off.' ), 'message' ); |
0 | 982 |
} else { |
983 |
// Some parts of this script use the main login form to display a message |
|
984 |
if ( isset($_GET['loggedout']) && true == $_GET['loggedout'] ) |
|
985 |
$errors->add('loggedout', __('You are now logged out.'), 'message'); |
|
986 |
elseif ( isset($_GET['registration']) && 'disabled' == $_GET['registration'] ) |
|
987 |
$errors->add('registerdisabled', __('User registration is currently not allowed.')); |
|
988 |
elseif ( isset($_GET['checkemail']) && 'confirm' == $_GET['checkemail'] ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
989 |
$errors->add('confirm', __('Check your email for the confirmation link.'), 'message'); |
0 | 990 |
elseif ( isset($_GET['checkemail']) && 'newpass' == $_GET['checkemail'] ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
$errors->add('newpass', __('Check your email for your new password.'), 'message'); |
0 | 992 |
elseif ( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
$errors->add('registered', __('Registration complete. Please check your email.'), 'message'); |
0 | 994 |
elseif ( strpos( $redirect_to, 'about.php?updated' ) ) |
5 | 995 |
$errors->add('updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to see what’s new.' ), 'message' ); |
0 | 996 |
} |
997 |
||
998 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
* Filters the login page errors. |
0 | 1000 |
* |
1001 |
* @since 3.6.0 |
|
1002 |
* |
|
1003 |
* @param object $errors WP Error object. |
|
1004 |
* @param string $redirect_to Redirect destination URL. |
|
1005 |
*/ |
|
1006 |
$errors = apply_filters( 'wp_login_errors', $errors, $redirect_to ); |
|
1007 |
||
1008 |
// Clear any stale cookies. |
|
1009 |
if ( $reauth ) |
|
1010 |
wp_clear_auth_cookie(); |
|
1011 |
||
1012 |
login_header(__('Log In'), '', $errors); |
|
1013 |
||
1014 |
if ( isset($_POST['log']) ) |
|
1015 |
$user_login = ( 'incorrect_password' == $errors->get_error_code() || 'empty_password' == $errors->get_error_code() ) ? esc_attr(wp_unslash($_POST['log'])) : ''; |
|
1016 |
$rememberme = ! empty( $_POST['rememberme'] ); |
|
5 | 1017 |
|
1018 |
if ( ! empty( $errors->errors ) ) { |
|
1019 |
$aria_describedby_error = ' aria-describedby="login_error"'; |
|
1020 |
} else { |
|
1021 |
$aria_describedby_error = ''; |
|
1022 |
} |
|
0 | 1023 |
?> |
1024 |
||
1025 |
<form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post"> |
|
1026 |
<p> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1027 |
<label for="user_login"><?php _e( 'Username or Email Address' ); ?><br /> |
5 | 1028 |
<input type="text" name="log" id="user_login"<?php echo $aria_describedby_error; ?> class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" /></label> |
0 | 1029 |
</p> |
1030 |
<p> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
<label for="user_pass"><?php _e( 'Password' ); ?><br /> |
5 | 1032 |
<input type="password" name="pwd" id="user_pass"<?php echo $aria_describedby_error; ?> class="input" value="" size="20" /></label> |
0 | 1033 |
</p> |
1034 |
<?php |
|
1035 |
/** |
|
1036 |
* Fires following the 'Password' field in the login form. |
|
1037 |
* |
|
1038 |
* @since 2.1.0 |
|
1039 |
*/ |
|
1040 |
do_action( 'login_form' ); |
|
1041 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1042 |
<p class="forgetmenot"><label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever" <?php checked( $rememberme ); ?> /> <?php esc_html_e( 'Remember Me' ); ?></label></p> |
0 | 1043 |
<p class="submit"> |
1044 |
<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Log In'); ?>" /> |
|
1045 |
<?php if ( $interim_login ) { ?> |
|
1046 |
<input type="hidden" name="interim-login" value="1" /> |
|
1047 |
<?php } else { ?> |
|
1048 |
<input type="hidden" name="redirect_to" value="<?php echo esc_attr($redirect_to); ?>" /> |
|
1049 |
<?php } ?> |
|
1050 |
<?php if ( $customize_login ) : ?> |
|
1051 |
<input type="hidden" name="customize-login" value="1" /> |
|
1052 |
<?php endif; ?> |
|
1053 |
<input type="hidden" name="testcookie" value="1" /> |
|
1054 |
</p> |
|
1055 |
</form> |
|
1056 |
||
1057 |
<?php if ( ! $interim_login ) { ?> |
|
1058 |
<p id="nav"> |
|
1059 |
<?php if ( ! isset( $_GET['checkemail'] ) || ! in_array( $_GET['checkemail'], array( 'confirm', 'newpass' ) ) ) : |
|
1060 |
if ( get_option( 'users_can_register' ) ) : |
|
1061 |
$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ); |
|
5 | 1062 |
|
1063 |
/** This filter is documented in wp-includes/general-template.php */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
echo apply_filters( 'register', $registration_url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1065 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1066 |
echo esc_html( $login_link_separator ); |
0 | 1067 |
endif; |
1068 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a> |
0 | 1070 |
<?php endif; ?> |
1071 |
</p> |
|
1072 |
<?php } ?> |
|
1073 |
||
1074 |
<script type="text/javascript"> |
|
1075 |
function wp_attempt_focus(){ |
|
1076 |
setTimeout( function(){ try{ |
|
5 | 1077 |
<?php if ( $user_login ) { ?> |
0 | 1078 |
d = document.getElementById('user_pass'); |
1079 |
d.value = ''; |
|
1080 |
<?php } else { ?> |
|
1081 |
d = document.getElementById('user_login'); |
|
1082 |
<?php if ( 'invalid_username' == $errors->get_error_code() ) { ?> |
|
1083 |
if( d.value != '' ) |
|
1084 |
d.value = ''; |
|
1085 |
<?php |
|
1086 |
} |
|
1087 |
}?> |
|
1088 |
d.focus(); |
|
1089 |
d.select(); |
|
1090 |
} catch(e){} |
|
1091 |
}, 200); |
|
1092 |
} |
|
1093 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1094 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1095 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
* Filters whether to print the call to `wp_attempt_focus()` on the login screen. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
* @param bool $print Whether to print the function call. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
if ( apply_filters( 'enable_login_autofocus', true ) && ! $error ) { ?> |
0 | 1103 |
wp_attempt_focus(); |
1104 |
<?php } ?> |
|
1105 |
if(typeof wpOnload=='function')wpOnload(); |
|
1106 |
<?php if ( $interim_login ) { ?> |
|
1107 |
(function(){ |
|
1108 |
try { |
|
1109 |
var i, links = document.getElementsByTagName('a'); |
|
1110 |
for ( i in links ) { |
|
1111 |
if ( links[i].href ) |
|
1112 |
links[i].target = '_blank'; |
|
1113 |
} |
|
1114 |
} catch(e){} |
|
1115 |
}()); |
|
1116 |
<?php } ?> |
|
1117 |
</script> |
|
1118 |
||
1119 |
<?php |
|
1120 |
login_footer(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1121 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1122 |
if ( $switched_locale ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1123 |
restore_previous_locale(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
|
0 | 1126 |
break; |
1127 |
} // end action switch |