WordPress.org

Make WordPress Core

Ticket #23295: 23295-6.patch

File 23295-6.patch, 1.5 KB (added by azaozz, 5 years ago)
  • wp-admin/includes/misc.php

     
    655655        <?php
    656656}
    657657add_action( 'admin_footer', '_local_storage_notice' );
     658
     659/**
     660 * Keep and return the time left until login expiration.
     661 * Should be called after current_user is set.
     662 *
     663 * @since 3.6
     664 *
     665 * @param $args When this function is called from the action, an array of the cookie elements.
     666 * @return mixed The time left until login expires (in seconds) or false on error/unknown.
     667 */
     668function wp_logout_time( $args = false ) {
     669        static $logout_time = 0;
     670
     671        if ( $args !== false ) {
     672                if ( is_array( $args ) && isset( $args['expiration'] ) )
     673                        $logout_time = (int) $args['expiration'];
     674
     675                return;
     676        }
     677
     678        if ( $logout_time > time() )
     679                $time_left = $logout_time - time();
     680        else
     681                $time_left = false;
     682        // Let plugins override if they know better.
     683        return apply_filters( 'wp_logout_time', $time_left );
     684}
     685add_action( 'auth_cookie_valid', 'wp_logout_time' );
     686
     687function _login_again_early() {
     688        if ( defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') || 'POST' == $_SERVER['REQUEST_METHOD'] )
     689                return;
     690
     691        if ( ( $time_left = wp_logout_time() ) && $time_left < 30 * MINUTE_IN_SECONDS ) {
     692                wp_redirect( wp_login_url( $_SERVER['REQUEST_URI'] ) );
     693                exit;
     694        }
     695}
     696add_action( 'admin_init', '_login_again_early' );