author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 9 | 177826044cd9 |
child 18 | be944660c56a |
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. */ |
|
16 | 12 |
require __DIR__ . '/wp-load.php'; |
0 | 13 |
|
9 | 14 |
// Redirect to HTTPS login if forced to use SSL. |
0 | 15 |
if ( force_ssl_admin() && ! is_ssl() ) { |
9 | 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' ) ); |
16 | 18 |
exit; |
0 | 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'] ); |
16 | 21 |
exit; |
0 | 22 |
} |
23 |
} |
|
24 |
||
25 |
/** |
|
26 |
* Output the login page header. |
|
27 |
* |
|
9 | 28 |
* @since 2.1.0 |
29 |
* |
|
16 | 30 |
* @global string $error Login error message set by deprecated pluggable wp_login() function |
31 |
* or plugins replacing it. |
|
32 |
* @global bool|string $interim_login Whether interim login modal is being displayed. String 'success' |
|
33 |
* upon successful login. |
|
34 |
* @global string $action The action that brought the visitor to the login page. |
|
35 |
* |
|
5 | 36 |
* @param string $title Optional. WordPress login Page title to display in the `<title>` element. |
37 |
* Default 'Log In'. |
|
38 |
* @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
|
39 |
* @param WP_Error $wp_error Optional. The error to pass. Default is a WP_Error instance. |
0 | 40 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
function login_header( $title = 'Log In', $message = '', $wp_error = null ) { |
5 | 42 |
global $error, $interim_login, $action; |
0 | 43 |
|
16 | 44 |
// Don't index any of these forms. |
9 | 45 |
add_action( 'login_head', 'wp_sensitive_page_meta' ); |
0 | 46 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
add_action( 'login_head', 'wp_login_viewport_meta' ); |
0 | 48 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
if ( ! is_wp_error( $wp_error ) ) { |
0 | 50 |
$wp_error = new WP_Error(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
} |
0 | 52 |
|
53 |
// Shake it! |
|
16 | 54 |
$shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password', 'retrieve_password_email_failure' ); |
0 | 55 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
* Filters the error codes array for shaking the login form. |
0 | 57 |
* |
58 |
* @since 3.0.0 |
|
59 |
* |
|
60 |
* @param array $shake_error_codes Error codes that shake the login form. |
|
61 |
*/ |
|
62 |
$shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes ); |
|
63 |
||
16 | 64 |
if ( $shake_error_codes && $wp_error->has_errors() && in_array( $wp_error->get_error_code(), $shake_error_codes, true ) ) { |
65 |
add_action( 'login_footer', 'wp_shake_js', 12 ); |
|
9 | 66 |
} |
0 | 67 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
$login_title = get_bloginfo( 'name', 'display' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
|
16 | 70 |
/* translators: Login screen title. 1: Login screen name, 2: Network or site name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
$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
|
72 |
|
9 | 73 |
if ( wp_is_recovery_mode() ) { |
74 |
/* translators: %s: Login screen title. */ |
|
75 |
$login_title = sprintf( __( 'Recovery Mode — %s' ), $login_title ); |
|
76 |
} |
|
77 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
* Filters the title tag content for login page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
* @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
|
84 |
* @param string $title The original page title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
$login_title = apply_filters( 'login_title', $login_title, $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
|
0 | 88 |
?><!DOCTYPE html> |
16 | 89 |
<html <?php language_attributes(); ?>> |
0 | 90 |
<head> |
9 | 91 |
<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
|
92 |
<title><?php echo $login_title; ?></title> |
0 | 93 |
<?php |
94 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
wp_enqueue_style( 'login' ); |
0 | 96 |
|
5 | 97 |
/* |
98 |
* Remove all stored post data on logging out. |
|
99 |
* This could be added by add_action('login_head'...) like wp_shake_js(), |
|
9 | 100 |
* but maybe better if it's not removable by plugins. |
5 | 101 |
*/ |
16 | 102 |
if ( 'loggedout' === $wp_error->get_error_code() ) { |
0 | 103 |
?> |
104 |
<script>if("sessionStorage" in window){try{for(var key in sessionStorage){if(key.indexOf("wp-autosave-")!=-1){sessionStorage.removeItem(key)}}}catch(e){}};</script> |
|
105 |
<?php |
|
106 |
} |
|
107 |
||
108 |
/** |
|
109 |
* Enqueue scripts and styles for the login page. |
|
110 |
* |
|
111 |
* @since 3.1.0 |
|
112 |
*/ |
|
113 |
do_action( 'login_enqueue_scripts' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
|
0 | 115 |
/** |
116 |
* Fires in the login page header after scripts are enqueued. |
|
117 |
* |
|
118 |
* @since 2.1.0 |
|
119 |
*/ |
|
120 |
do_action( 'login_head' ); |
|
121 |
||
9 | 122 |
$login_header_url = __( 'https://wordpress.org/' ); |
0 | 123 |
|
124 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
* Filters link URL of the header logo above login form. |
0 | 126 |
* |
127 |
* @since 2.1.0 |
|
128 |
* |
|
129 |
* @param string $login_header_url Login header logo URL. |
|
130 |
*/ |
|
131 |
$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
|
132 |
|
9 | 133 |
$login_header_title = ''; |
134 |
||
0 | 135 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
* Filters the title attribute of the header logo above login form. |
0 | 137 |
* |
138 |
* @since 2.1.0 |
|
16 | 139 |
* @deprecated 5.2.0 Use {@see 'login_headertext'} instead. |
0 | 140 |
* |
141 |
* @param string $login_header_title Login header logo title attribute. |
|
142 |
*/ |
|
9 | 143 |
$login_header_title = apply_filters_deprecated( |
144 |
'login_headertitle', |
|
145 |
array( $login_header_title ), |
|
146 |
'5.2.0', |
|
147 |
'login_headertext', |
|
148 |
__( 'Usage of the title attribute on the login logo is not recommended for accessibility reasons. Use the link text instead.' ) |
|
149 |
); |
|
0 | 150 |
|
9 | 151 |
$login_header_text = empty( $login_header_title ) ? __( 'Powered by WordPress' ) : $login_header_title; |
152 |
||
153 |
/** |
|
154 |
* Filters the link text of the header logo above the login form. |
|
155 |
* |
|
156 |
* @since 5.2.0 |
|
157 |
* |
|
158 |
* @param string $login_header_text The login header logo link text. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
*/ |
9 | 160 |
$login_header_text = apply_filters( 'login_headertext', $login_header_text ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
|
0 | 162 |
$classes = array( 'login-action-' . $action, 'wp-core-ui' ); |
16 | 163 |
|
9 | 164 |
if ( is_rtl() ) { |
0 | 165 |
$classes[] = 'rtl'; |
9 | 166 |
} |
16 | 167 |
|
0 | 168 |
if ( $interim_login ) { |
169 |
$classes[] = 'interim-login'; |
|
16 | 170 |
|
0 | 171 |
?> |
172 |
<style type="text/css">html{background-color: transparent;}</style> |
|
173 |
<?php |
|
174 |
||
9 | 175 |
if ( 'success' === $interim_login ) { |
0 | 176 |
$classes[] = 'interim-login-success'; |
9 | 177 |
} |
0 | 178 |
} |
16 | 179 |
|
9 | 180 |
$classes[] = ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) ); |
0 | 181 |
|
182 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
* Filters the login page body classes. |
0 | 184 |
* |
185 |
* @since 3.5.0 |
|
186 |
* |
|
187 |
* @param array $classes An array of body classes. |
|
188 |
* @param string $action The action that brought the visitor to the login page. |
|
189 |
*/ |
|
190 |
$classes = apply_filters( 'login_body_class', $classes, $action ); |
|
191 |
||
192 |
?> |
|
193 |
</head> |
|
16 | 194 |
<body class="login no-js <?php echo esc_attr( implode( ' ', $classes ) ); ?>"> |
195 |
<script type="text/javascript"> |
|
196 |
document.body.className = document.body.className.replace('no-js','js'); |
|
197 |
</script> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
* 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
|
201 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
do_action( 'login_header' ); |
16 | 205 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
?> |
0 | 207 |
<div id="login"> |
9 | 208 |
<h1><a href="<?php echo esc_url( $login_header_url ); ?>"><?php echo $login_header_text; ?></a></h1> |
0 | 209 |
<?php |
210 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
* Filters the message to display above the login form. |
0 | 212 |
* |
213 |
* @since 2.1.0 |
|
214 |
* |
|
215 |
* @param string $message Login message text. |
|
216 |
*/ |
|
217 |
$message = apply_filters( 'login_message', $message ); |
|
16 | 218 |
|
9 | 219 |
if ( ! empty( $message ) ) { |
0 | 220 |
echo $message . "\n"; |
221 |
} |
|
222 |
||
9 | 223 |
// In case a plugin uses $error rather than the $wp_errors object. |
224 |
if ( ! empty( $error ) ) { |
|
225 |
$wp_error->add( 'error', $error ); |
|
226 |
unset( $error ); |
|
227 |
} |
|
228 |
||
229 |
if ( $wp_error->has_errors() ) { |
|
230 |
$errors = ''; |
|
0 | 231 |
$messages = ''; |
16 | 232 |
|
0 | 233 |
foreach ( $wp_error->get_error_codes() as $code ) { |
5 | 234 |
$severity = $wp_error->get_error_data( $code ); |
235 |
foreach ( $wp_error->get_error_messages( $code ) as $error_message ) { |
|
16 | 236 |
if ( 'message' === $severity ) { |
5 | 237 |
$messages .= ' ' . $error_message . "<br />\n"; |
9 | 238 |
} else { |
5 | 239 |
$errors .= ' ' . $error_message . "<br />\n"; |
9 | 240 |
} |
0 | 241 |
} |
242 |
} |
|
16 | 243 |
|
0 | 244 |
if ( ! empty( $errors ) ) { |
245 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
* Filters the error messages displayed above the login form. |
0 | 247 |
* |
248 |
* @since 2.1.0 |
|
249 |
* |
|
250 |
* @param string $errors Login error message. |
|
251 |
*/ |
|
252 |
echo '<div id="login_error">' . apply_filters( 'login_errors', $errors ) . "</div>\n"; |
|
253 |
} |
|
16 | 254 |
|
0 | 255 |
if ( ! empty( $messages ) ) { |
256 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
* Filters instructional messages displayed above the login form. |
0 | 258 |
* |
259 |
* @since 2.5.0 |
|
260 |
* |
|
261 |
* @param string $messages Login messages. |
|
262 |
*/ |
|
263 |
echo '<p class="message">' . apply_filters( 'login_messages', $messages ) . "</p>\n"; |
|
264 |
} |
|
265 |
} |
|
16 | 266 |
} // End of login_header(). |
0 | 267 |
|
268 |
/** |
|
269 |
* Outputs the footer for the login page. |
|
270 |
* |
|
9 | 271 |
* @since 3.1.0 |
272 |
* |
|
16 | 273 |
* @global bool|string $interim_login Whether interim login modal is being displayed. String 'success' |
274 |
* upon successful login. |
|
275 |
* |
|
9 | 276 |
* @param string $input_id Which input to auto-focus. |
0 | 277 |
*/ |
9 | 278 |
function login_footer( $input_id = '' ) { |
0 | 279 |
global $interim_login; |
280 |
||
281 |
// Don't allow interim logins to navigate away from the page. |
|
16 | 282 |
if ( ! $interim_login ) { |
9 | 283 |
?> |
16 | 284 |
<p id="backtoblog"><a href="<?php echo esc_url( home_url( '/' ) ); ?>"> |
9 | 285 |
<?php |
16 | 286 |
|
287 |
/* translators: %s: Site title. */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
288 |
printf( _x( '← Back to %s', 'site' ), get_bloginfo( 'title', 'display' ) ); |
16 | 289 |
|
9 | 290 |
?> |
16 | 291 |
</a></p> |
292 |
<?php |
|
0 | 293 |
|
16 | 294 |
the_privacy_policy_link( '<div class="privacy-policy-page-link">', '</div>' ); |
295 |
} |
|
296 |
||
297 |
?> |
|
298 |
</div><?php // End of <div id="login">. ?> |
|
0 | 299 |
|
300 |
<?php |
|
16 | 301 |
|
302 |
if ( ! empty( $input_id ) ) { |
|
303 |
?> |
|
304 |
<script type="text/javascript"> |
|
305 |
try{document.getElementById('<?php echo $input_id; ?>').focus();}catch(e){} |
|
306 |
if(typeof wpOnload=='function')wpOnload(); |
|
307 |
</script> |
|
308 |
<?php |
|
309 |
} |
|
310 |
||
0 | 311 |
/** |
312 |
* Fires in the login page footer. |
|
313 |
* |
|
314 |
* @since 3.1.0 |
|
315 |
*/ |
|
9 | 316 |
do_action( 'login_footer' ); |
16 | 317 |
|
9 | 318 |
?> |
0 | 319 |
<div class="clear"></div> |
320 |
</body> |
|
321 |
</html> |
|
322 |
<?php |
|
323 |
} |
|
324 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
/** |
9 | 326 |
* Outputs the Javascript to handle the form shaking. |
327 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
* @since 3.0.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
329 |
*/ |
0 | 330 |
function wp_shake_js() { |
9 | 331 |
?> |
16 | 332 |
<script type="text/javascript"> |
333 |
document.querySelector('form').classList.add('shake'); |
|
334 |
</script> |
|
9 | 335 |
<?php |
0 | 336 |
} |
337 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
/** |
9 | 339 |
* Outputs the viewport meta tag. |
340 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
* @since 3.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
*/ |
0 | 343 |
function wp_login_viewport_meta() { |
344 |
?> |
|
345 |
<meta name="viewport" content="width=device-width" /> |
|
346 |
<?php |
|
347 |
} |
|
348 |
||
349 |
/** |
|
350 |
* Handles sending password retrieval email to user. |
|
351 |
* |
|
9 | 352 |
* @since 2.5.0 |
353 |
* |
|
0 | 354 |
* @return bool|WP_Error True: when finish. WP_Error on error |
355 |
*/ |
|
356 |
function retrieve_password() { |
|
16 | 357 |
$errors = new WP_Error(); |
358 |
$user_data = false; |
|
0 | 359 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
if ( empty( $_POST['user_login'] ) || ! is_string( $_POST['user_login'] ) ) { |
16 | 361 |
$errors->add( 'empty_username', __( '<strong>Error</strong>: Please enter a username or email address.' ) ); |
5 | 362 |
} elseif ( strpos( $_POST['user_login'], '@' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
$user_data = get_user_by( 'email', trim( wp_unslash( $_POST['user_login'] ) ) ); |
9 | 364 |
if ( empty( $user_data ) ) { |
16 | 365 |
$errors->add( 'invalid_email', __( '<strong>Error</strong>: There is no account with that username or email address.' ) ); |
9 | 366 |
} |
0 | 367 |
} else { |
16 | 368 |
$login = trim( wp_unslash( $_POST['user_login'] ) ); |
9 | 369 |
$user_data = get_user_by( 'login', $login ); |
0 | 370 |
} |
371 |
||
372 |
/** |
|
373 |
* Fires before errors are returned from a password reset request. |
|
374 |
* |
|
375 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
* @since 4.4.0 Added the `$errors` parameter. |
16 | 377 |
* @since 5.4.0 Added the `$user_data` parameter. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
* |
16 | 379 |
* @param WP_Error $errors A WP_Error object containing any errors generated |
380 |
* by using invalid credentials. |
|
381 |
* @param WP_User|false $user_data WP_User object if found, false if the user does not exist. |
|
0 | 382 |
*/ |
16 | 383 |
do_action( 'lostpassword_post', $errors, $user_data ); |
384 |
||
385 |
/** |
|
386 |
* Filters the errors encountered on a password reset request. |
|
387 |
* |
|
388 |
* The filtered WP_Error object may, for example, contain errors for an invalid |
|
389 |
* username or email address. A WP_Error object should always be returned, |
|
390 |
* but may or may not contain errors. |
|
391 |
* |
|
392 |
* If any errors are present in $errors, this will abort the password reset request. |
|
393 |
* |
|
394 |
* @since 5.5.0 |
|
395 |
* |
|
396 |
* @param WP_Error $errors A WP_Error object containing any errors generated |
|
397 |
* by using invalid credentials. |
|
398 |
* @param WP_User|false $user_data WP_User object if found, false if the user does not exist. |
|
399 |
*/ |
|
400 |
$errors = apply_filters( 'lostpassword_errors', $errors, $user_data ); |
|
0 | 401 |
|
9 | 402 |
if ( $errors->has_errors() ) { |
0 | 403 |
return $errors; |
9 | 404 |
} |
0 | 405 |
|
9 | 406 |
if ( ! $user_data ) { |
16 | 407 |
$errors->add( 'invalidcombo', __( '<strong>Error</strong>: There is no account with that username or email address.' ) ); |
0 | 408 |
return $errors; |
409 |
} |
|
410 |
||
5 | 411 |
// Redefining user_login ensures we return the right case in the email. |
0 | 412 |
$user_login = $user_data->user_login; |
413 |
$user_email = $user_data->user_email; |
|
9 | 414 |
$key = get_password_reset_key( $user_data ); |
5 | 415 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
if ( is_wp_error( $key ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
return $key; |
5 | 418 |
} |
0 | 419 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
if ( is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
$site_name = get_network()->site_name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
} else { |
5 | 423 |
/* |
424 |
* The blogname option is escaped with esc_html on the way into the database |
|
425 |
* in sanitize_option we want to reverse this for the plain text arena of emails. |
|
426 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
$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
|
428 |
} |
0 | 429 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
$message = __( 'Someone has requested a password reset for the following account:' ) . "\r\n\r\n"; |
16 | 431 |
/* translators: %s: Site name. */ |
9 | 432 |
$message .= sprintf( __( 'Site Name: %s' ), $site_name ) . "\r\n\r\n"; |
16 | 433 |
/* translators: %s: User login. */ |
9 | 434 |
$message .= sprintf( __( 'Username: %s' ), $user_login ) . "\r\n\r\n"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
$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
|
436 |
$message .= __( 'To reset your password, visit the following address:' ) . "\r\n\r\n"; |
16 | 437 |
$message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . "\r\n"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
|
16 | 439 |
/* translators: Password reset notification email subject. %s: Site title. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
$title = sprintf( __( '[%s] Password Reset' ), $site_name ); |
0 | 441 |
|
442 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
* Filters the subject of the password reset email. |
0 | 444 |
* |
445 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
* @since 4.4.0 Added the `$user_login` and `$user_data` parameters. |
0 | 447 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
* @param string $title Default email title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
* @param string $user_login The username for the user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
* @param WP_User $user_data WP_User object. |
0 | 451 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
$title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data ); |
5 | 453 |
|
0 | 454 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
* Filters the message body of the password reset mail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
* If the filtered message is empty, the password reset email will not be sent. |
0 | 458 |
* |
459 |
* @since 2.8.0 |
|
5 | 460 |
* @since 4.1.0 Added `$user_login` and `$user_data` parameters. |
0 | 461 |
* |
5 | 462 |
* @param string $message Default mail message. |
463 |
* @param string $key The activation key. |
|
464 |
* @param string $user_login The username for the user. |
|
465 |
* @param WP_User $user_data WP_User object. |
|
0 | 466 |
*/ |
5 | 467 |
$message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data ); |
0 | 468 |
|
9 | 469 |
if ( $message && ! wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) ) { |
16 | 470 |
$errors->add( |
471 |
'retrieve_password_email_failure', |
|
472 |
sprintf( |
|
473 |
/* translators: %s: Documentation URL. */ |
|
474 |
__( '<strong>Error</strong>: The email could not be sent. Your site may not be correctly configured to send emails. <a href="%s">Get support for resetting your password</a>.' ), |
|
475 |
esc_url( __( 'https://wordpress.org/support/article/resetting-your-password/' ) ) |
|
476 |
) |
|
477 |
); |
|
478 |
return $errors; |
|
9 | 479 |
} |
0 | 480 |
|
481 |
return true; |
|
482 |
} |
|
483 |
||
484 |
// |
|
9 | 485 |
// Main. |
0 | 486 |
// |
487 |
||
9 | 488 |
$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'login'; |
0 | 489 |
$errors = new WP_Error(); |
490 |
||
9 | 491 |
if ( isset( $_GET['key'] ) ) { |
0 | 492 |
$action = 'resetpass'; |
9 | 493 |
} |
0 | 494 |
|
16 | 495 |
if ( isset( $_GET['checkemail'] ) ) { |
496 |
$action = 'checkemail'; |
|
497 |
} |
|
498 |
||
499 |
$default_actions = array( |
|
500 |
'confirm_admin_email', |
|
501 |
'postpass', |
|
502 |
'logout', |
|
503 |
'lostpassword', |
|
504 |
'retrievepassword', |
|
505 |
'resetpass', |
|
506 |
'rp', |
|
507 |
'register', |
|
508 |
'checkemail', |
|
509 |
'confirmaction', |
|
510 |
'login', |
|
511 |
WP_Recovery_Mode_Link_Service::LOGIN_ACTION_ENTERED, |
|
512 |
); |
|
513 |
||
9 | 514 |
// Validate action so as to default to the login screen. |
16 | 515 |
if ( ! in_array( $action, $default_actions, true ) && false === has_filter( 'login_form_' . $action ) ) { |
0 | 516 |
$action = 'login'; |
9 | 517 |
} |
0 | 518 |
|
519 |
nocache_headers(); |
|
520 |
||
9 | 521 |
header( 'Content-Type: ' . get_bloginfo( 'html_type' ) . '; charset=' . get_bloginfo( 'charset' ) ); |
0 | 522 |
|
16 | 523 |
if ( defined( 'RELOCATE' ) && RELOCATE ) { // Move flag is set. |
524 |
if ( isset( $_SERVER['PATH_INFO'] ) && ( $_SERVER['PATH_INFO'] !== $_SERVER['PHP_SELF'] ) ) { |
|
0 | 525 |
$_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] ); |
9 | 526 |
} |
0 | 527 |
|
9 | 528 |
$url = dirname( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) ); |
16 | 529 |
|
530 |
if ( get_option( 'siteurl' ) !== $url ) { |
|
0 | 531 |
update_option( 'siteurl', $url ); |
9 | 532 |
} |
0 | 533 |
} |
534 |
||
16 | 535 |
// 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
|
536 |
$secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) ); |
5 | 537 |
setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure ); |
16 | 538 |
|
539 |
if ( SITECOOKIEPATH !== COOKIEPATH ) { |
|
5 | 540 |
setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure ); |
9 | 541 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
|
0 | 543 |
/** |
544 |
* Fires when the login form is initialized. |
|
545 |
* |
|
546 |
* @since 3.2.0 |
|
547 |
*/ |
|
548 |
do_action( 'login_init' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
|
0 | 550 |
/** |
551 |
* Fires before a specified login form action. |
|
552 |
* |
|
5 | 553 |
* The dynamic portion of the hook name, `$action`, refers to the action |
0 | 554 |
* that brought the visitor to the login form. Actions include 'postpass', |
555 |
* 'logout', 'lostpassword', etc. |
|
556 |
* |
|
557 |
* @since 2.8.0 |
|
558 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
do_action( "login_form_{$action}" ); |
0 | 560 |
|
16 | 561 |
$http_post = ( 'POST' === $_SERVER['REQUEST_METHOD'] ); |
9 | 562 |
$interim_login = isset( $_REQUEST['interim-login'] ); |
0 | 563 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
* Filters the separator used between login form navigation links. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
568 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
* @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
|
570 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
571 |
$login_link_separator = apply_filters( 'login_link_separator', ' | ' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
|
9 | 573 |
switch ( $action ) { |
0 | 574 |
|
16 | 575 |
case 'confirm_admin_email': |
576 |
/* |
|
577 |
* Note that `is_user_logged_in()` will return false immediately after logging in |
|
578 |
* as the current user is not set, see wp-includes/pluggable.php. |
|
579 |
* However this action runs on a redirect after logging in. |
|
580 |
*/ |
|
581 |
if ( ! is_user_logged_in() ) { |
|
582 |
wp_safe_redirect( wp_login_url() ); |
|
583 |
exit; |
|
584 |
} |
|
585 |
||
586 |
if ( ! empty( $_REQUEST['redirect_to'] ) ) { |
|
587 |
$redirect_to = $_REQUEST['redirect_to']; |
|
588 |
} else { |
|
589 |
$redirect_to = admin_url(); |
|
590 |
} |
|
591 |
||
592 |
if ( current_user_can( 'manage_options' ) ) { |
|
593 |
$admin_email = get_option( 'admin_email' ); |
|
594 |
} else { |
|
595 |
wp_safe_redirect( $redirect_to ); |
|
596 |
exit; |
|
597 |
} |
|
598 |
||
599 |
/** |
|
600 |
* Filters the interval for dismissing the admin email confirmation screen. |
|
601 |
* |
|
602 |
* If `0` (zero) is returned, the "Remind me later" link will not be displayed. |
|
603 |
* |
|
604 |
* @since 5.3.1 |
|
605 |
* |
|
606 |
* @param int $interval Interval time (in seconds). Default is 3 days. |
|
607 |
*/ |
|
608 |
$remind_interval = (int) apply_filters( 'admin_email_remind_interval', 3 * DAY_IN_SECONDS ); |
|
609 |
||
610 |
if ( ! empty( $_GET['remind_me_later'] ) ) { |
|
611 |
if ( ! wp_verify_nonce( $_GET['remind_me_later'], 'remind_me_later_nonce' ) ) { |
|
612 |
wp_safe_redirect( wp_login_url() ); |
|
613 |
exit; |
|
614 |
} |
|
615 |
||
616 |
if ( $remind_interval > 0 ) { |
|
617 |
update_option( 'admin_email_lifespan', time() + $remind_interval ); |
|
618 |
} |
|
619 |
||
620 |
$redirect_to = add_query_arg( 'admin_email_remind_later', 1, $redirect_to ); |
|
621 |
wp_safe_redirect( $redirect_to ); |
|
622 |
exit; |
|
623 |
} |
|
624 |
||
625 |
if ( ! empty( $_POST['correct-admin-email'] ) ) { |
|
626 |
if ( ! check_admin_referer( 'confirm_admin_email', 'confirm_admin_email_nonce' ) ) { |
|
627 |
wp_safe_redirect( wp_login_url() ); |
|
628 |
exit; |
|
629 |
} |
|
630 |
||
631 |
/** |
|
632 |
* Filters the interval for redirecting the user to the admin email confirmation screen. |
|
633 |
* |
|
634 |
* If `0` (zero) is returned, the user will not be redirected. |
|
635 |
* |
|
636 |
* @since 5.3.0 |
|
637 |
* |
|
638 |
* @param int $interval Interval time (in seconds). Default is 6 months. |
|
639 |
*/ |
|
640 |
$admin_email_check_interval = (int) apply_filters( 'admin_email_check_interval', 6 * MONTH_IN_SECONDS ); |
|
641 |
||
642 |
if ( $admin_email_check_interval > 0 ) { |
|
643 |
update_option( 'admin_email_lifespan', time() + $admin_email_check_interval ); |
|
644 |
} |
|
645 |
||
646 |
wp_safe_redirect( $redirect_to ); |
|
647 |
exit; |
|
648 |
} |
|
649 |
||
650 |
login_header( __( 'Confirm your administration email' ), '', $errors ); |
|
651 |
||
652 |
/** |
|
653 |
* Fires before the admin email confirm form. |
|
654 |
* |
|
655 |
* @since 5.3.0 |
|
656 |
* |
|
657 |
* @param WP_Error $errors A `WP_Error` object containing any errors generated by using invalid |
|
658 |
* credentials. Note that the error object may not contain any errors. |
|
659 |
*/ |
|
660 |
do_action( 'admin_email_confirm', $errors ); |
|
661 |
||
662 |
?> |
|
663 |
||
664 |
<form class="admin-email-confirm-form" name="admin-email-confirm-form" action="<?php echo esc_url( site_url( 'wp-login.php?action=confirm_admin_email', 'login_post' ) ); ?>" method="post"> |
|
665 |
<?php |
|
666 |
/** |
|
667 |
* Fires inside the admin-email-confirm-form form tags, before the hidden fields. |
|
668 |
* |
|
669 |
* @since 5.3.0 |
|
670 |
*/ |
|
671 |
do_action( 'admin_email_confirm_form' ); |
|
672 |
||
673 |
wp_nonce_field( 'confirm_admin_email', 'confirm_admin_email_nonce' ); |
|
674 |
||
675 |
?> |
|
676 |
<input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" /> |
|
677 |
||
678 |
<h1 class="admin-email__heading"> |
|
679 |
<?php _e( 'Administration email verification' ); ?> |
|
680 |
</h1> |
|
681 |
<p class="admin-email__details"> |
|
682 |
<?php _e( 'Please verify that the <strong>administration email</strong> for this website is still correct.' ); ?> |
|
683 |
<?php |
|
684 |
||
685 |
/* translators: URL to the WordPress help section about admin email. */ |
|
686 |
$admin_email_help_url = __( 'https://wordpress.org/support/article/settings-general-screen/#email-address' ); |
|
687 |
||
688 |
/* translators: accessibility text */ |
|
689 |
$accessibility_text = sprintf( '<span class="screen-reader-text"> %s</span>', __( '(opens in a new tab)' ) ); |
|
690 |
||
691 |
printf( |
|
692 |
'<a href="%s" rel="noopener noreferrer" target="_blank">%s%s</a>', |
|
693 |
esc_url( $admin_email_help_url ), |
|
694 |
__( 'Why is this important?' ), |
|
695 |
$accessibility_text |
|
696 |
); |
|
697 |
||
698 |
?> |
|
699 |
</p> |
|
700 |
<p class="admin-email__details"> |
|
701 |
<?php |
|
702 |
||
703 |
printf( |
|
704 |
/* translators: %s: Admin email address. */ |
|
705 |
__( 'Current administration email: %s' ), |
|
706 |
'<strong>' . esc_html( $admin_email ) . '</strong>' |
|
707 |
); |
|
708 |
||
709 |
?> |
|
710 |
</p> |
|
711 |
<p class="admin-email__details"> |
|
712 |
<?php _e( 'This email may be different from your personal email address.' ); ?> |
|
713 |
</p> |
|
714 |
||
715 |
<div class="admin-email__actions"> |
|
716 |
<div class="admin-email__actions-primary"> |
|
717 |
<?php |
|
718 |
||
719 |
$change_link = admin_url( 'options-general.php' ); |
|
720 |
$change_link = add_query_arg( 'highlight', 'confirm_admin_email', $change_link ); |
|
721 |
||
722 |
?> |
|
723 |
<a class="button button-large" href="<?php echo esc_url( $change_link ); ?>"><?php _e( 'Update' ); ?></a> |
|
724 |
<input type="submit" name="correct-admin-email" id="correct-admin-email" class="button button-primary button-large" value="<?php esc_attr_e( 'The email is correct' ); ?>" /> |
|
725 |
</div> |
|
726 |
<?php if ( $remind_interval > 0 ) : ?> |
|
727 |
<div class="admin-email__actions-secondary"> |
|
728 |
<?php |
|
729 |
||
730 |
$remind_me_link = wp_login_url( $redirect_to ); |
|
731 |
$remind_me_link = add_query_arg( |
|
732 |
array( |
|
733 |
'action' => 'confirm_admin_email', |
|
734 |
'remind_me_later' => wp_create_nonce( 'remind_me_later_nonce' ), |
|
735 |
), |
|
736 |
$remind_me_link |
|
737 |
); |
|
738 |
||
739 |
?> |
|
740 |
<a href="<?php echo esc_url( $remind_me_link ); ?>"><?php _e( 'Remind me later' ); ?></a> |
|
741 |
</div> |
|
742 |
<?php endif; ?> |
|
743 |
</div> |
|
744 |
</form> |
|
745 |
||
746 |
<?php |
|
747 |
||
748 |
login_footer(); |
|
749 |
break; |
|
750 |
||
9 | 751 |
case 'postpass': |
752 |
if ( ! array_key_exists( 'post_password', $_POST ) ) { |
|
753 |
wp_safe_redirect( wp_get_referer() ); |
|
16 | 754 |
exit; |
0 | 755 |
} |
9 | 756 |
|
757 |
require_once ABSPATH . WPINC . '/class-phpass.php'; |
|
758 |
$hasher = new PasswordHash( 8, true ); |
|
0 | 759 |
|
9 | 760 |
/** |
761 |
* Filters the life span of the post password cookie. |
|
762 |
* |
|
763 |
* By default, the cookie expires 10 days from creation. To turn this |
|
764 |
* into a session cookie, return 0. |
|
765 |
* |
|
766 |
* @since 3.7.0 |
|
767 |
* |
|
768 |
* @param int $expires The expiry time, as passed to setcookie(). |
|
769 |
*/ |
|
770 |
$expire = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS ); |
|
771 |
$referer = wp_get_referer(); |
|
16 | 772 |
|
9 | 773 |
if ( $referer ) { |
774 |
$secure = ( 'https' === parse_url( $referer, PHP_URL_SCHEME ) ); |
|
775 |
} else { |
|
776 |
$secure = false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
777 |
} |
16 | 778 |
|
9 | 779 |
setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure ); |
780 |
||
781 |
wp_safe_redirect( wp_get_referer() ); |
|
16 | 782 |
exit; |
9 | 783 |
|
784 |
case 'logout': |
|
785 |
check_admin_referer( 'log-out' ); |
|
786 |
||
787 |
$user = wp_get_current_user(); |
|
788 |
||
789 |
wp_logout(); |
|
790 |
||
791 |
if ( ! empty( $_REQUEST['redirect_to'] ) ) { |
|
16 | 792 |
$redirect_to = $_REQUEST['redirect_to']; |
793 |
$requested_redirect_to = $redirect_to; |
|
9 | 794 |
} else { |
16 | 795 |
$redirect_to = add_query_arg( |
796 |
array( |
|
797 |
'loggedout' => 'true', |
|
798 |
'wp_lang' => get_user_locale( $user ), |
|
799 |
), |
|
800 |
wp_login_url() |
|
801 |
); |
|
802 |
||
9 | 803 |
$requested_redirect_to = ''; |
804 |
} |
|
0 | 805 |
|
9 | 806 |
/** |
807 |
* Filters the log out redirect URL. |
|
808 |
* |
|
809 |
* @since 4.2.0 |
|
810 |
* |
|
811 |
* @param string $redirect_to The redirect destination URL. |
|
812 |
* @param string $requested_redirect_to The requested redirect destination URL passed as a parameter. |
|
813 |
* @param WP_User $user The WP_User object for the user that's logging out. |
|
814 |
*/ |
|
815 |
$redirect_to = apply_filters( 'logout_redirect', $redirect_to, $requested_redirect_to, $user ); |
|
16 | 816 |
|
9 | 817 |
wp_safe_redirect( $redirect_to ); |
16 | 818 |
exit; |
9 | 819 |
|
820 |
case 'lostpassword': |
|
821 |
case 'retrievepassword': |
|
822 |
if ( $http_post ) { |
|
823 |
$errors = retrieve_password(); |
|
16 | 824 |
|
9 | 825 |
if ( ! is_wp_error( $errors ) ) { |
826 |
$redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?checkemail=confirm'; |
|
827 |
wp_safe_redirect( $redirect_to ); |
|
16 | 828 |
exit; |
9 | 829 |
} |
830 |
} |
|
831 |
||
832 |
if ( isset( $_GET['error'] ) ) { |
|
16 | 833 |
if ( 'invalidkey' === $_GET['error'] ) { |
9 | 834 |
$errors->add( 'invalidkey', __( 'Your password reset link appears to be invalid. Please request a new link below.' ) ); |
16 | 835 |
} elseif ( 'expiredkey' === $_GET['error'] ) { |
9 | 836 |
$errors->add( 'expiredkey', __( 'Your password reset link has expired. Please request a new link below.' ) ); |
837 |
} |
|
838 |
} |
|
0 | 839 |
|
9 | 840 |
$lostpassword_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; |
841 |
/** |
|
842 |
* Filters the URL redirected to after submitting the lostpassword/retrievepassword form. |
|
843 |
* |
|
844 |
* @since 3.0.0 |
|
845 |
* |
|
846 |
* @param string $lostpassword_redirect The redirect destination URL. |
|
847 |
*/ |
|
848 |
$redirect_to = apply_filters( 'lostpassword_redirect', $lostpassword_redirect ); |
|
0 | 849 |
|
9 | 850 |
/** |
851 |
* Fires before the lost password form. |
|
852 |
* |
|
853 |
* @since 1.5.1 |
|
854 |
* @since 5.1.0 Added the `$errors` parameter. |
|
855 |
* |
|
856 |
* @param WP_Error $errors A `WP_Error` object containing any errors generated by using invalid |
|
857 |
* credentials. Note that the error object may not contain any errors. |
|
858 |
*/ |
|
859 |
do_action( 'lost_password', $errors ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
|
16 | 861 |
login_header( __( 'Lost Password' ), '<p class="message">' . __( 'Please enter your username or email address. You will receive an email message with instructions on how to reset your password.' ) . '</p>', $errors ); |
9 | 862 |
|
863 |
$user_login = ''; |
|
0 | 864 |
|
9 | 865 |
if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) { |
866 |
$user_login = wp_unslash( $_POST['user_login'] ); |
|
867 |
} |
|
0 | 868 |
|
9 | 869 |
?> |
870 |
||
16 | 871 |
<form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post"> |
872 |
<p> |
|
873 |
<label for="user_login"><?php _e( 'Username or Email Address' ); ?></label> |
|
874 |
<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" autocapitalize="off" /> |
|
875 |
</p> |
|
876 |
<?php |
|
877 |
||
878 |
/** |
|
879 |
* Fires inside the lostpassword form tags, before the hidden fields. |
|
880 |
* |
|
881 |
* @since 2.1.0 |
|
882 |
*/ |
|
883 |
do_action( 'lostpassword_form' ); |
|
0 | 884 |
|
16 | 885 |
?> |
886 |
<input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" /> |
|
887 |
<p class="submit"> |
|
888 |
<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Get New Password' ); ?>" /> |
|
889 |
</p> |
|
890 |
</form> |
|
5 | 891 |
|
16 | 892 |
<p id="nav"> |
893 |
<a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a> |
|
894 |
<?php |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
|
16 | 896 |
if ( get_option( 'users_can_register' ) ) { |
897 |
$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ); |
|
898 |
||
899 |
echo esc_html( $login_link_separator ); |
|
0 | 900 |
|
16 | 901 |
/** This filter is documented in wp-includes/general-template.php */ |
902 |
echo apply_filters( 'register', $registration_url ); |
|
903 |
} |
|
904 |
||
905 |
?> |
|
906 |
</p> |
|
9 | 907 |
<?php |
16 | 908 |
|
9 | 909 |
login_footer( 'user_login' ); |
910 |
break; |
|
0 | 911 |
|
9 | 912 |
case 'resetpass': |
913 |
case 'rp': |
|
914 |
list( $rp_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) ); |
|
915 |
$rp_cookie = 'wp-resetpass-' . COOKIEHASH; |
|
16 | 916 |
|
9 | 917 |
if ( isset( $_GET['key'] ) ) { |
918 |
$value = sprintf( '%s:%s', wp_unslash( $_GET['login'] ), wp_unslash( $_GET['key'] ) ); |
|
919 |
setcookie( $rp_cookie, $value, 0, $rp_path, COOKIE_DOMAIN, is_ssl(), true ); |
|
16 | 920 |
|
9 | 921 |
wp_safe_redirect( remove_query_arg( array( 'key', 'login' ) ) ); |
922 |
exit; |
|
923 |
} |
|
0 | 924 |
|
9 | 925 |
if ( isset( $_COOKIE[ $rp_cookie ] ) && 0 < strpos( $_COOKIE[ $rp_cookie ], ':' ) ) { |
926 |
list( $rp_login, $rp_key ) = explode( ':', wp_unslash( $_COOKIE[ $rp_cookie ] ), 2 ); |
|
16 | 927 |
|
928 |
$user = check_password_reset_key( $rp_key, $rp_login ); |
|
929 |
||
9 | 930 |
if ( isset( $_POST['pass1'] ) && ! hash_equals( $rp_key, $_POST['rp_key'] ) ) { |
931 |
$user = false; |
|
932 |
} |
|
933 |
} else { |
|
5 | 934 |
$user = false; |
935 |
} |
|
936 |
||
9 | 937 |
if ( ! $user || is_wp_error( $user ) ) { |
938 |
setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true ); |
|
16 | 939 |
|
9 | 940 |
if ( $user && $user->get_error_code() === 'expired_key' ) { |
941 |
wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=expiredkey' ) ); |
|
942 |
} else { |
|
943 |
wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=invalidkey' ) ); |
|
944 |
} |
|
16 | 945 |
|
9 | 946 |
exit; |
947 |
} |
|
0 | 948 |
|
9 | 949 |
$errors = new WP_Error(); |
0 | 950 |
|
16 | 951 |
if ( isset( $_POST['pass1'] ) && $_POST['pass1'] !== $_POST['pass2'] ) { |
9 | 952 |
$errors->add( 'password_reset_mismatch', __( 'The passwords do not match.' ) ); |
953 |
} |
|
0 | 954 |
|
9 | 955 |
/** |
956 |
* Fires before the password reset procedure is validated. |
|
957 |
* |
|
958 |
* @since 3.5.0 |
|
959 |
* |
|
16 | 960 |
* @param WP_Error $errors WP Error object. |
9 | 961 |
* @param WP_User|WP_Error $user WP_User object if the login and reset key match. WP_Error object otherwise. |
962 |
*/ |
|
963 |
do_action( 'validate_password_reset', $errors, $user ); |
|
0 | 964 |
|
9 | 965 |
if ( ( ! $errors->has_errors() ) && isset( $_POST['pass1'] ) && ! empty( $_POST['pass1'] ) ) { |
966 |
reset_password( $user, $_POST['pass1'] ); |
|
967 |
setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true ); |
|
968 |
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>' ); |
|
969 |
login_footer(); |
|
970 |
exit; |
|
971 |
} |
|
0 | 972 |
|
9 | 973 |
wp_enqueue_script( 'utils' ); |
974 |
wp_enqueue_script( 'user-profile' ); |
|
0 | 975 |
|
9 | 976 |
login_header( __( 'Reset Password' ), '<p class="message reset-pass">' . __( 'Enter your new password below.' ) . '</p>', $errors ); |
0 | 977 |
|
9 | 978 |
?> |
16 | 979 |
<form name="resetpassform" id="resetpassform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=resetpass', 'login_post' ) ); ?>" method="post" autocomplete="off"> |
980 |
<input type="hidden" id="user_login" value="<?php echo esc_attr( $rp_login ); ?>" autocomplete="off" /> |
|
981 |
||
982 |
<div class="user-pass1-wrap"> |
|
983 |
<p> |
|
984 |
<label for="pass1"><?php _e( 'New password' ); ?></label> |
|
985 |
</p> |
|
0 | 986 |
|
16 | 987 |
<div class="wp-pwd"> |
988 |
<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" /> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
989 |
|
16 | 990 |
<button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>"> |
991 |
<span class="dashicons dashicons-hidden" aria-hidden="true"></span> |
|
992 |
</button> |
|
993 |
<div id="pass-strength-result" class="hide-if-no-js" aria-live="polite"><?php _e( 'Strength indicator' ); ?></div> |
|
994 |
</div> |
|
995 |
<div class="pw-weak"> |
|
996 |
<input type="checkbox" name="pw_weak" id="pw-weak" class="pw-checkbox" /> |
|
997 |
<label for="pw-weak"><?php _e( 'Confirm use of weak password' ); ?></label> |
|
998 |
</div> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
</div> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
|
16 | 1001 |
<p class="user-pass2-wrap"> |
1002 |
<label for="pass2"><?php _e( 'Confirm new password' ); ?></label> |
|
1003 |
<input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" /> |
|
1004 |
</p> |
|
1005 |
||
1006 |
<p class="description indicator-hint"><?php echo wp_get_password_hint(); ?></p> |
|
1007 |
<br class="clear" /> |
|
1008 |
||
1009 |
<?php |
|
0 | 1010 |
|
16 | 1011 |
/** |
1012 |
* Fires following the 'Strength indicator' meter in the user password reset form. |
|
1013 |
* |
|
1014 |
* @since 3.9.0 |
|
1015 |
* |
|
1016 |
* @param WP_User $user User object of the user whose password is being reset. |
|
1017 |
*/ |
|
1018 |
do_action( 'resetpass_form', $user ); |
|
0 | 1019 |
|
16 | 1020 |
?> |
1021 |
<input type="hidden" name="rp_key" value="<?php echo esc_attr( $rp_key ); ?>" /> |
|
1022 |
<p class="submit"> |
|
1023 |
<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Reset Password' ); ?>" /> |
|
1024 |
</p> |
|
1025 |
</form> |
|
9 | 1026 |
|
16 | 1027 |
<p id="nav"> |
1028 |
<a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a> |
|
1029 |
<?php |
|
9 | 1030 |
|
16 | 1031 |
if ( get_option( 'users_can_register' ) ) { |
1032 |
$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ); |
|
1033 |
||
1034 |
echo esc_html( $login_link_separator ); |
|
0 | 1035 |
|
16 | 1036 |
/** This filter is documented in wp-includes/general-template.php */ |
1037 |
echo apply_filters( 'register', $registration_url ); |
|
1038 |
} |
|
9 | 1039 |
|
16 | 1040 |
?> |
1041 |
</p> |
|
9 | 1042 |
<?php |
16 | 1043 |
|
9 | 1044 |
login_footer( 'user_pass' ); |
1045 |
break; |
|
5 | 1046 |
|
9 | 1047 |
case 'register': |
1048 |
if ( is_multisite() ) { |
|
1049 |
/** |
|
1050 |
* Filters the Multisite sign up URL. |
|
1051 |
* |
|
1052 |
* @since 3.0.0 |
|
1053 |
* |
|
1054 |
* @param string $sign_up_url The sign up URL. |
|
1055 |
*/ |
|
1056 |
wp_redirect( apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ) ); |
|
1057 |
exit; |
|
1058 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
|
9 | 1060 |
if ( ! get_option( 'users_can_register' ) ) { |
1061 |
wp_redirect( site_url( 'wp-login.php?registration=disabled' ) ); |
|
16 | 1062 |
exit; |
9 | 1063 |
} |
0 | 1064 |
|
9 | 1065 |
$user_login = ''; |
1066 |
$user_email = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1067 |
|
9 | 1068 |
if ( $http_post ) { |
1069 |
if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) { |
|
16 | 1070 |
$user_login = wp_unslash( $_POST['user_login'] ); |
9 | 1071 |
} |
1072 |
||
1073 |
if ( isset( $_POST['user_email'] ) && is_string( $_POST['user_email'] ) ) { |
|
1074 |
$user_email = wp_unslash( $_POST['user_email'] ); |
|
1075 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
|
9 | 1077 |
$errors = register_new_user( $user_login, $user_email ); |
16 | 1078 |
|
9 | 1079 |
if ( ! is_wp_error( $errors ) ) { |
1080 |
$redirect_to = ! empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : 'wp-login.php?checkemail=registered'; |
|
1081 |
wp_safe_redirect( $redirect_to ); |
|
16 | 1082 |
exit; |
9 | 1083 |
} |
1084 |
} |
|
0 | 1085 |
|
9 | 1086 |
$registration_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; |
16 | 1087 |
|
0 | 1088 |
/** |
9 | 1089 |
* Filters the registration redirect URL. |
0 | 1090 |
* |
1091 |
* @since 3.0.0 |
|
1092 |
* |
|
9 | 1093 |
* @param string $registration_redirect The redirect destination URL. |
0 | 1094 |
*/ |
9 | 1095 |
$redirect_to = apply_filters( 'registration_redirect', $registration_redirect ); |
16 | 1096 |
|
9 | 1097 |
login_header( __( 'Registration Form' ), '<p class="message register">' . __( 'Register For This Site' ) . '</p>', $errors ); |
16 | 1098 |
|
9 | 1099 |
?> |
16 | 1100 |
<form name="registerform" id="registerform" action="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login_post' ) ); ?>" method="post" novalidate="novalidate"> |
1101 |
<p> |
|
1102 |
<label for="user_login"><?php _e( 'Username' ); ?></label> |
|
1103 |
<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr( wp_unslash( $user_login ) ); ?>" size="20" autocapitalize="off" /> |
|
1104 |
</p> |
|
1105 |
<p> |
|
1106 |
<label for="user_email"><?php _e( 'Email' ); ?></label> |
|
1107 |
<input type="email" name="user_email" id="user_email" class="input" value="<?php echo esc_attr( wp_unslash( $user_email ) ); ?>" size="25" /> |
|
1108 |
</p> |
|
1109 |
<?php |
|
1110 |
||
1111 |
/** |
|
1112 |
* Fires following the 'Email' field in the user registration form. |
|
1113 |
* |
|
1114 |
* @since 2.1.0 |
|
1115 |
*/ |
|
1116 |
do_action( 'register_form' ); |
|
1117 |
||
1118 |
?> |
|
1119 |
<p id="reg_passmail"> |
|
1120 |
<?php _e( 'Registration confirmation will be emailed to you.' ); ?> |
|
1121 |
</p> |
|
1122 |
<br class="clear" /> |
|
1123 |
<input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" /> |
|
1124 |
<p class="submit"> |
|
1125 |
<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Register' ); ?>" /> |
|
1126 |
</p> |
|
1127 |
</form> |
|
1128 |
||
1129 |
<p id="nav"> |
|
1130 |
<a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a> |
|
1131 |
<?php echo esc_html( $login_link_separator ); ?> |
|
1132 |
<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a> |
|
1133 |
</p> |
|
9 | 1134 |
<?php |
16 | 1135 |
|
1136 |
login_footer( 'user_login' ); |
|
1137 |
break; |
|
1138 |
||
1139 |
case 'checkemail': |
|
1140 |
$redirect_to = admin_url(); |
|
1141 |
$errors = new WP_Error(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
|
16 | 1143 |
if ( 'confirm' === $_GET['checkemail'] ) { |
1144 |
$errors->add( |
|
1145 |
'confirm', |
|
1146 |
sprintf( |
|
1147 |
/* translators: %s: Link to the login page. */ |
|
1148 |
__( 'Check your email for the confirmation link, then visit the <a href="%s">login page</a>.' ), |
|
1149 |
wp_login_url() |
|
1150 |
), |
|
1151 |
'message' |
|
1152 |
); |
|
1153 |
} elseif ( 'registered' === $_GET['checkemail'] ) { |
|
1154 |
$errors->add( |
|
1155 |
'registered', |
|
1156 |
sprintf( |
|
1157 |
/* translators: %s: Link to the login page. */ |
|
1158 |
__( 'Registration complete. Please check your email, then visit the <a href="%s">login page</a>.' ), |
|
1159 |
wp_login_url() |
|
1160 |
), |
|
1161 |
'message' |
|
1162 |
); |
|
1163 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
|
16 | 1165 |
/** This action is documented in wp-login.php */ |
1166 |
$errors = apply_filters( 'wp_login_errors', $errors, $redirect_to ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1167 |
|
16 | 1168 |
login_header( __( 'Check your email' ), '', $errors ); |
1169 |
login_footer(); |
|
9 | 1170 |
break; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
|
9 | 1172 |
case 'confirmaction': |
1173 |
if ( ! isset( $_GET['request_id'] ) ) { |
|
1174 |
wp_die( __( 'Missing request ID.' ) ); |
|
1175 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
|
9 | 1177 |
if ( ! isset( $_GET['confirm_key'] ) ) { |
1178 |
wp_die( __( 'Missing confirm key.' ) ); |
|
1179 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1180 |
|
9 | 1181 |
$request_id = (int) $_GET['request_id']; |
1182 |
$key = sanitize_text_field( wp_unslash( $_GET['confirm_key'] ) ); |
|
1183 |
$result = wp_validate_user_request_key( $request_id, $key ); |
|
0 | 1184 |
|
9 | 1185 |
if ( is_wp_error( $result ) ) { |
1186 |
wp_die( $result ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1187 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
|
9 | 1189 |
/** |
1190 |
* Fires an action hook when the account action has been confirmed by the user. |
|
1191 |
* |
|
1192 |
* Using this you can assume the user has agreed to perform the action by |
|
1193 |
* clicking on the link in the confirmation email. |
|
1194 |
* |
|
1195 |
* After firing this action hook the page will redirect to wp-login a callback |
|
1196 |
* redirects or exits first. |
|
1197 |
* |
|
1198 |
* @since 4.9.6 |
|
1199 |
* |
|
1200 |
* @param int $request_id Request ID. |
|
1201 |
*/ |
|
1202 |
do_action( 'user_request_action_confirmed', $request_id ); |
|
1203 |
||
1204 |
$message = _wp_privacy_account_request_confirmed_message( $request_id ); |
|
1205 |
||
1206 |
login_header( __( 'User action confirmed.' ), $message ); |
|
1207 |
login_footer(); |
|
1208 |
exit; |
|
1209 |
||
1210 |
case 'login': |
|
1211 |
default: |
|
1212 |
$secure_cookie = ''; |
|
1213 |
$customize_login = isset( $_REQUEST['customize-login'] ); |
|
16 | 1214 |
|
9 | 1215 |
if ( $customize_login ) { |
1216 |
wp_enqueue_script( 'customize-base' ); |
|
1217 |
} |
|
1218 |
||
1219 |
// If the user wants SSL but the session is not SSL, force a secure cookie. |
|
1220 |
if ( ! empty( $_POST['log'] ) && ! force_ssl_admin() ) { |
|
16 | 1221 |
$user_name = sanitize_user( wp_unslash( $_POST['log'] ) ); |
9 | 1222 |
$user = get_user_by( 'login', $user_name ); |
1223 |
||
1224 |
if ( ! $user && strpos( $user_name, '@' ) ) { |
|
1225 |
$user = get_user_by( 'email', $user_name ); |
|
1226 |
} |
|
1227 |
||
1228 |
if ( $user ) { |
|
1229 |
if ( get_user_option( 'use_ssl', $user->ID ) ) { |
|
1230 |
$secure_cookie = true; |
|
1231 |
force_ssl_admin( true ); |
|
1232 |
} |
|
1233 |
} |
|
1234 |
} |
|
1235 |
||
1236 |
if ( isset( $_REQUEST['redirect_to'] ) ) { |
|
1237 |
$redirect_to = $_REQUEST['redirect_to']; |
|
1238 |
// Redirect to HTTPS if user wants SSL. |
|
1239 |
if ( $secure_cookie && false !== strpos( $redirect_to, 'wp-admin' ) ) { |
|
1240 |
$redirect_to = preg_replace( '|^http://|', 'https://', $redirect_to ); |
|
1241 |
} |
|
1242 |
} else { |
|
1243 |
$redirect_to = admin_url(); |
|
1244 |
} |
|
1245 |
||
1246 |
$reauth = empty( $_REQUEST['reauth'] ) ? false : true; |
|
1247 |
||
1248 |
$user = wp_signon( array(), $secure_cookie ); |
|
1249 |
||
1250 |
if ( empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) { |
|
1251 |
if ( headers_sent() ) { |
|
1252 |
$user = new WP_Error( |
|
1253 |
'test_cookie', |
|
1254 |
sprintf( |
|
16 | 1255 |
/* translators: 1: Browser cookie documentation URL, 2: Support forums URL. */ |
1256 |
__( '<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>.' ), |
|
9 | 1257 |
__( 'https://wordpress.org/support/article/cookies/' ), |
16 | 1258 |
__( 'https://wordpress.org/support/forums/' ) |
9 | 1259 |
) |
1260 |
); |
|
1261 |
} elseif ( isset( $_POST['testcookie'] ) && empty( $_COOKIE[ TEST_COOKIE ] ) ) { |
|
16 | 1262 |
// If cookies are disabled, we can't log in even with a valid user and password. |
9 | 1263 |
$user = new WP_Error( |
1264 |
'test_cookie', |
|
1265 |
sprintf( |
|
16 | 1266 |
/* translators: %s: Browser cookie documentation URL. */ |
1267 |
__( '<strong>Error</strong>: Cookies are blocked or not supported by your browser. You must <a href="%s">enable cookies</a> to use WordPress.' ), |
|
9 | 1268 |
__( 'https://wordpress.org/support/article/cookies/#enable-cookies-in-your-browser' ) |
1269 |
) |
|
1270 |
); |
|
0 | 1271 |
} |
1272 |
} |
|
1273 |
||
9 | 1274 |
$requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; |
1275 |
/** |
|
1276 |
* Filters the login redirect URL. |
|
1277 |
* |
|
1278 |
* @since 3.0.0 |
|
1279 |
* |
|
1280 |
* @param string $redirect_to The redirect destination URL. |
|
1281 |
* @param string $requested_redirect_to The requested redirect destination URL passed as a parameter. |
|
1282 |
* @param WP_User|WP_Error $user WP_User object if login was successful, WP_Error object otherwise. |
|
1283 |
*/ |
|
1284 |
$redirect_to = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $user ); |
|
0 | 1285 |
|
9 | 1286 |
if ( ! is_wp_error( $user ) && ! $reauth ) { |
1287 |
if ( $interim_login ) { |
|
1288 |
$message = '<p class="message">' . __( 'You have logged in successfully.' ) . '</p>'; |
|
1289 |
$interim_login = 'success'; |
|
1290 |
login_header( '', $message ); |
|
16 | 1291 |
|
9 | 1292 |
?> |
1293 |
</div> |
|
1294 |
<?php |
|
16 | 1295 |
|
9 | 1296 |
/** This action is documented in wp-login.php */ |
1297 |
do_action( 'login_footer' ); |
|
16 | 1298 |
|
1299 |
if ( $customize_login ) { |
|
1300 |
?> |
|
1301 |
<script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo wp_customize_url(); ?>', channel: 'login' }).send('login') }, 1000 );</script> |
|
1302 |
<?php |
|
1303 |
} |
|
1304 |
||
9 | 1305 |
?> |
1306 |
</body></html> |
|
1307 |
<?php |
|
16 | 1308 |
|
9 | 1309 |
exit; |
1310 |
} |
|
1311 |
||
16 | 1312 |
// Check if it is time to add a redirect to the admin email confirmation screen. |
1313 |
if ( is_a( $user, 'WP_User' ) && $user->exists() && $user->has_cap( 'manage_options' ) ) { |
|
1314 |
$admin_email_lifespan = (int) get_option( 'admin_email_lifespan' ); |
|
1315 |
||
1316 |
// If `0` (or anything "falsey" as it is cast to int) is returned, the user will not be redirected |
|
1317 |
// to the admin email confirmation screen. |
|
1318 |
/** This filter is documented in wp-login.php */ |
|
1319 |
$admin_email_check_interval = (int) apply_filters( 'admin_email_check_interval', 6 * MONTH_IN_SECONDS ); |
|
1320 |
||
1321 |
if ( $admin_email_check_interval > 0 && time() > $admin_email_lifespan ) { |
|
1322 |
$redirect_to = add_query_arg( |
|
1323 |
array( |
|
1324 |
'action' => 'confirm_admin_email', |
|
1325 |
'wp_lang' => get_user_locale( $user ), |
|
1326 |
), |
|
1327 |
wp_login_url( $redirect_to ) |
|
1328 |
); |
|
1329 |
} |
|
1330 |
} |
|
1331 |
||
1332 |
if ( ( empty( $redirect_to ) || 'wp-admin/' === $redirect_to || admin_url() === $redirect_to ) ) { |
|
9 | 1333 |
// 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. |
1334 |
if ( is_multisite() && ! get_active_blog_for_user( $user->ID ) && ! is_super_admin( $user->ID ) ) { |
|
1335 |
$redirect_to = user_admin_url(); |
|
1336 |
} elseif ( is_multisite() && ! $user->has_cap( 'read' ) ) { |
|
1337 |
$redirect_to = get_dashboard_url( $user->ID ); |
|
1338 |
} elseif ( ! $user->has_cap( 'edit_posts' ) ) { |
|
1339 |
$redirect_to = $user->has_cap( 'read' ) ? admin_url( 'profile.php' ) : home_url(); |
|
1340 |
} |
|
1341 |
||
1342 |
wp_redirect( $redirect_to ); |
|
16 | 1343 |
exit; |
9 | 1344 |
} |
16 | 1345 |
|
9 | 1346 |
wp_safe_redirect( $redirect_to ); |
16 | 1347 |
exit; |
9 | 1348 |
} |
1349 |
||
1350 |
$errors = $user; |
|
1351 |
// Clear errors if loggedout is set. |
|
1352 |
if ( ! empty( $_GET['loggedout'] ) || $reauth ) { |
|
1353 |
$errors = new WP_Error(); |
|
0 | 1354 |
} |
1355 |
||
9 | 1356 |
if ( empty( $_POST ) && $errors->get_error_codes() === array( 'empty_username', 'empty_password' ) ) { |
1357 |
$errors = new WP_Error( '', '' ); |
|
1358 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1359 |
|
9 | 1360 |
if ( $interim_login ) { |
1361 |
if ( ! $errors->has_errors() ) { |
|
1362 |
$errors->add( 'expired', __( 'Your session has expired. Please log in to continue where you left off.' ), 'message' ); |
|
1363 |
} |
|
1364 |
} else { |
|
1365 |
// Some parts of this script use the main login form to display a message. |
|
16 | 1366 |
if ( isset( $_GET['loggedout'] ) && $_GET['loggedout'] ) { |
9 | 1367 |
$errors->add( 'loggedout', __( 'You are now logged out.' ), 'message' ); |
16 | 1368 |
} elseif ( isset( $_GET['registration'] ) && 'disabled' === $_GET['registration'] ) { |
9 | 1369 |
$errors->add( 'registerdisabled', __( 'User registration is currently not allowed.' ) ); |
1370 |
} elseif ( strpos( $redirect_to, 'about.php?updated' ) ) { |
|
1371 |
$errors->add( 'updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to see what’s new.' ), 'message' ); |
|
1372 |
} elseif ( WP_Recovery_Mode_Link_Service::LOGIN_ACTION_ENTERED === $action ) { |
|
1373 |
$errors->add( 'enter_recovery_mode', __( 'Recovery Mode Initialized. Please log in to continue.' ), 'message' ); |
|
1374 |
} |
|
0 | 1375 |
} |
1376 |
||
9 | 1377 |
/** |
1378 |
* Filters the login page errors. |
|
1379 |
* |
|
1380 |
* @since 3.6.0 |
|
1381 |
* |
|
16 | 1382 |
* @param WP_Error $errors WP Error object. |
1383 |
* @param string $redirect_to Redirect destination URL. |
|
9 | 1384 |
*/ |
1385 |
$errors = apply_filters( 'wp_login_errors', $errors, $redirect_to ); |
|
1386 |
||
1387 |
// Clear any stale cookies. |
|
1388 |
if ( $reauth ) { |
|
1389 |
wp_clear_auth_cookie(); |
|
1390 |
} |
|
0 | 1391 |
|
9 | 1392 |
login_header( __( 'Log In' ), '', $errors ); |
0 | 1393 |
|
9 | 1394 |
if ( isset( $_POST['log'] ) ) { |
16 | 1395 |
$user_login = ( 'incorrect_password' === $errors->get_error_code() || 'empty_password' === $errors->get_error_code() ) ? esc_attr( wp_unslash( $_POST['log'] ) ) : ''; |
9 | 1396 |
} |
16 | 1397 |
|
9 | 1398 |
$rememberme = ! empty( $_POST['rememberme'] ); |
0 | 1399 |
|
9 | 1400 |
if ( $errors->has_errors() ) { |
1401 |
$aria_describedby_error = ' aria-describedby="login_error"'; |
|
1402 |
} else { |
|
1403 |
$aria_describedby_error = ''; |
|
1404 |
} |
|
16 | 1405 |
|
1406 |
wp_enqueue_script( 'user-profile' ); |
|
9 | 1407 |
?> |
5 | 1408 |
|
16 | 1409 |
<form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post"> |
1410 |
<p> |
|
1411 |
<label for="user_login"><?php _e( 'Username or Email Address' ); ?></label> |
|
1412 |
<input type="text" name="log" id="user_login"<?php echo $aria_describedby_error; ?> class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" autocapitalize="off" /> |
|
1413 |
</p> |
|
1414 |
||
1415 |
<div class="user-pass-wrap"> |
|
1416 |
<label for="user_pass"><?php _e( 'Password' ); ?></label> |
|
1417 |
<div class="wp-pwd"> |
|
1418 |
<input type="password" name="pwd" id="user_pass"<?php echo $aria_describedby_error; ?> class="input password-input" value="" size="20" /> |
|
1419 |
<button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Show password' ); ?>"> |
|
1420 |
<span class="dashicons dashicons-visibility" aria-hidden="true"></span> |
|
1421 |
</button> |
|
1422 |
</div> |
|
1423 |
</div> |
|
1424 |
<?php |
|
1425 |
||
1426 |
/** |
|
1427 |
* Fires following the 'Password' field in the login form. |
|
1428 |
* |
|
1429 |
* @since 2.1.0 |
|
1430 |
*/ |
|
1431 |
do_action( 'login_form' ); |
|
1432 |
||
1433 |
?> |
|
1434 |
<p class="forgetmenot"><input name="rememberme" type="checkbox" id="rememberme" value="forever" <?php checked( $rememberme ); ?> /> <label for="rememberme"><?php esc_html_e( 'Remember Me' ); ?></label></p> |
|
1435 |
<p class="submit"> |
|
1436 |
<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Log In' ); ?>" /> |
|
1437 |
<?php |
|
1438 |
||
1439 |
if ( $interim_login ) { |
|
1440 |
?> |
|
1441 |
<input type="hidden" name="interim-login" value="1" /> |
|
1442 |
<?php |
|
1443 |
} else { |
|
1444 |
?> |
|
1445 |
<input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" /> |
|
1446 |
<?php |
|
1447 |
} |
|
1448 |
||
1449 |
if ( $customize_login ) { |
|
1450 |
?> |
|
1451 |
<input type="hidden" name="customize-login" value="1" /> |
|
1452 |
<?php |
|
1453 |
} |
|
1454 |
||
1455 |
?> |
|
1456 |
<input type="hidden" name="testcookie" value="1" /> |
|
1457 |
</p> |
|
1458 |
</form> |
|
1459 |
||
9 | 1460 |
<?php |
0 | 1461 |
|
16 | 1462 |
if ( ! $interim_login ) { |
1463 |
?> |
|
1464 |
<p id="nav"> |
|
1465 |
<?php |
|
1466 |
||
1467 |
if ( get_option( 'users_can_register' ) ) { |
|
9 | 1468 |
$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) ); |
5 | 1469 |
|
9 | 1470 |
/** This filter is documented in wp-includes/general-template.php */ |
1471 |
echo apply_filters( 'register', $registration_url ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1472 |
|
9 | 1473 |
echo esc_html( $login_link_separator ); |
16 | 1474 |
} |
1475 |
||
9 | 1476 |
?> |
16 | 1477 |
<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a> |
1478 |
</p> |
|
1479 |
<?php |
|
1480 |
} |
|
1481 |
||
1482 |
$login_script = 'function wp_attempt_focus() {'; |
|
1483 |
$login_script .= 'setTimeout( function() {'; |
|
1484 |
$login_script .= 'try {'; |
|
0 | 1485 |
|
16 | 1486 |
if ( $user_login ) { |
1487 |
$login_script .= 'd = document.getElementById( "user_pass" ); d.value = "";'; |
|
1488 |
} else { |
|
1489 |
$login_script .= 'd = document.getElementById( "user_login" );'; |
|
1490 |
||
1491 |
if ( $errors->get_error_code() === 'invalid_username' ) { |
|
1492 |
$login_script .= 'd.value = "";'; |
|
9 | 1493 |
} |
16 | 1494 |
} |
0 | 1495 |
|
16 | 1496 |
$login_script .= 'd.focus(); d.select();'; |
1497 |
$login_script .= '} catch( er ) {}'; |
|
1498 |
$login_script .= '}, 200);'; |
|
1499 |
$login_script .= "}\n"; // End of wp_attempt_focus(). |
|
1500 |
||
9 | 1501 |
/** |
1502 |
* Filters whether to print the call to `wp_attempt_focus()` on the login screen. |
|
1503 |
* |
|
1504 |
* @since 4.8.0 |
|
1505 |
* |
|
1506 |
* @param bool $print Whether to print the function call. Default true. |
|
1507 |
*/ |
|
1508 |
if ( apply_filters( 'enable_login_autofocus', true ) && ! $error ) { |
|
16 | 1509 |
$login_script .= "wp_attempt_focus();\n"; |
1510 |
} |
|
1511 |
||
1512 |
// Run `wpOnload()` if defined. |
|
1513 |
$login_script .= "if ( typeof wpOnload === 'function' ) { wpOnload() }"; |
|
1514 |
||
1515 |
?> |
|
1516 |
<script type="text/javascript"> |
|
1517 |
<?php echo $login_script; ?> |
|
1518 |
</script> |
|
1519 |
<?php |
|
1520 |
||
1521 |
if ( $interim_login ) { |
|
9 | 1522 |
?> |
16 | 1523 |
<script type="text/javascript"> |
1524 |
( function() { |
|
1525 |
try { |
|
1526 |
var i, links = document.getElementsByTagName( 'a' ); |
|
1527 |
for ( i in links ) { |
|
1528 |
if ( links[i].href ) { |
|
1529 |
links[i].target = '_blank'; |
|
1530 |
links[i].rel = 'noreferrer noopener'; |
|
1531 |
} |
|
1532 |
} |
|
1533 |
} catch( er ) {} |
|
1534 |
}()); |
|
1535 |
</script> |
|
1536 |
<?php |
|
9 | 1537 |
} |
0 | 1538 |
|
9 | 1539 |
login_footer(); |
1540 |
break; |
|
1541 |
} // End action switch. |