PluginProbe
School Management System – WPSchoolPress / 2.2.45
School Management System – WPSchoolPress v2.2.45
2.2.48 2.2.47 2.2.46 2.2.45 2.2.44 2.2.43 2.2.42 2.2.41 2.2.40 2.2.39 2.2.38 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 All 103 releases
wpschoolpress / wpsp-school-login.php

wpsp-school-login.php in School Management System – WPSchoolPress 2.2.45, at wpsp-school-login.php

876 lines 39.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 /** Make sure that the WordPress bootstrap has run before continuing. */
11 // Exit if accessed directly
12 if ( !defined( 'ABSPATH' ) ) exit;
13 // Redirect to https login if forced to use SSL
14 if ( force_ssl_admin() && ! is_ssl() ) {
15 if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
16 wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
17 exit();
18 } else {
19 wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
20 exit();
21 }
22 }
23 /**
24 * Output the login page header.
25 *
26 * @param string $title Optional. WordPress login Page title to display in the `<title>` element.
27 * Default 'Log In'.
28 * @param string $message Optional. Message to display in header. Default empty.
29 * @param WP_Error $wp_error Optional. The error to pass. Default empty.
30 */
31 function wpsp_login_header( $title = 'Log In', $message = '', $wp_error = '' ) {
32 global $error, $interim_login, $action;
33 // Don't index any of these forms
34 add_action( 'login_head', 'wp_no_robots' );
35 add_action( 'login_head', 'wp_login_viewport_meta' );
36 if ( empty($wp_error) )
37 $wp_error = new WP_Error();
38 // Shake it!
39 $shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password' );
40 /**
41 * Filters the error codes array for shaking the login form.
42 *
43 * @since 3.0.0
44 *
45 * @param array $shake_error_codes Error codes that shake the login form.
46 */
47 $shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes );
48 if ( $shake_error_codes && $wp_error->get_error_code() && in_array( $wp_error->get_error_code(), $shake_error_codes ) )
49 add_action( 'login_head', 'wp_shake_js', 12 );
50 $separator = is_rtl() ? ' &rsaquo; ' : ' &lsaquo; ';
51 ?><!DOCTYPE html>
52 <!--[if IE 8]>
53 <html xmlns="http://www.w3.org/1999/xhtml" class="ie8" <?php language_attributes(); ?>>
54 <![endif]-->
55 <!--[if !(IE 8) ]><!-->
56 <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
57 <!--<![endif]-->
58 <head>
59 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
60 <title><?php echo esc_html(get_bloginfo( 'name', 'display' ) . $separator . $title.'wpschoolpress'); ?></title>
61 <?php
62 wp_enqueue_style( 'login' );
63 /*
64 * Remove all stored post data on logging out.
65 * This could be added by add_action('login_head'...) like wp_shake_js(),
66 * but maybe better if it's not removable by plugins
67 */
68 if ( 'loggedout' == $wp_error->get_error_code() ) {
69 ?>
70 <script>if("sessionStorage" in window){try{for(var key in sessionStorage){if(key.indexOf("wp-autosave-")!=-1){sessionStorage.removeItem(key)}}}catch(e){}};</script>
71 <?php
72 }
73 /**
74 * Enqueue scripts and styles for the login page.
75 *
76 * @since 3.1.0
77 */
78 do_action( 'login_enqueue_scripts' );
79 /**
80 * Fires in the login page header after scripts are enqueued.
81 *
82 * @since 2.1.0
83 */
84 do_action( 'login_head' );
85 if ( is_multisite() ) {
86 $wpsp_login_header_url = network_home_url();
87 $wpsp_login_header_title = get_network()->site_name;
88 } else {
89 $wpsp_login_header_url = __( 'https://wordpress.org/','wpschoolpress' );
90 $wpsp_login_header_title = __( 'Powered by WordPress','wpschoolpress' );
91 }
92 /**
93 * Filters link URL of the header logo above login form.
94 *
95 * @since 2.1.0
96 *
97 * @param string $wpsp_login_header_url Login header logo URL.
98 */
99 $wpsp_login_header_url = apply_filters( 'login_headerurl', $wpsp_login_header_url );
100 /**
101 * Filters the title attribute of the header logo above login form.
102 *
103 * @since 2.1.0
104 *
105 * @param string $login_header_title Login header logo title attribute.
106 */
107 $wpsp_login_header_title = apply_filters( 'login_headertitle', $wpsp_login_header_title );
108 $classes = array( 'login-action-' . $action, 'wp-core-ui' );
109 if ( is_rtl() )
110 $classes[] = 'rtl';
111 if ( $interim_login ) {
112 $classes[] = 'interim-login';
113 ?>
114 <style type="text/css">html{background-color: transparent;}</style>
115 <?php
116 if ( 'success' === $interim_login )
117 $classes[] = 'interim-login-success';
118 }
119 $classes[] =' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
120 /**
121 * Filters the login page body classes.
122 *
123 * @since 3.5.0
124 *
125 * @param array $classes An array of body classes.
126 * @param string $action The action that brought the visitor to the login page.
127 */
128 $classes = apply_filters( 'login_body_class', $classes, $action );
129 ?>
130 </head>
131 <body class="login <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
132 <?php
133 /**
134 * Fires in the login page header after the body tag is opened.
135 *
136 * @since 4.6.0
137 */
138 do_action( 'wpsp_login_header' );
139 ?>
140 <div id="login">
141 <h1><a href="<?php echo esc_url( $wpsp_login_header_url ); ?>" title="<?php echo esc_html( $wpsp_login_header_title ); ?>" tabindex="-1"><?php bloginfo( 'name' ); ?></a></h1>
142 <?php
143 unset( $wpsp_login_header_url, $wpsp_login_header_title );
144 /**
145 * Filters the message to display above the login form.
146 *
147 * @since 2.1.0
148 *
149 * @param string $message Login message text.
150 */
151 $message = apply_filters( 'login_message', $message );
152 if ( !empty( $message ) )
153 echo esc_html($message . "\n",'wpschoolpress');
154 // In case a plugin uses $error rather than the $wp_errors object
155 if ( !empty( $error ) ) {
156 $wp_error->add('error', $error);
157 unset($error);
158 }
159 if ( $wp_error->get_error_code() ) {
160 $errors = '';
161 $messages = '';
162 foreach ( $wp_error->get_error_codes() as $code ) {
163 $severity = $wp_error->get_error_data( $code );
164 foreach ( $wp_error->get_error_messages( $code ) as $error_message ) {
165 if ( 'message' == $severity )
166 $messages .= ' ' . $error_message . "<br />\n";
167 else
168 $errors .= ' ' . $error_message . "<br />\n";
169 }
170 }
171 if ( ! empty( $errors ) ) {
172 /**
173 * Filters the error messages displayed above the login form.
174 *
175 * @since 2.1.0
176 *
177 * @param string $errors Login error message.
178 */
179 echo '<div id="login_error">' . esc_html(apply_filters( 'login_errors', $errors ),'wpschoolpress') . "</div>\n";
180 }
181 if ( ! empty( $messages ) ) {
182 /**
183 * Filters instructional messages displayed above the login form.
184 *
185 * @since 2.5.0
186 *
187 * @param string $messages Login messages.
188 */
189 echo '<p class="message">' . esc_html(apply_filters( 'login_messages', $messages ),'wpschoolpress') . "</p>\n";
190 }
191 }
192 } // End of login_header()
193 /**
194 * Outputs the footer for the login page.
195 *
196 * @param string $input_id Which input to auto-focus
197 */
198 function wpsp_login_footer($input_id = '') {
199 global $interim_login;
200 // Don't allow interim logins to navigate away from the page.
201 if ( ! $interim_login ): ?>
202 <p id="backtoblog"><a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php
203 /* translators: %s: site title */
204 printf( esc_html( '&larr; Back to %s', 'site' ), esc_html(get_bloginfo( 'title', 'display' ),'wpschoolpress') );
205 ?></a></p>
206 <?php endif; ?>
207 </div>
208 <?php if ( !empty($input_id) ) : ?>
209 <script type="text/javascript">
210 try{document.getElementById('<?php echo esc_html($input_id); ?>').focus();}catch(e){}
211 if(typeof wpOnload=='function')wpOnload();
212 </script>
213 <?php endif; ?>
214 <?php
215 /**
216 * Fires in the login page footer.
217 *
218 * @since 3.1.0
219 */
220 do_action( 'wpsp_login_footer' ); ?>
221 <div class="clear"></div>
222 </body>
223 </html>
224 <?php
225 }
226 /**
227 * @since 3.0.0
228 */
229 function wp_shake_js() {
230 ?>
231 <script type="text/javascript">
232 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();}}};
233 function s(id,pos){g(id).left=pos+'px';}
234 function g(id){return document.getElementById(id).style;}
235 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){}}}
236 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);});
237 </script>
238 <?php
239 }
240 /**
241 * @since 3.7.0
242 */
243 function wp_login_viewport_meta() {
244 ?>
245 <meta name="viewport" content="width=device-width" />
246 <?php
247 }
248 /**
249 * Handles sending password retrieval email to user.
250 *
251 * @return bool|WP_Error True: when finish. WP_Error on error
252 */
253 function retrieve_password() {
254 $errors = new WP_Error();
255 if ( empty( $_POST['user_login'] ) ) {
256 $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or email address.','wpschoolpress'));
257 } elseif ( strpos( $_POST['user_login'], '@' ) ) {
258 $user_data = get_user_by( 'email', trim( wp_unslash( sanitize_text_field($_POST['user_login'] )) ) );
259 if ( empty( $user_data ) )
260 $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.','wpschoolpress'));
261 } else {
262 $login = trim(sanitize_user($_POST['user_login']));
263 $user_data = get_user_by('login', $login);
264 }
265 /**
266 * Fires before errors are returned from a password reset request.
267 *
268 * @since 2.1.0
269 * @since 4.4.0 Added the `$errors` parameter.
270 *
271 * @param WP_Error $errors A WP_Error object containing any errors generated
272 * by using invalid credentials.
273 */
274 do_action( 'lostpassword_post', $errors );
275 if ( $errors->get_error_code() )
276 return $errors;
277 if ( !$user_data ) {
278 $errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or email.','wpschoolpress'));
279 return $errors;
280 }
281 // Redefining user_login ensures we return the right case in the email.
282 $user_login = $user_data->user_login;
283 $user_email = $user_data->user_email;
284 $key = get_password_reset_key( $user_data );
285 if ( is_wp_error( $key ) ) {
286 return $key;
287 }
288 $message = __('Someone has requested a password reset for the following account:','wpschoolpress') . "\r\n\r\n";
289 $message .= network_home_url( '/' ) . "\r\n\r\n";
290 $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
291 $message .= __('If this was a mistake, just ignore this email and nothing will happen.','wpschoolpress') . "\r\n\r\n";
292 $message .= __('To reset your password, visit the following address:','wpschoolpress') . "\r\n\r\n";
293 $message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";
294 if ( is_multisite() ) {
295 $blogname = get_network()->site_name;
296 } else {
297 /*
298 * The blogname option is escaped with esc_html on the way into the database
299 * in sanitize_option we want to reverse this for the plain text arena of emails.
300 */
301 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
302 }
303 /* translators: Password reset email subject. 1: Site name */
304 $title = sprintf( __('[%s] Password Reset','wpschoolpress'), $blogname );
305 /**
306 * Filters the subject of the password reset email.
307 *
308 * @since 2.8.0
309 * @since 4.4.0 Added the `$user_login` and `$user_data` parameters.
310 *
311 * @param string $title Default email title.
312 * @param string $user_login The username for the user.
313 * @param WP_User $user_data WP_User object.
314 */
315 $title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data );
316 /**
317 * Filters the message body of the password reset mail.
318 *
319 * If the filtered message is empty, the password reset email will not be sent.
320 *
321 * @since 2.8.0
322 * @since 4.1.0 Added `$user_login` and `$user_data` parameters.
323 *
324 * @param string $message Default mail message.
325 * @param string $key The activation key.
326 * @param string $user_login The username for the user.
327 * @param WP_User $user_data WP_User object.
328 */
329 $message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
330 if ( $message && !wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) )
331 wp_die( esc_html_e('The email could not be sent.','wpschoolpress') . "<br />\n" . esc_html_e('Possible reason: your host may have disabled the mail() function.','wpschoolpress') );
332 return true;
333 }
334 //
335 // Main
336 //
337 $action = isset($_REQUEST['action']) ? sanitize_text_field($_REQUEST['action']) : 'login';
338 $errors = new WP_Error();
339 if ( isset($_GET['key']) )
340 $action = 'resetpass';
341 // validate action so as to default to the login screen
342 if ( !in_array( $action, array( 'postpass', 'logout', 'lostpassword', 'retrievepassword', 'resetpass', 'rp', 'register', 'login' ), true ) && false === has_filter( 'login_form_' . $action ) )
343 $action = 'login';
344 nocache_headers();
345 header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset'));
346 if ( defined( 'RELOCATE' ) && RELOCATE ) { // Move flag is set
347 if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
348 $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
349 $url = dirname( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) );
350 if ( $url != get_option( 'siteurl' ) )
351 update_option( 'siteurl', $url );
352 }
353 //Set a cookie now to see if they are supported by the browser.
354 $secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) );
355 setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure );
356 if ( SITECOOKIEPATH != COOKIEPATH )
357 setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );
358 /**
359 * Fires when the login form is initialized.
360 *
361 * @since 3.2.0
362 */
363 do_action( 'login_init' );
364 /**
365 * Fires before a specified login form action.
366 *
367 * The dynamic portion of the hook name, `$action`, refers to the action
368 * that brought the visitor to the login form. Actions include 'postpass',
369 * 'logout', 'lostpassword', etc.
370 *
371 * @since 2.8.0
372 */
373 do_action( "login_form_{$action}" );
374 $http_post = ('POST' == $_SERVER['REQUEST_METHOD']);
375 $interim_login = isset($_REQUEST['interim-login']);
376 switch ($action) {
377 case 'postpass' :
378 if ( ! array_key_exists( 'post_password', $_POST ) ) {
379 wp_safe_redirect( wp_get_referer() );
380 exit();
381 }
382 require_once ABSPATH . WPINC . '/class-phpass.php';
383 $hasher = new PasswordHash( 8, true );
384 /**
385 * Filters the life span of the post password cookie.
386 *
387 * By default, the cookie expires 10 days from creation. To turn this
388 * into a session cookie, return 0.
389 *
390 * @since 3.7.0
391 *
392 * @param int $expires The expiry time, as passed to setcookie().
393 */
394 $expire = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );
395 $referer = wp_get_referer();
396 if ( $referer ) {
397 $secure = ( 'https' === parse_url( $referer, PHP_URL_SCHEME ) );
398 } else {
399 $secure = false;
400 }
401 setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash(sanitize_text_field( $_POST['post_password'] )) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
402 wp_safe_redirect( wp_get_referer() );
403 exit();
404 case 'logout' :
405 check_admin_referer('log-out');
406 $user = wp_get_current_user();
407 wp_logout();
408 if ( ! empty( $_REQUEST['redirect_to'] ) ) {
409 $redirect_to = wp_sanitize_redirect(stripslashes($_REQUEST['redirect_to']));
410 $requested_redirect_to = $redirect_to;
411 } else {
412 $redirect_to = add_query_arg(
413 array(
414 'loggedout' => 'true',
415 'wp_lang' => get_user_locale( $user ),
416 ),
417 wp_login_url()
418 );
419
420 $requested_redirect_to = '';
421 }
422 /**
423 * Filters the log out redirect URL.
424 *
425 * @since 4.2.0
426 *
427 * @param string $redirect_to The redirect destination URL.
428 * @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
429 * @param WP_User $user The WP_User object for the user that's logging out.
430 */
431 $redirect_to = apply_filters( 'logout_redirect', $redirect_to, $requested_redirect_to, $user );
432 wp_safe_redirect( $redirect_to );
433 exit();
434 case 'lostpassword' :
435 case 'retrievepassword' :
436 if ( $http_post ) {
437 $errors = retrieve_password();
438 if ( !is_wp_error($errors) ) {
439 $redirect_to = !empty( $_REQUEST['redirect_to'] ) ? wp_sanitize_redirect(stripslashes($_REQUEST['redirect_to'])) : wp_sanitize_redirect(stripslashes('wp-login.php?checkemail=confirm'));
440 wp_safe_redirect( $redirect_to );
441 exit();
442 }
443 }
444 if ( isset( $_GET['error'] ) ) {
445 if ( 'invalidkey' == $_GET['error'] ) {
446 $errors->add( 'invalidkey', __( 'Your password reset link appears to be invalid. Please request a new link below.' ,'wpschoolpress') );
447 } elseif ( 'expiredkey' == $_GET['error'] ) {
448 $errors->add( 'expiredkey', __( 'Your password reset link has expired. Please request a new link below.' ,'wpschoolpress') );
449 }
450 }
451 $lostpassword_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
452 /**
453 * Filters the URL redirected to after submitting the lostpassword/retrievepassword form.
454 *
455 * @since 3.0.0
456 *
457 * @param string $lostpassword_redirect The redirect destination URL.
458 */
459 $redirect_to = apply_filters( 'lostpassword_redirect', $lostpassword_redirect );
460 /**
461 * Fires before the lost password form.
462 *
463 * @since 1.5.1
464 */
465 do_action( 'lost_password' );
466 wpsp_login_header(__('Lost Password','wpschoolpress'), '<p class="message">' . __('Please enter your username or email address. You will receive a link to create a new password via email.','wpschoolpress') . '</p>', $errors);
467 $user_login = isset($_POST['user_login']) ? wp_unslash(sanitize_user($_POST['user_login'])) : '';
468 ?>
469 <form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post">
470 <p>
471 <label for="user_login" ><?php esc_html_e( 'Username or Email Address','wpschoolpress' ); ?><br />
472 <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
473 </p>
474 <?php
475 /**
476 * Fires inside the lostpassword form tags, before the hidden fields.
477 *
478 * @since 2.1.0
479 */
480 do_action( 'lostpassword_form' ); ?>
481 <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
482 <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','wpschoolpress'); ?>" /></p>
483 </form>
484 <p id="nav">
485 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php esc_html_e('Log in','wpschoolpress') ?></a>
486 <?php
487 if ( get_option( 'users_can_register' ) ) :
488 $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ,'wpschoolpress') );
489 /** This filter is documented in wp-includes/general-template.php */
490 echo ' | ' . esc_html(apply_filters( 'register', $registration_url ),'wpschoolpress');
491 endif;
492 ?>
493 </p>
494 <?php
495 wpsp_login_footer('user_login');
496 break;
497 case 'resetpass' :
498 case 'rp' :
499 list( $rp_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) );
500 $rp_cookie = 'wp-resetpass-' . COOKIEHASH;
501 if ( isset( $_GET['key'] ) ) {
502 $value = sprintf( '%s:%s', wp_unslash( $_GET['login'] ), wp_unslash( $_GET['key'] ) );
503 setcookie( $rp_cookie, $value, 0, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
504 wp_safe_redirect( remove_query_arg( array( 'key', 'login' ) ) );
505 exit;
506 }
507 if ( isset( $_COOKIE[ $rp_cookie ] ) && 0 < strpos( $_COOKIE[ $rp_cookie ], ':' ) ) {
508 list( $rp_login, $rp_key ) = explode( ':', wp_unslash( $_COOKIE[ $rp_cookie ] ), 2 );
509 $user = check_password_reset_key( $rp_key, $rp_login );
510 if ( isset( $_POST['pass1'] ) && ! hash_equals( $rp_key, sanitize_text_field($_POST['rp_key']) ) ) {
511 $user = false;
512 }
513 } else {
514 $user = false;
515 }
516 if ( ! $user || is_wp_error( $user ) ) {
517 setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
518 if ( $user && $user->get_error_code() === 'expired_key' )
519 wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=expiredkey' ) );
520 else
521 wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=invalidkey' ) );
522 exit;
523 }
524 $errors = new WP_Error();
525 if ( isset($_POST['pass1']) && sanitize_text_field($_POST['pass1']) != sanitize_text_field($_POST['pass2']) )
526 $errors->add( 'password_reset_mismatch', __( 'The passwords do not match.','wpschoolpress' ) );
527 /**
528 * Fires before the password reset procedure is validated.
529 *
530 * @since 3.5.0
531 *
532 * @param object $errors WP Error object.
533 * @param WP_User|WP_Error $user WP_User object if the login and reset key match. WP_Error object otherwise.
534 */
535 do_action( 'validate_password_reset', $errors, $user );
536 if ( ( ! $errors->get_error_code() ) && isset( $_POST['pass1'] ) && !empty( $_POST['pass1'] ) ) {
537 reset_password($user, sanitize_text_field($_POST['pass1']));
538 setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
539 wpsp_login_header( __( 'Password Reset','wpschoolpress' ), '<p class="message reset-pass">' . __( 'Your password has been reset.' ,'wpschoolpress') . ' <a href="' . esc_url( wp_login_url() ) . '">' . __( 'Log in','wpschoolpress' ) . '</a></p>' );
540 wpsp_login_footer();
541 exit;
542 }
543 wp_enqueue_script('utils');
544 wp_enqueue_script('user-profile');
545 wpsp_login_header(__('Reset Password','wpschoolpress'), '<p class="message reset-pass">' . __('Enter your new password below.','wpschoolpress') . '</p>', $errors );
546 ?>
547 <form name="resetpassform" id="resetpassform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=resetpass', 'login_post' ) ); ?>" method="post" autocomplete="off">
548 <input type="hidden" id="user_login" value="<?php echo esc_attr( $rp_login ); ?>" autocomplete="off" />
549 <div class="user-pass1-wrap">
550 <p>
551 <label for="pass1"><?php esc_html_e( 'New password' ,'wpschoolpress') ?></label>
552 </p>
553 <div class="wp-pwd">
554 <span class="password-input-wrapper">
555 <input type="password" data-reveal="1" data-pw="<?php echo esc_attr( wp_generate_password( 16 ) ); ?>" name="pass1" id="pass1" class="input" size="20" value="" autocomplete="off" aria-describedby="pass-strength-result" />
556 </span>
557 <div id="pass-strength-result" class="hide-if-no-js" aria-live="polite"><?php esc_html_e( 'Strength indicator','wpschoolpress' ); ?></div>
558 </div>
559 </div>
560 <p class="user-pass2-wrap">
561 <label for="pass2"><?php esc_html_e( 'Confirm new password','wpschoolpress' ) ?></label><br />
562 <input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" />
563 </p>
564 <p class="description indicator-hint"><?php echo esc_html(wp_get_password_hint(),'wpschoolpress'); ?></p>
565 <br class="clear" />
566 <?php
567 /**
568 * Fires following the 'Strength indicator' meter in the user password reset form.
569 *
570 * @since 3.9.0
571 *
572 * @param WP_User $user User object of the user whose password is being reset.
573 */
574 do_action( 'resetpass_form', $user );
575 ?>
576 <input type="hidden" name="rp_key" value="<?php echo esc_attr( $rp_key ); ?>" />
577 <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>
578 </form>
579 <p id="nav">
580 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php esc_html_e( 'Log in','wpschoolpress' ); ?></a>
581 <?php
582 if ( get_option( 'users_can_register' ) ) :
583 $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register','wpschoolpress' ) );
584 /** This filter is documented in wp-includes/general-template.php */
585 echo ' | ' . esc_html(apply_filters( 'register', $registration_url ),'wpschoolpress');
586 endif;
587 ?>
588 </p>
589 <?php
590 wpsp_login_footer('user_pass');
591 break;
592 case 'register' :
593 if ( is_multisite() ) {
594 /**
595 * Filters the Multisite sign up URL.
596 *
597 * @since 3.0.0
598 *
599 * @param string $sign_up_url The sign up URL.
600 */
601 wp_redirect( apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ) );
602 exit;
603 }
604 if ( !get_option('users_can_register') ) {
605 wp_redirect( site_url('wp-login.php?registration=disabled') );
606 exit();
607 }
608 $user_login = '';
609 $user_email = '';
610 if ( $http_post ) {
611 $user_login = isset( $_POST['user_login'] ) ? sanitize_user($_POST['user_login']) : '';
612 $user_email = isset( $_POST['user_email'] ) ? wp_unslash( sanitize_email($_POST['user_email']) ) : '';
613 $errors = register_new_user($user_login, $user_email);
614 if ( !is_wp_error($errors) ) {
615 $redirect_to = !empty( $_POST['redirect_to'] ) ? sanitize_text_field($_POST['redirect_to']) : 'wp-login.php?checkemail=registered';
616 wp_safe_redirect( $redirect_to );
617 exit();
618 }
619 }
620 $registration_redirect = ! empty( $_REQUEST['redirect_to'] ) ? sanitize_text_field($_REQUEST['redirect_to']) : '';
621 /**
622 * Filters the registration redirect URL.
623 *
624 * @since 3.0.0
625 *
626 * @param string $registration_redirect The redirect destination URL.
627 */
628 $redirect_to = apply_filters( 'registration_redirect', $registration_redirect );
629 wpsp_login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site','wpschoolpress') . '</p>', $errors);
630 ?>
631 <form name="registerform" id="registerform" action="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login_post' ) ); ?>" method="post" novalidate="novalidate">
632 <p>
633 <label for="user_login"><?php esc_html_e('Username','wpschoolpress') ?><br />
634 <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr(wp_unslash($user_login)); ?>" size="20" /></label>
635 </p>
636 <p>
637 <label for="user_email"><?php esc_html_e('Email','wpschoolpress') ?><br />
638 <input type="email" name="user_email" id="user_email" class="input" value="<?php echo esc_attr( wp_unslash( $user_email ) ); ?>" size="25" /></label>
639 </p>
640 <?php
641 /**
642 * Fires following the 'Email' field in the user registration form.
643 *
644 * @since 2.1.0
645 */
646 do_action( 'register_form' );
647 ?>
648 <p id="reg_passmail"><?php esc_html_e( 'Registration confirmation will be emailed to you.','wpschoolpress' ); ?></p>
649 <br class="clear" />
650 <input type="hidden" name="redirect_to" value="<?php echo esc_url( $redirect_to ); ?>" />
651 <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>
652 </form>
653 <p id="nav">
654 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php esc_html_e( 'Log in','wpschoolpress' ); ?></a> |
655 <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php esc_html_e( 'Lost your password?','wpschoolpress' ); ?></a>
656 </p>
657 <?php
658 wpsp_login_footer('user_login');
659 break;
660 case 'login' :
661 default:
662 $secure_cookie = '';
663 $customize_login = isset( $_REQUEST['customize-login'] );
664 if ( $customize_login )
665 wp_enqueue_script( 'customize-base' );
666 // If the user wants ssl but the session is not ssl, force a secure cookie.
667 if ( !empty($_POST['log']) && !force_ssl_admin() ) {
668 $user_name = sanitize_user($_POST['log']);
669 $user = get_user_by( 'login', $user_name );
670 if ( ! $user && strpos( $user_name, '@' ) ) {
671 $user = get_user_by( 'email', $user_name );
672 }
673 if ( $user ) {
674 if ( get_user_option('use_ssl', $user->ID) ) {
675 $secure_cookie = true;
676 force_ssl_admin(true);
677 }
678 }
679 }
680 if ( isset( $_REQUEST['redirect_to'] ) ) {
681 $redirect_to = wp_sanitize_redirect(stripslashes($_REQUEST['redirect_to']));
682 // Redirect to https if user wants ssl
683 if ( $secure_cookie && false !== strpos($redirect_to, 'wp-admin') )
684 $redirect_to = preg_replace('|^http://|', 'https://', $redirect_to);
685 } else {
686 $redirect_to = admin_url();
687 }
688 $reauth = empty($_REQUEST['reauth']) ? false : true;
689 $user = wp_signon( array(), $secure_cookie );
690 if ( empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) {
691 if ( headers_sent() ) {
692 /* translators: 1: Browser cookie documentation URL, 2: Support forums URL */
693 $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>.' ,'wpschoolpress'),
694 __( 'https://codex.wordpress.org/Cookies','wpschoolpress' ), __( 'https://wordpress.org/support/','wpschoolpress' ) ) );
695 } elseif ( isset( $_POST['testcookie'] ) && empty( $_COOKIE[ TEST_COOKIE ] ) ) {
696 // If cookies are disabled we can't log in even with a valid user+pass
697 /* translators: 1: Browser cookie documentation URL */
698 $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.','wpschoolpress' ),
699 __( 'https://codex.wordpress.org/Cookies','wpschoolpress' ) ) );
700 }
701 }
702 $requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? sanitize_text_field($_REQUEST['redirect_to']) : '';
703 /**
704 * Filters the login redirect URL.
705 *
706 * @since 3.0.0
707 *
708 * @param string $redirect_to The redirect destination URL.
709 * @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
710 * @param WP_User|WP_Error $user WP_User object if login was successful, WP_Error object otherwise.
711 */
712 $redirect_to = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $user );
713 if ( !is_wp_error($user) && !$reauth ) {
714 if ( $interim_login ) {
715 $message = '<p class="message">' . __('You have logged in successfully.','wpschoolpress') . '</p>';
716 $interim_login = 'success';
717 wpsp_login_header( '', $message ); ?>
718 </div>
719 <?php
720 /** This action is documented in wp-login.php */
721 do_action( 'wpsp_login_footer' ); ?>
722 <?php if ( $customize_login ) : ?>
723 <script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo esc_attr(wp_customize_url(),'wpschoolpress'); ?>', channel: 'login' }).send('login') }, 1000 );</script>
724 <?php endif; ?>
725 </body></html>
726 <?php exit;
727 }
728 if ( ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' || $redirect_to == admin_url() ) ) {
729 // 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.
730 if ( is_multisite() && !get_active_blog_for_user($user->ID) && !is_super_admin( $user->ID ) )
731 $redirect_to = user_admin_url();
732 elseif ( is_multisite() && !$user->has_cap('read') )
733 $redirect_to = get_dashboard_url( $user->ID );
734 elseif ( !$user->has_cap('edit_posts') )
735 $redirect_to = $user->has_cap( 'read' ) ? admin_url( 'profile.php' ) : home_url();
736 wp_redirect( $redirect_to );
737 exit();
738 }
739 wp_safe_redirect($redirect_to);
740 exit();
741 }
742 $errors = $user;
743 // Clear errors if loggedout is set.
744 if ( !empty($_GET['loggedout']) || $reauth )
745 $errors = new WP_Error();
746 if ( $interim_login ) {
747 if ( ! $errors->get_error_code() )
748 $errors->add( 'expired', __( 'Your session has expired. Please log in to continue where you left off.' ,'wpschoolpress'), 'message' );
749 } else {
750 // Some parts of this script use the main login form to display a message
751 if ( isset($_GET['loggedout']) && true == sanitize_text_field($_GET['loggedout']) )
752 $errors->add('loggedout', __('You are now logged out.','wpschoolpress'), 'message');
753 elseif ( isset($_GET['registration']) && 'disabled' == sanitize_text_field($_GET['registration']) )
754 $errors->add('registerdisabled', __('User registration is currently not allowed.','wpschoolpress'));
755 elseif ( isset($_GET['checkemail']) && 'confirm' == sanitize_text_field($_GET['checkemail']) )
756 $errors->add('confirm', __('Check your email for the confirmation link.','wpschoolpress'), 'message');
757 elseif ( isset($_GET['checkemail']) && 'newpass' == sanitize_text_field($_GET['checkemail']) )
758 $errors->add('newpass', __('Check your email for your new password.','wpschoolpress'), 'message');
759 elseif ( isset($_GET['checkemail']) && 'registered' == sanitize_text_field($_GET['checkemail']) )
760 $errors->add('registered', __('Registration complete. Please check your email.','wpschoolpress'), 'message');
761 elseif ( strpos( $redirect_to, 'about.php?updated' ) )
762 $errors->add('updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to see what&#8217;s new.' ,'wpschoolpress'), 'message' );
763 }
764 /**
765 * Filters the login page errors.
766 *
767 * @since 3.6.0
768 *
769 * @param object $errors WP Error object.
770 * @param string $redirect_to Redirect destination URL.
771 */
772 $errors = apply_filters( 'wp_login_errors', $errors, $redirect_to );
773 // Clear any stale cookies.
774 if ( $reauth )
775 wp_clear_auth_cookie();
776 wpsp_login_header(__('Log In','wpschoolpress'), '', $errors);
777 if ( isset($_POST['log']) )
778 $user_login = ( 'incorrect_password' == $errors->get_error_code() || 'empty_password' == $errors->get_error_code() ) ? esc_attr(wp_unslash($_POST['log'])) : '';
779 $rememberme = ! empty( $_POST['rememberme'] );
780 if ( ! empty( $errors->errors ) ) {
781 $aria_describedby_error = ' aria-describedby="login_error"';
782 } else {
783 $aria_describedby_error = '';
784 }
785 ?>
786 <form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
787 <p>
788 <label for="user_login"><?php esc_html_e( 'Username or Email Address','wpschoolpress' ); ?><br />
789 <input type="text" name="log" id="user_login"<?php echo esc_attr($aria_describedby_error); ?> class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" /></label>
790 </p>
791 <p>
792 <label for="user_pass"><?php esc_html_e( 'Password','wpschoolpress' ); ?><br />
793 <input type="password" name="pwd" id="user_pass"<?php echo esc_attr($aria_describedby_error); ?> class="input" value="" size="20" /></label>
794 </p>
795 <?php
796 /**
797 * Fires following the 'Password' field in the login form.
798 *
799 * @since 2.1.0
800 */
801 do_action( 'login_form' );
802 ?>
803 <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>
804 <p class="submit">
805 <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Log In'); ?>" />
806 <?php if ( $interim_login ) { ?>
807 <input type="hidden" name="interim-login" value="1" />
808 <?php } else { ?>
809 <input type="hidden" name="redirect_to" value="<?php echo esc_attr($redirect_to); ?>" />
810 <?php } ?>
811 <?php if ( $customize_login ) : ?>
812 <input type="hidden" name="customize-login" value="1" />
813 <?php endif; ?>
814 <input type="hidden" name="testcookie" value="1" />
815 </p>
816 </form>
817 <?php if ( ! $interim_login ) { ?>
818 <p id="nav">
819 <?php if ( ! isset( $_GET['checkemail'] ) || ! in_array( $_GET['checkemail'], array( 'confirm', 'newpass' ) ) ) :
820 if ( get_option( 'users_can_register' ) ) :
821 $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ,'wpschoolpress') );
822 /** This filter is documented in wp-includes/general-template.php */
823 echo esc_html(apply_filters( 'register', $registration_url ),'wpschoolpress') . ' | ';
824 endif;
825 ?>
826 <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php esc_html_e( 'Lost your password?','wpschoolpress' ); ?></a>
827 <?php endif; ?>
828 </p>
829 <?php } ?>
830 <script type="text/javascript">
831 function wp_attempt_focus(){
832 setTimeout( function(){ try{
833 <?php if ( $user_login ) { ?>
834 d = document.getElementById('user_pass');
835 d.value = '';
836 <?php } else { ?>
837 d = document.getElementById('user_login');
838 <?php if ( 'invalid_username' == $errors->get_error_code() ) { ?>
839 if( d.value != '' )
840 d.value = '';
841 <?php
842 }
843 }?>
844 d.focus();
845 d.select();
846 } catch(e){}
847 }, 200);
848 }
849 /**
850 * Filters whether to print the call to `wp_attempt_focus()` on the login screen.
851 *
852 * @since 4.8.0
853 *
854 * @param bool $print Whether to print the function call. Default true.
855 */
856 <?php if ( apply_filters( 'enable_login_autofocus', true ) && ! $error ) { ?>
857 wp_attempt_focus();
858 <?php } ?>
859 if(typeof wpOnload=='function')wpOnload();
860 <?php if ( $interim_login ) { ?>
861 (function(){
862 try {
863 var i, links = document.getElementsByTagName('a');
864 for ( i in links ) {
865 if ( links[i].href )
866 links[i].target = '_blank';
867 }
868 } catch(e){}
869 }());
870 <?php } ?>
871 </script>
872 <?php
873 wpsp_login_footer();
874 break;
875 } // end action switch
876