login-header.php
212 lines
| 1 | <?php |
| 2 | defined( 'ABSPATH' ) || exit; |
| 3 | |
| 4 | /** |
| 5 | * Output the login page header. |
| 6 | * |
| 7 | * @param string $title Optional. WordPress login Page title to display in the `<title>` element. |
| 8 | * Default 'Log In'. |
| 9 | * @param string $message Optional. Message to display in header. Default empty. |
| 10 | * @param WP_Error $wp_error Optional. The error to pass. Default is a WP_Error instance. |
| 11 | */ |
| 12 | function login_header( $title = 'Log In', $message = '', $wp_error = null ) { |
| 13 | |
| 14 | global $error, $interim_login, $action; |
| 15 | |
| 16 | // Don't index any of these forms. |
| 17 | add_filter( 'wp_robots', 'wp_robots_sensitive_page' ); |
| 18 | add_action( 'login_head', 'wp_strict_cross_origin_referrer' ); |
| 19 | |
| 20 | add_action( 'login_head', 'wp_login_viewport_meta' ); |
| 21 | |
| 22 | if ( ! is_wp_error( $wp_error ) ) { |
| 23 | $wp_error = new WP_Error(); |
| 24 | } |
| 25 | // Shake it! |
| 26 | $shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password' ); |
| 27 | /** |
| 28 | * Filters the error codes array for shaking the login form. |
| 29 | * |
| 30 | * @since 3.0.0 |
| 31 | * |
| 32 | * @param array $shake_error_codes Error codes that shake the login form. |
| 33 | */ |
| 34 | $shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes ); |
| 35 | if ( $shake_error_codes && $wp_error->get_error_code() && in_array( $wp_error->get_error_code(), $shake_error_codes ) ) { |
| 36 | add_action( 'login_head', 'wp_shake_js', 12 ); |
| 37 | } |
| 38 | $login_title = \esc_html( get_bloginfo( 'name', 'display' ) ); |
| 39 | /* translators: Login screen title. 1: Login screen name, 2: Network or site name */ |
| 40 | $login_title = sprintf( __( '%1$s ‹ %2$s — WordPress' ), $title, $login_title ); |
| 41 | /** |
| 42 | * Filters the title tag content for login page. |
| 43 | * |
| 44 | * @since 4.9.0 |
| 45 | * |
| 46 | * @param string $login_title The page title, with extra context added. |
| 47 | * @param string $title The original page title. |
| 48 | */ |
| 49 | $login_title = apply_filters( 'login_title', $login_title, $title ); |
| 50 | ?><!DOCTYPE html> |
| 51 | <!--[if IE 8]> |
| 52 | <html xmlns="http://www.w3.org/1999/xhtml" class="ie8" <?php language_attributes(); ?>> |
| 53 | <![endif]--> |
| 54 | <!--[if !(IE 8) ]><!--> |
| 55 | <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> |
| 56 | <!--<![endif]--> |
| 57 | <head> |
| 58 | <meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php bloginfo( 'charset' ); ?>" /> |
| 59 | <title><?php echo \esc_html( $login_title ); ?></title> |
| 60 | <?php |
| 61 | wp_enqueue_style( 'login' ); |
| 62 | |
| 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 ( \WP2FA\Admin\Helpers\WP_Helper::is_multisite() ) { |
| 86 | $login_header_url = network_home_url(); |
| 87 | $login_header_title = get_network()->site_name; |
| 88 | } else { |
| 89 | $login_header_url = __( 'https://wordpress.org/' ); |
| 90 | $login_header_title = __( 'Powered by WordPress' ); |
| 91 | } |
| 92 | /** |
| 93 | * Filters link URL of the header logo above login form. |
| 94 | * |
| 95 | * @since 2.1.0 |
| 96 | * |
| 97 | * @param string $login_header_url Login header logo URL. |
| 98 | */ |
| 99 | $login_header_url = apply_filters( 'login_headerurl', $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 | $login_header_title = apply_filters( 'login_headertitle', $login_header_title ); |
| 108 | /* |
| 109 | * To match the URL/title set above, Multisite sites have the blog name, |
| 110 | * while single sites get the header title. |
| 111 | */ |
| 112 | if ( \WP2FA\Admin\Helpers\WP_Helper::is_multisite() ) { |
| 113 | $login_header_text = get_bloginfo( 'name', 'display' ); |
| 114 | } else { |
| 115 | $login_header_text = $login_header_title; |
| 116 | } |
| 117 | $classes = array( 'login-action-' . $action, 'wp-core-ui', 'admin-color-modern' ); |
| 118 | if ( is_rtl() ) { |
| 119 | $classes[] = 'rtl'; |
| 120 | } |
| 121 | if ( $interim_login ) { |
| 122 | $classes[] = 'interim-login'; |
| 123 | ?> |
| 124 | <style type="text/css">html{background-color: transparent;}</style> |
| 125 | <?php |
| 126 | if ( 'success' === $interim_login ) { |
| 127 | $classes[] = 'interim-login-success'; |
| 128 | } |
| 129 | } |
| 130 | $classes[] = ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) ); |
| 131 | /** |
| 132 | * Filters the login page body classes. |
| 133 | * |
| 134 | * @since 3.5.0 |
| 135 | * |
| 136 | * @param array $classes An array of body classes. |
| 137 | * @param string $action The action that brought the visitor to the login page. |
| 138 | */ |
| 139 | $classes = apply_filters( 'login_body_class', $classes, $action ); |
| 140 | ?> |
| 141 | </head> |
| 142 | <body class="login <?php echo esc_attr( implode( ' ', $classes ) ); ?>"> |
| 143 | <?php |
| 144 | /** |
| 145 | * Fires in the login page header after the body tag is opened. |
| 146 | * |
| 147 | * @since 4.6.0 |
| 148 | */ |
| 149 | do_action( 'login_header' ); |
| 150 | ?> |
| 151 | <div id="login"> |
| 152 | <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> |
| 153 | <?php |
| 154 | unset( $login_header_url, $login_header_title ); |
| 155 | /** |
| 156 | * Filters the message to display above the login form. |
| 157 | * |
| 158 | * @since 2.1.0 |
| 159 | * |
| 160 | * @param string $message Login message text. |
| 161 | */ |
| 162 | $message = apply_filters( 'login_message', $message ); |
| 163 | if ( ! empty( $message ) ) { |
| 164 | echo $message . "\n"; |
| 165 | } |
| 166 | // In case a plugin uses $error rather than the $wp_errors object. |
| 167 | if ( ! empty( $error ) ) { |
| 168 | $wp_error->add( 'error', $error ); |
| 169 | unset( $error ); |
| 170 | } |
| 171 | if ( $wp_error->get_error_code() ) { |
| 172 | $errors = ''; |
| 173 | $messages = ''; |
| 174 | foreach ( $wp_error->get_error_codes() as $code ) { |
| 175 | $severity = $wp_error->get_error_data( $code ); |
| 176 | foreach ( $wp_error->get_error_messages( $code ) as $error_message ) { |
| 177 | if ( 'message' == $severity ) { |
| 178 | $messages .= ' ' . $error_message . "<br />\n"; |
| 179 | } else { |
| 180 | $errors .= ' ' . $error_message . "<br />\n"; |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | if ( ! empty( $errors ) ) { |
| 185 | /** |
| 186 | * Filters the error messages displayed above the login form. |
| 187 | * |
| 188 | * @since 2.1.0 |
| 189 | * |
| 190 | * @param string $errors Login error message. |
| 191 | */ |
| 192 | echo '<div id="login_error">' . apply_filters( 'login_errors', $errors ) . "</div>\n"; |
| 193 | } |
| 194 | if ( ! empty( $messages ) ) { |
| 195 | /** |
| 196 | * Filters instructional messages displayed above the login form. |
| 197 | * |
| 198 | * @since 2.5.0 |
| 199 | * |
| 200 | * @param string $messages Login messages. |
| 201 | */ |
| 202 | echo '<p class="message">' . apply_filters( 'login_messages', $messages ) . "</p>\n"; |
| 203 | } |
| 204 | } |
| 205 | } // End of login_header(). |
| 206 | |
| 207 | function wp_login_viewport_meta() { |
| 208 | ?> |
| 209 | <meta name="viewport" content="width=device-width" /> |
| 210 | <?php |
| 211 | } |
| 212 |