PluginProbe
LoginPress | wp-login Custom Login Page Customizer / 3.0.2
LoginPress | wp-login Custom Login Page Customizer v3.0.2
6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.3 1.0.4 All 118 releases
loginpress / include / template-loginpress.php

template-loginpress.php in LoginPress | wp-login Custom Login Page Customizer 3.0.2, at include/template-loginpress.php

634 lines 18.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Template Name: LoginPress
5 *
6 * Template to display the WordPress login page in the WP-Customizer.
7 *
8 * @package LoginPress
9 * @author WPBrigade
10 * @since 1.1.3
11 */
12
13 // Redirect if viewed from outside the Customizer.
14 global $interim_login;
15
16 if ( ! is_customize_preview() ) {
17
18 $loginpress_obj = new LoginPress();
19 $loginpress_page = $loginpress_obj->get_loginpress_page();
20
21 $page = get_permalink( $loginpress_page );
22
23 // Generate the redirect url.
24 $url = add_query_arg(
25 array(
26 'autofocus[panel]' => 'loginpress_panel',
27 'return' => admin_url( 'index.php' ),
28 'url' => rawurlencode( $page ),
29 ),
30 admin_url( 'customize.php' )
31 );
32
33 wp_safe_redirect( $url );
34 }
35
36 /** Make sure that the WordPress bootstrap has run before continuing. */
37 require( ABSPATH . '/wp-load.php' );
38
39 // Redirect to https login if forced to use SSL
40 if ( force_ssl_admin() && ! is_ssl() ) {
41 if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
42 wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
43 exit();
44 } else {
45 wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
46 exit();
47 }
48 }
49
50 /**
51 * Output the login page header.
52 *
53 * @param string $title Optional. WordPress login Page title to display in the `<title>` element.
54 * Default 'Log In'.
55 * @param string $message Optional. Message to display in header. Default empty.
56 * @param WP_Error $wp_error Optional. The error to pass. Default empty.
57 */
58 function login_header( $title = 'Log In', $message = '', $wp_error = '' ) {
59 global $error, $interim_login, $action;
60
61 // Don't index any of these forms
62 add_action( 'login_head', 'wp_no_robots' );
63
64 add_action( 'login_head', 'wp_login_viewport_meta' );
65
66 if ( empty($wp_error) )
67 $wp_error = new WP_Error();
68
69 $login_title = get_bloginfo( 'name', 'display' );
70
71 /* translators: Login screen title. 1: Login screen name, 2: Network or site name */
72 $login_title = sprintf( __( '%1$s &lsaquo; %2$s &#8212; WordPress' ), $title, $login_title );
73
74 /**
75 * Filters the title tag content for login page.
76 *
77 * @since 4.9.0
78 *
79 * @param string $login_title The page title, with extra context added.
80 * @param string $title The original page title.
81 */
82 $login_title = apply_filters( 'login_title', $login_title, $title );
83
84 ?><!DOCTYPE html>
85 <!--[if IE 8]>
86 <html xmlns="http://www.w3.org/1999/xhtml" class="ie8" <?php language_attributes(); ?>>
87 <![endif]-->
88 <!--[if !(IE 8) ]><!-->
89 <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
90 <!--<![endif]-->
91 <head>
92 <title><?php echo $login_title; ?></title>
93 <?php
94
95 wp_enqueue_style( 'login' );
96
97 /**
98 * Enqueue scripts and styles for the login page.
99 *
100 * @since 3.0.1
101 */
102 do_action( 'login_enqueue_scripts' );
103
104 /**
105 * Fires in the login page header after scripts are enqueued.
106 *
107 * @since 2.1.0
108 */
109 do_action( 'login_head' );
110
111 $classes = array( 'login-action-' . $action, 'wp-core-ui' );
112 if ( is_rtl() )
113 $classes[] = 'rtl';
114
115 if ( $interim_login ) {
116 $classes[] = 'interim-login'; ?>
117
118 <style type="text/css">html{background-color: transparent;}</style>
119 <?php
120
121 if ( 'success' === $interim_login )
122 $classes[] = 'interim-login-success';
123 }
124 $classes[] =' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
125
126 /**
127 * Filters the login page body classes.
128 *
129 * @since 3.5.0
130 *
131 * @param array $classes An array of body classes.
132 * @param string $action The action that brought the visitor to the login page.
133 */
134 $classes = apply_filters( 'login_body_class', $classes, $action );
135 ?>
136 </head>
137 <body class="login <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
138 <?php
139 /**
140 * Fires in the login page header after the body tag is opened.
141 *
142 * @since 4.6.0
143 */
144 do_action( 'login_header' );
145
146 if ( is_multisite() ) {
147 $login_header_url = network_home_url();
148 $login_header_title = get_network()->site_name;
149 } else {
150 $login_header_url = __( 'https://wordpress.org/' );
151 $login_header_title = __( 'Powered by WordPress' );
152 }
153
154 /**
155 * Filters link URL of the header logo above login form.
156 *
157 * @since 2.1.0
158 *
159 * @param string $login_header_url Login header logo URL.
160 */
161 $login_header_url = apply_filters( 'login_headerurl', $login_header_url );
162
163 /**
164 * Filters the title attribute of the header logo above login form.
165 *
166 * @since 2.1.0
167 *
168 * @param string $login_header_title Login header logo title attribute.
169 */
170 $login_header_title = apply_filters( 'login_headertitle', $login_header_title );
171
172 /*
173 * To match the URL/title set above, Multisite sites have the blog name,
174 * while single sites get the header title.
175 */
176 if ( is_multisite() ) {
177 $login_header_text = get_bloginfo( 'name', 'display' );
178 } else {
179 $login_header_text = $login_header_title;
180 }
181
182 ?>
183 <div id="login">
184 <h1><a href="<?php echo esc_url( $login_header_url ); ?>" title="<?php echo esc_attr( $login_header_title ); ?>" tabindex="-1"><?php echo $login_header_text; ?></a></h1>
185 <?php
186
187 unset( $login_header_url, $login_header_title );
188
189 /**
190 * Filters the message to display above the login form.
191 *
192 * @since 2.1.0
193 *
194 * @param string $message Login message text.
195 */
196 $message = apply_filters( 'login_message', $message );
197 if ( !empty( $message ) )
198 echo $message . "\n";
199
200 // In case a plugin uses $error rather than the $wp_errors object
201 if ( !empty( $error ) ) {
202 $wp_error->add('error', $error);
203 unset($error);
204 }
205
206 if ( $wp_error->get_error_code() ) {
207 $errors = '';
208 $messages = '';
209 foreach ( $wp_error->get_error_codes() as $code ) {
210 $severity = $wp_error->get_error_data( $code );
211 foreach ( $wp_error->get_error_messages( $code ) as $error_message ) {
212 if ( 'message' == $severity )
213 $messages .= ' ' . $error_message . "<br />\n";
214 else
215 $errors .= ' ' . $error_message . "<br />\n";
216 }
217 }
218 if ( ! empty( $errors ) ) {
219 /**
220 * Filters the error messages displayed above the login form.
221 *
222 * @since 2.1.0
223 *
224 * @param string $errors Login error message.
225 */
226 echo '<div id="login_error">' . apply_filters( 'login_errors', $errors ) . "</div>\n";
227 }
228 if ( ! empty( $messages ) ) {
229 /**
230 * Filters instructional messages displayed above the login form.
231 *
232 * @since 2.5.0
233 *
234 * @param string $messages Login messages.
235 */
236 echo '<p class="message">' . apply_filters( 'login_messages', $messages ) . "</p>\n";
237 }
238 }
239 } // End of login_header()
240
241 /**
242 * Outputs the footer for the login page.
243 *
244 * @param string $input_id Which input to auto-focus
245 */
246 function login_footer($input_id = '') {
247 global $interim_login;
248
249 // Don't allow interim logins to navigate away from the page.
250 if ( ! $interim_login ): ?>
251 <p id="backtoblog"><a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php
252 /* translators: %s: site title */
253 printf( _x( '&larr; Back to %s', 'site' ), get_bloginfo( 'title', 'display' ) );
254 ?></a></p>
255 <?php endif; ?>
256
257 </div>
258
259 <?php if ( !empty($input_id) ) : ?>
260 <script type="text/javascript">
261 try{document.getElementById('<?php echo $input_id; ?>').focus();}catch(e){}
262 if(typeof wpOnload=='function')wpOnload();
263 </script>
264 <?php endif; ?>
265
266 <?php
267 /**
268 * Fires in the login page footer.
269 *
270 * @since 3.0.1
271 */
272 do_action( 'login_footer' ); ?>
273 <div class="clear"></div>
274 </body>
275 </html>
276 <?php
277 }
278 ?>
279 </div><?php // End of <div id="login">.
280 /**
281 * WordPress language switcher functionality of login form
282 *
283 * @since 1.5.11
284 */
285 if (
286 ! $interim_login && version_compare( $GLOBALS['wp_version'], '5.9', '>=' ) &&
287 /**
288 * Filters the Languages select input activation on the login screen.
289 *
290 * @since 1.5.11
291 *
292 * @param bool Whether to display the Languages select input on the login screen.
293 */
294 apply_filters( 'login_display_language_dropdown', true )
295 ) {
296 $languages = get_available_languages();
297
298 if ( ! empty( $languages ) ) {
299 ?>
300 <div class="language-switcher">
301 <form id="language-switcher" action="" method="get">
302
303 <label for="language-switcher-locales">
304 <span class="dashicons dashicons-translation" aria-hidden="true"></span>
305 <span class="screen-reader-text"><?php _e( 'Language' ); ?></span>
306 </label>
307
308 <?php
309 $args = array(
310 'id' => 'language-switcher-locales',
311 'name' => 'wp_lang',
312 'selected' => determine_locale(),
313 'show_available_translations' => false,
314 'explicit_option_en_us' => true,
315 'languages' => $languages,
316 );
317
318 /**
319 * Filters default arguments for the Languages select input on the login screen.
320 *
321 * @since 5.9.0
322 *
323 * @param array $args Arguments for the Languages select input on the login screen.
324 */
325 wp_dropdown_languages( apply_filters( 'login_language_dropdown_args', $args ) );
326 ?>
327
328 <?php if ( $interim_login ) { ?>
329 <input type="hidden" name="interim-login" value="1" />
330 <?php } ?>
331
332 <?php if ( isset( $_GET['redirect_to'] ) && '' !== $_GET['redirect_to'] ) { ?>
333 <input type="hidden" name="redirect_to" value="<?php echo esc_url_raw( $_GET['redirect_to'] ); ?>" />
334 <?php } ?>
335
336 <?php if ( isset( $_GET['action'] ) && '' !== $_GET['action'] ) { ?>
337 <input type="hidden" name="action" value="<?php echo esc_attr( $_GET['action'] ); ?>" />
338 <?php } ?>
339
340 <input type="submit" class="button" value="<?php esc_attr_e( 'Change' ); ?>">
341
342 </form>
343 </div>
344 <?php } ?>
345 <?php } ?>
346 <?php
347
348 /**
349 * @since 3.7.0
350 */
351 function wp_login_viewport_meta() { ?>
352 <meta name="viewport" content="width=device-width" />
353 <?php
354 }
355
356
357 $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'login';
358 $errors = new WP_Error();
359
360 if ( isset($_GET['key']) )
361 $action = 'resetpass';
362
363 // validate action so as to default to the login screen
364 if ( !in_array( $action, array( 'postpass', 'logout', 'lostpassword', 'retrievepassword', 'resetpass', 'rp', 'register', 'login' ), true ) && false === has_filter( 'login_form_' . $action ) )
365 $action = 'login';
366
367 nocache_headers();
368
369 header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset'));
370
371 if ( defined( 'RELOCATE' ) && RELOCATE ) { // Move flag is set
372 if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
373 $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
374
375 $url = dirname( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) );
376 if ( $url != get_option( 'siteurl' ) )
377 update_option( 'siteurl', $url );
378 }
379
380 //Set a cookie now to see if they are supported by the browser.
381 $secure = ( 'https' === wp_parse_url( wp_login_url(), PHP_URL_SCHEME ) );
382 setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure );
383 if ( SITECOOKIEPATH != COOKIEPATH )
384 setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );
385
386 $lang = ! empty( $_GET['wp_lang'] ) ? sanitize_text_field( $_GET['wp_lang'] ) : '';
387 $switched_locale = switch_to_locale( $lang );
388
389 /**
390 * Fires when the login form is initialized.
391 *
392 * @since 3.2.0
393 */
394 do_action( 'login_init' );
395
396 /**
397 * Fires before a specified login form action.
398 *
399 * The dynamic portion of the hook name, `$action`, refers to the action
400 * that brought the visitor to the login form. Actions include 'postpass',
401 * 'logout', 'lostpassword', etc.
402 *
403 * @since 2.8.0
404 */
405 do_action( "login_form_{$action}" );
406
407 $http_post = ('POST' == $_SERVER['REQUEST_METHOD']);
408 $interim_login = isset($_REQUEST['interim-login']);
409
410 /**
411 * Filters the separator used between login form navigation links.
412 *
413 * @since 4.9.0
414 *
415 * @param string $login_link_separator The separator used between login form navigation links.
416 */
417 $login_link_separator = apply_filters( 'login_link_separator', ' | ' );
418
419 switch ($action) {
420
421 case 'lostpassword' :
422 case 'retrievepassword' :
423
424 /**
425 * Filters the URL redirected to after submitting the lostpassword/retrievepassword form.
426 *
427 * @since 3.0.0
428 *
429 * @param string $lostpassword_redirect The redirect destination URL.
430 */
431 $redirect_to = apply_filters( 'lostpassword_redirect', $lostpassword_redirect );
432
433 /**
434 * Fires before the lost password form.
435 *
436 * @since 1.5.1
437 */
438 do_action( 'lost_password' );
439
440 login_header(__('Lost Password'), '<p class="message">' . __('Please enter your username or email address. You will receive a link to create a new password via email.') . '</p>', $errors);
441
442 $user_login = '';
443
444 if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) {
445 $user_login = wp_unslash( $_POST['user_login'] );
446 }
447
448 ?>
449
450 <form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post">
451 <p>
452 <label for="user_login" ><span><?php _e( 'Username or Email Address' ); ?></span><br />
453 <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
454 </p>
455 <?php
456 /**
457 * Fires inside the lostpassword form tags, before the hidden fields.
458 *
459 * @since 2.1.0
460 */
461 do_action( 'lostpassword_form' ); ?>
462 <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
463 <p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Get New Password'); ?>" /></p>
464 </form>
465
466 <p id="nav">
467 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e('Log in') ?></a>
468 <?php
469 if ( get_option( 'users_can_register' ) ) :
470 $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
471
472 echo esc_html( $login_link_separator );
473
474 /** This filter is documented in wp-includes/general-template.php */
475 echo apply_filters( 'register', $registration_url );
476 endif;
477 ?>
478 </p>
479
480 <?php
481 login_footer('user_login');
482
483
484
485 break;
486
487 case 'resetpass' :
488 case 'register' :
489 if ( is_multisite() ) {
490 /**
491 * Filters the Multisite sign up URL.
492 *
493 * @since 3.0.0
494 *
495 * @param string $sign_up_url The sign up URL.
496 */
497 wp_redirect( apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ) );
498 exit;
499 }
500
501 if ( !get_option('users_can_register') ) {
502 wp_redirect( site_url('wp-login.php?registration=disabled') );
503 exit();
504 }
505
506 $user_login = '';
507 $user_email = '';
508
509 if ( $http_post ) {
510 if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) {
511 $user_login = $_POST['user_login'];
512 }
513
514 if ( isset( $_POST['user_email'] ) && is_string( $_POST['user_email'] ) ) {
515 $user_email = wp_unslash( $_POST['user_email'] );
516 }
517
518 $errors = register_new_user($user_login, $user_email);
519 if ( !is_wp_error($errors) ) {
520 $redirect_to = !empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : 'wp-login.php?checkemail=registered';
521 wp_safe_redirect( $redirect_to );
522 exit();
523 }
524 }
525
526 $registration_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
527 /**
528 * Filters the registration redirect URL.
529 *
530 * @since 3.0.0
531 *
532 * @param string $registration_redirect The redirect destination URL.
533 */
534 $redirect_to = apply_filters( 'registration_redirect', $registration_redirect );
535 login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>', $errors);
536 ?>
537 <form name="registerform" id="registerform" action="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login_post' ) ); ?>" method="post" novalidate="novalidate">
538 <p>
539 <label for="user_login"><?php _e('Username') ?><br />
540 <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr(wp_unslash($user_login)); ?>" size="20" /></label>
541 </p>
542 <p>
543 <label for="user_email"><?php _e('Email') ?><br />
544 <input type="email" name="user_email" id="user_email" class="input" value="<?php echo esc_attr( wp_unslash( $user_email ) ); ?>" size="25" /></label>
545 </p>
546 <?php
547 /**
548 * Fires following the 'Email' field in the user registration form.
549 *
550 * @since 2.1.0
551 */
552 do_action( 'register_form' );
553 ?>
554 <p id="reg_passmail"><?php _e( 'Registration confirmation will be emailed to you.' ); ?></p>
555 <br class="clear" />
556 <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
557 <p class="submit">
558 <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Register'); ?>" />
559 </p>
560 </form>
561
562 <p id="nav">
563 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
564 <?php echo esc_html( $login_link_separator ); ?>
565 <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a>
566 </p>
567
568 <?php
569 login_footer('user_login');
570
571 break;
572
573 case 'login' :
574 default:
575 $secure_cookie = '';
576 $customize_login = isset( $_REQUEST['customize-login'] );
577 if ( $customize_login )
578 wp_enqueue_script( 'customize-base' );
579
580 login_header(__('Log In'), '', $errors);
581 $aria_describedby_error = '';
582 ?>
583
584 <form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post" autocomplete="off">
585 <p>
586 <label for="user_login"><span><?php _e( 'Username or Email Address' ); ?></span><br />
587 <input type="text" name="log" id="user_login"<?php echo $aria_describedby_error; ?> class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" autocomplete="off"/></label>
588 </p>
589 <p>
590 <label for="user_pass"><span><?php _e( 'Password' ); ?></span><br />
591 <input type="password" name="pwd" id="user_pass"<?php echo $aria_describedby_error; ?> class="input" value="" size="20" autocomplete="off"/></label>
592 </p>
593 <?php
594 /**
595 * Fires following the 'Password' field in the login form.
596 *
597 * @since 2.1.0
598 */
599 do_action( 'login_form' );
600 if (isset($_POST)) {
601 $rememberme = ! empty( $_POST['rememberme'] );
602 } else {
603 $rememberme = '';
604 }
605 ?>
606 <p class="forgetmenot">
607 <label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever" <?php checked( $rememberme ); ?> /> <?php esc_html_e( 'Remember Me' ); ?></label>
608 </p>
609 <p class="submit">
610 <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Log In'); ?>" />
611 </p>
612 </form>
613
614 <?php if ( ! $interim_login ) { ?>
615 <p id="nav">
616 <?php if ( ! isset( $_GET['checkemail'] ) || ! in_array( $_GET['checkemail'], array( 'confirm', 'newpass' ) ) ) :
617 if ( get_option( 'users_can_register' ) ) :
618 $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
619
620 /** This filter is documented in wp-includes/general-template.php */
621 echo apply_filters( 'register', $registration_url );
622
623 echo esc_html( $login_link_separator );
624 endif;
625 ?>
626 <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a>
627 <?php endif; ?>
628 </p>
629 <?php }
630
631 login_footer();
632 break;
633 } // end action switch
634