PluginProbe
LoginPress | wp-login Custom Login Page Customizer / 1.1.11
LoginPress | wp-login Custom Login Page Customizer v1.1.11
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 1.1.11, at include/template-loginpress.php

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