Advertisement
Agilphil

wp-login.php

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