Bez popisu

compat-wp-login.php 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <?php
  2. /**
  3. * Adjusted according to wp-login.php - WordPress 5.4.2
  4. */
  5. if (!defined('ABSPATH')) {
  6. exit;
  7. }
  8. /**
  9. * Output the login page header.
  10. *
  11. * @param string $title Optional. WordPress login Page title to display in the `<title>` element.
  12. * Default 'Log In'.
  13. * @param string $message Optional. Message to display in header. Default empty.
  14. * @param WP_Error $wp_error Optional. The error to pass. Default empty.
  15. */
  16. function login_header( $title = 'Log In', $message = '', $wp_error = '' ) {
  17. global $error, $interim_login, $action;
  18. // Don't index any of these forms
  19. if (function_exists('wp_sensitive_page_meta')) {
  20. /**
  21. * wp_sensitive_page_meta() was introduced in 5.0.1
  22. */
  23. add_action('login_head', 'wp_sensitive_page_meta');
  24. } else {
  25. add_action('login_head', 'wp_no_robots');
  26. }
  27. add_action('login_head', 'wp_login_viewport_meta');
  28. if (!is_wp_error($wp_error)) {
  29. $wp_error = new WP_Error();
  30. }
  31. // Shake it!
  32. $shake_error_codes = array(
  33. 'empty_password',
  34. 'empty_email',
  35. 'invalid_email',
  36. 'invalidcombo',
  37. 'empty_username',
  38. 'invalid_username',
  39. 'incorrect_password'
  40. );
  41. /**
  42. * Filters the error codes array for shaking the login form.
  43. *
  44. * @param array $shake_error_codes Error codes that shake the login form.
  45. *
  46. * @since 3.0.0
  47. *
  48. */
  49. $shake_error_codes = apply_filters('shake_error_codes', $shake_error_codes);
  50. if ($shake_error_codes && $wp_error->get_error_code() && in_array($wp_error->get_error_code(), $shake_error_codes, true)) add_action('login_footer', 'wp_shake_js', 12);
  51. $login_title = get_bloginfo('name', 'display');
  52. /* translators: Login screen title. 1: Login screen name, 2: Network or site name */
  53. $login_title = sprintf(__('%1$s &lsaquo; %2$s &#8212; WordPress'), $title, $login_title);
  54. /**
  55. * Filters the title tag content for login page.
  56. *
  57. * @param string $login_title The page title, with extra context added.
  58. * @param string $title The original page title.
  59. *
  60. * @since 4.9.0
  61. *
  62. */
  63. $login_title = apply_filters('login_title', $login_title, $title);
  64. ?><!DOCTYPE html>
  65. <!--[if IE 8]>
  66. <html xmlns="http://www.w3.org/1999/xhtml" class="ie8" <?php language_attributes(); ?>>
  67. <![endif]-->
  68. <!--[if !(IE 8) ]><!-->
  69. <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
  70. <!--<![endif]-->
  71. <head>
  72. <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>"/>
  73. <title><?php echo $login_title; ?></title>
  74. <?php
  75. wp_enqueue_style('login');
  76. /*
  77. * Remove all stored post data on logging out.
  78. * This could be added by add_action('login_head'...) like wp_shake_js(),
  79. * but maybe better if it's not removable by plugins
  80. */
  81. if ('loggedout' == $wp_error->get_error_code()) {
  82. ?>
  83. <script>if ("sessionStorage" in window) {
  84. try {
  85. for (var key in sessionStorage) {
  86. if (key.indexOf("wp-autosave-") != -1) {
  87. sessionStorage.removeItem(key)
  88. }
  89. }
  90. } catch (e) {
  91. }
  92. }
  93. </script>
  94. <?php
  95. }
  96. /**
  97. * Enqueue scripts and styles for the login page.
  98. *
  99. * @since 3.1.0
  100. */
  101. do_action('login_enqueue_scripts');
  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. if (is_multisite()) {
  109. $login_header_url = network_home_url();
  110. $login_header_title = get_network()->site_name;
  111. } else {
  112. $login_header_url = __('https://wordpress.org/');
  113. $login_header_title = __('Powered by WordPress');
  114. }
  115. /**
  116. * Filters link URL of the header logo above login form.
  117. *
  118. * @param string $login_header_url Login header logo URL.
  119. *
  120. * @since 2.1.0
  121. *
  122. */
  123. $login_header_url = apply_filters('login_headerurl', $login_header_url);
  124. /**
  125. * Filters the title attribute of the header logo above login form.
  126. *
  127. * @param string $login_header_title Login header logo title attribute.
  128. *
  129. * @since 2.1.0
  130. *
  131. */
  132. $login_header_title = apply_filters('login_headertitle', $login_header_title);
  133. /*
  134. * To match the URL/title set above, Multisite sites have the blog name,
  135. * while single sites get the header title.
  136. */
  137. if (is_multisite()) {
  138. $login_header_text = get_bloginfo('name', 'display');
  139. } else {
  140. $login_header_text = $login_header_title;
  141. }
  142. /**
  143. * Filters the link text of the header logo above the login form.
  144. *
  145. * @param string $login_header_text The login header logo link text.
  146. *
  147. * @since 5.2.0
  148. *
  149. */
  150. $login_header_text = apply_filters('login_headertext', $login_header_text);
  151. $classes = array(
  152. 'login-action-' . $action,
  153. 'wp-core-ui'
  154. );
  155. if (is_rtl()) $classes[] = 'rtl';
  156. if ($interim_login) {
  157. $classes[] = 'interim-login';
  158. ?>
  159. <style type="text/css">html {
  160. background-color: transparent;
  161. }</style>
  162. <?php
  163. if ('success' === $interim_login) $classes[] = 'interim-login-success';
  164. }
  165. $classes[] = ' locale-' . sanitize_html_class(strtolower(str_replace('_', '-', get_locale())));
  166. /**
  167. * Filters the login page body classes.
  168. *
  169. * @param array $classes An array of body classes.
  170. * @param string $action The action that brought the visitor to the login page.
  171. *
  172. * @since 3.5.0
  173. *
  174. */
  175. $classes = apply_filters('login_body_class', $classes, $action);
  176. ?>
  177. </head>
  178. <body class="login <?php echo esc_attr(implode(' ', $classes)); ?>">
  179. <?php
  180. /**
  181. * Fires in the login page header after the body tag is opened.
  182. *
  183. * @since 4.6.0
  184. */
  185. do_action('login_header');
  186. ?>
  187. <div id="login">
  188. <h1>
  189. <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>
  190. </h1>
  191. <?php
  192. unset($login_header_url, $login_header_title);
  193. /**
  194. * Filters the message to display above the login form.
  195. *
  196. * @param string $message Login message text.
  197. *
  198. * @since 2.1.0
  199. *
  200. */
  201. $message = apply_filters('login_message', $message);
  202. if (!empty($message)) echo $message . "\n";
  203. // In case a plugin uses $error rather than the $wp_errors object
  204. if (!empty($error)) {
  205. $wp_error->add('error', $error);
  206. unset($error);
  207. }
  208. if ($wp_error->get_error_code()) {
  209. $errors = '';
  210. $messages = '';
  211. foreach ($wp_error->get_error_codes() as $code) {
  212. $severity = $wp_error->get_error_data($code);
  213. foreach ($wp_error->get_error_messages($code) as $error_message) {
  214. if ('message' == $severity) $messages .= ' ' . $error_message . "<br />\n"; 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. * @param string $errors Login error message.
  223. *
  224. * @since 2.1.0
  225. *
  226. */
  227. echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
  228. }
  229. if (!empty($messages)) {
  230. /**
  231. * Filters instructional messages displayed above the login form.
  232. *
  233. * @param string $messages Login messages.
  234. *
  235. * @since 2.5.0
  236. *
  237. */
  238. echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
  239. }
  240. }
  241. } // End of login_header()
  242. /**
  243. * Outputs the footer for the login page.
  244. *
  245. * @param string $input_id Which input to auto-focus
  246. */
  247. function login_footer($input_id = '') {
  248. global $interim_login;
  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
  256. if (function_exists('the_privacy_policy_link')) {
  257. the_privacy_policy_link('<div class="privacy-policy-page-link">', '</div>');
  258. }
  259. ?>
  260. <?php endif; ?>
  261. </div>
  262. <?php if (!empty($input_id)) : ?>
  263. <script type="text/javascript">
  264. try {
  265. document.getElementById('<?php echo $input_id; ?>').focus();
  266. } catch (e) {
  267. }
  268. if (typeof wpOnload == 'function') wpOnload();
  269. </script>
  270. <?php endif; ?>
  271. <?php
  272. /**
  273. * Fires in the login page footer.
  274. *
  275. * @since 3.1.0
  276. */
  277. do_action('login_footer'); ?>
  278. <div class="clear"></div>
  279. </body>
  280. </html>
  281. <?php
  282. }
  283. /**
  284. * Outputs the Javascript to handle the form shaking.
  285. *
  286. * @since 3.0.0
  287. */
  288. function wp_shake_js() {
  289. ?>
  290. <script type="text/javascript">
  291. document.querySelector('form').classList.add('shake');
  292. </script>
  293. <?php
  294. }
  295. /**
  296. * @since 3.7.0
  297. */
  298. function wp_login_viewport_meta() {
  299. ?>
  300. <meta name="viewport" content="width=device-width"/>
  301. <?php
  302. }
  303. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'login';
  304. if (!in_array($action, array(
  305. 'postpass',
  306. 'logout',
  307. 'lostpassword',
  308. 'retrievepassword',
  309. 'resetpass',
  310. 'rp',
  311. 'register',
  312. 'login'
  313. ), true) && false === has_filter('login_form_' . $action)) $action = 'login';
  314. nocache_headers();