Agilphil

wp-login

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