Improved logged out warnings, first run, props mintindeed, see #23295
git-svn-id: http://core.svn.wordpress.org/trunk@23504 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ccd6e6aeec
commit
0910d5755e
|
@ -6785,6 +6785,23 @@ a.rsswidget {
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.interim-login #login {
|
||||||
|
padding: 0;
|
||||||
|
width: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.interim-login.login h1 a {
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.interim-login #login_error,
|
||||||
|
.interim-login.login .message {
|
||||||
|
margin: 0 0 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.interim-login.login form {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* ms */
|
/* ms */
|
||||||
/* Dashboard: MS Specific Data */
|
/* Dashboard: MS Specific Data */
|
||||||
|
|
|
@ -0,0 +1,192 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Test the user's current authorization state
|
||||||
|
*
|
||||||
|
* @package WordPress
|
||||||
|
* @since 3.6.0
|
||||||
|
*/
|
||||||
|
class WP_Auth_Check {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds the singleton instance of this object
|
||||||
|
*/
|
||||||
|
private static $_instance = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private constructor because we're a singleton
|
||||||
|
*/
|
||||||
|
private function __construct() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the singleton
|
||||||
|
*/
|
||||||
|
public static function get_instance() {
|
||||||
|
$this_class = get_called_class(); // gets the right class when this is extended
|
||||||
|
if ( ! ( self::$_instance instanceof $this_class ) ) {
|
||||||
|
self::$_instance = new $this_class;
|
||||||
|
self::$_instance->_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object init, sets up hooks. Not done in the constructor so that the
|
||||||
|
* _init() method may be extended without breaking the singleton.
|
||||||
|
*/
|
||||||
|
protected function _init() {
|
||||||
|
if ( is_admin() ) {
|
||||||
|
add_action( 'admin_footer', array( $this, 'enqueue_scripts' ) );
|
||||||
|
add_action( 'admin_print_footer_scripts', array( $this, 'footer_js' ) );
|
||||||
|
} elseif ( is_user_logged_in() ) {
|
||||||
|
add_action( 'wp_footer', array( $this, 'enqueue_scripts' ) );
|
||||||
|
add_action( 'wp_print_footer_scripts', array( $this, 'footer_js' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
add_filter( 'heartbeat_received', array( $this, 'login' ), 10, 2 );
|
||||||
|
add_filter( 'heartbeat_nopriv_received', array( $this, 'nopriv_login' ), 10, 2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the user is still logged in
|
||||||
|
*/
|
||||||
|
public function login( $response, $data ) {
|
||||||
|
if ( array_key_exists('wp-auth-check', $data) && ( ! isset( $_COOKIE[LOGGED_IN_COOKIE] ) || ! wp_validate_auth_cookie() || ! empty( $GLOBALS['login_grace_period'] ) ) )
|
||||||
|
$response['wp-auth-check-html'] = $this->notice();
|
||||||
|
|
||||||
|
|
||||||
|
$response['LOGGED_IN_COOKIE'] = isset( $_COOKIE[LOGGED_IN_COOKIE] );
|
||||||
|
|
||||||
|
$response['wp_validate_auth_cookie'] = wp_validate_auth_cookie();
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs when a user is expected to be logged in
|
||||||
|
* but has logged out or cannot be validated
|
||||||
|
*/
|
||||||
|
public function nopriv_login( $response, $data ) {
|
||||||
|
if ( array_key_exists('wp-auth-check', $data) )
|
||||||
|
$response['wp-auth-check-html'] = $this->notice();
|
||||||
|
|
||||||
|
|
||||||
|
$response['nopriv_login'] = 1;
|
||||||
|
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function footer_js() {
|
||||||
|
?>
|
||||||
|
<script>
|
||||||
|
(function($){
|
||||||
|
$( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) {
|
||||||
|
var wrap = $('#wp-auth-check-notice-wrap');
|
||||||
|
|
||||||
|
if ( data['wp-auth-check-html'] && ! wrap.length ) {
|
||||||
|
$('body').append( data['wp-auth-check-html'] );
|
||||||
|
} else if ( !data['wp-auth-check-html'] && wrap.length && ! wrap.data('logged-in') ) {
|
||||||
|
wrap.remove();
|
||||||
|
}
|
||||||
|
}).on( 'heartbeat-send.wp-auth-check', function( e, data ) {
|
||||||
|
data['wp-auth-check'] = 1;
|
||||||
|
});
|
||||||
|
}(jQuery));
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enqueue_scripts() {
|
||||||
|
// This will also enqueue jQuery
|
||||||
|
wp_enqueue_script( 'heartbeat' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the login notice
|
||||||
|
*/
|
||||||
|
public function notice() {
|
||||||
|
// Inline JS and CSS, keep the notice portable.
|
||||||
|
return '
|
||||||
|
<div id="wp-auth-check-notice-wrap">
|
||||||
|
<style type="text/css" scoped>
|
||||||
|
#wp-auth-check {
|
||||||
|
position: fixed;
|
||||||
|
height: 90%;
|
||||||
|
left: 50%;
|
||||||
|
max-height: 415px;
|
||||||
|
overflow: auto;
|
||||||
|
top: 35px;
|
||||||
|
width: 300px;
|
||||||
|
margin: 0 0 0 -160px;
|
||||||
|
padding: 12px 20px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
background-color: #fbfbfb;
|
||||||
|
-webkit-border-radius: 3px;
|
||||||
|
border-radius: 3px;
|
||||||
|
z-index: 1000000000;
|
||||||
|
}
|
||||||
|
#wp-auth-check-form {
|
||||||
|
background: url("' . admin_url('/images/wpspin_light-2x.gif') . '") no-repeat center center;
|
||||||
|
background-size: 16px 16px;
|
||||||
|
}
|
||||||
|
#wp-auth-check-form iframe {
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
#wp-auth-check a.wp-auth-check-close {
|
||||||
|
position: absolute;
|
||||||
|
right: 8px;
|
||||||
|
top: 8px;
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
background: url("' . includes_url('images/uploader-icons.png') . '") no-repeat scroll -95px center transparent;
|
||||||
|
}
|
||||||
|
#wp-auth-check h3 {
|
||||||
|
margin: 0 0 12px;
|
||||||
|
padding: 0;
|
||||||
|
font-size: 1.25em;
|
||||||
|
}
|
||||||
|
@media print,
|
||||||
|
(-o-min-device-pixel-ratio: 5/4),
|
||||||
|
(-webkit-min-device-pixel-ratio: 1.25),
|
||||||
|
(min-resolution: 120dpi) {
|
||||||
|
#wp-auth-check a.wp-auth-check-close {
|
||||||
|
background-image: url("' . includes_url('images/uploader-icons-2x.png') . '");
|
||||||
|
background-size: 134px 15px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<div id="wp-auth-check" tabindex="0">
|
||||||
|
<h3>' . __('Session expired') . '</h3>
|
||||||
|
<a href="#" class="wp-auth-check-close"><span class="screen-reader-text">' . __('close') . '</span></a>
|
||||||
|
<div id="wp-auth-check-form">
|
||||||
|
<iframe src="' . esc_url( add_query_arg( array( 'interim-login' => 1 ), wp_login_url() ) ) . '" frameborder="0"></iframe>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
(function($){
|
||||||
|
var el, wrap = $("#wp-auth-check-notice-wrap");
|
||||||
|
el = $("#wp-auth-check").focus().find("a.wp-auth-check-close").on("click", function(e){
|
||||||
|
el.fadeOut(200, function(){ wrap.remove(); });
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
$("#wp-auth-check-form iframe").load(function(){
|
||||||
|
var height;
|
||||||
|
try { height = $(this.contentWindow.document).find("#login").height(); } catch(er){}
|
||||||
|
if ( height ) {
|
||||||
|
$("#wp-auth-check").css("max-height", height + 40 + "px");
|
||||||
|
$(this).css("height", height + 5 + "px");
|
||||||
|
if ( height < 200 ) {
|
||||||
|
wrap.data("logged-in", true);
|
||||||
|
setTimeout( function(){ wrap.fadeOut(200, function(){ wrap.remove(); }); }, 5000 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}(jQuery));
|
||||||
|
</script>
|
||||||
|
</div>';
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -294,4 +294,7 @@ add_filter( 'default_option_embed_autourls', '__return_true' );
|
||||||
// Default settings for heartbeat
|
// Default settings for heartbeat
|
||||||
add_filter( 'heartbeat_settings', 'wp_heartbeat_settings' );
|
add_filter( 'heartbeat_settings', 'wp_heartbeat_settings' );
|
||||||
|
|
||||||
|
// Check if the user is logged out
|
||||||
|
add_action( 'admin_init', 'wp_auth_check_load' );
|
||||||
|
|
||||||
unset($filter, $action);
|
unset($filter, $action);
|
||||||
|
|
|
@ -3883,4 +3883,18 @@ function wp_is_stream( $path ) {
|
||||||
*/
|
*/
|
||||||
function wp_checkdate( $month, $day, $year, $source_date ) {
|
function wp_checkdate( $month, $day, $year, $source_date ) {
|
||||||
return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date );
|
return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the auth check, for monitoring whether the user is still logged in
|
||||||
|
*
|
||||||
|
* @since 3.6.0
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function wp_auth_check_load() {
|
||||||
|
if ( ! class_exists('WP_Auth_Check') ) {
|
||||||
|
require( ABSPATH . WPINC . '/class-wp-auth-check.php' );
|
||||||
|
WP_Auth_Check::get_instance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
21
wp-login.php
21
wp-login.php
|
@ -51,7 +51,7 @@ function login_header($title = 'Log In', $message = '', $wp_error = '') {
|
||||||
$shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password' );
|
$shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password' );
|
||||||
$shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes );
|
$shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes );
|
||||||
|
|
||||||
if ( $shake_error_codes && $wp_error->get_error_code() && in_array( $wp_error->get_error_code(), $shake_error_codes ) )
|
if ( ! $interim_login && $shake_error_codes && $wp_error->get_error_code() && in_array( $wp_error->get_error_code(), $shake_error_codes ) )
|
||||||
add_action( 'login_head', 'wp_shake_js', 12 );
|
add_action( 'login_head', 'wp_shake_js', 12 );
|
||||||
|
|
||||||
?><!DOCTYPE html>
|
?><!DOCTYPE html>
|
||||||
|
@ -82,16 +82,19 @@ function login_header($title = 'Log In', $message = '', $wp_error = '') {
|
||||||
$login_header_url = apply_filters( 'login_headerurl', $login_header_url );
|
$login_header_url = apply_filters( 'login_headerurl', $login_header_url );
|
||||||
$login_header_title = apply_filters( 'login_headertitle', $login_header_title );
|
$login_header_title = apply_filters( 'login_headertitle', $login_header_title );
|
||||||
|
|
||||||
// Don't allow interim logins to navigate away from the page.
|
|
||||||
if ( $interim_login )
|
|
||||||
$login_header_url = '#';
|
|
||||||
|
|
||||||
$classes = array( 'login-action-' . $action, 'wp-core-ui' );
|
$classes = array( 'login-action-' . $action, 'wp-core-ui' );
|
||||||
if ( wp_is_mobile() )
|
if ( wp_is_mobile() )
|
||||||
$classes[] = 'mobile';
|
$classes[] = 'mobile';
|
||||||
if ( is_rtl() )
|
if ( is_rtl() )
|
||||||
$classes[] = 'rtl';
|
$classes[] = 'rtl';
|
||||||
|
if ( $interim_login ) {
|
||||||
|
// Don't allow interim logins to navigate away from the page.
|
||||||
|
$login_header_url = '#';
|
||||||
|
$classes[] = 'interim-login';
|
||||||
|
}
|
||||||
|
|
||||||
$classes = apply_filters( 'login_body_class', $classes, $action );
|
$classes = apply_filters( 'login_body_class', $classes, $action );
|
||||||
|
|
||||||
?>
|
?>
|
||||||
</head>
|
</head>
|
||||||
<body class="login <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
|
<body class="login <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
|
||||||
|
@ -613,12 +616,6 @@ default:
|
||||||
if ( $interim_login ) {
|
if ( $interim_login ) {
|
||||||
$message = '<p class="message">' . __('You have logged in successfully.') . '</p>';
|
$message = '<p class="message">' . __('You have logged in successfully.') . '</p>';
|
||||||
login_header( '', $message ); ?>
|
login_header( '', $message ); ?>
|
||||||
|
|
||||||
<?php if ( ! $customize_login ) : ?>
|
|
||||||
<script type="text/javascript">setTimeout( function(){window.close()}, 8000);</script>
|
|
||||||
<p class="alignright">
|
|
||||||
<input type="button" class="button-primary" value="<?php esc_attr_e('Close'); ?>" onclick="window.close()" /></p>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
</div>
|
||||||
<?php do_action( 'login_footer' ); ?>
|
<?php do_action( 'login_footer' ); ?>
|
||||||
<?php if ( $customize_login ) : ?>
|
<?php if ( $customize_login ) : ?>
|
||||||
|
@ -662,7 +659,7 @@ default:
|
||||||
elseif ( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] )
|
elseif ( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] )
|
||||||
$errors->add('registered', __('Registration complete. Please check your e-mail.'), 'message');
|
$errors->add('registered', __('Registration complete. Please check your e-mail.'), 'message');
|
||||||
elseif ( $interim_login )
|
elseif ( $interim_login )
|
||||||
$errors->add('expired', __('Your session has expired. Please log-in again.'), 'message');
|
$errors->add('expired', __('Please log-in again. You will not move away from this page.'), 'message');
|
||||||
elseif ( strpos( $redirect_to, 'about.php?updated' ) )
|
elseif ( strpos( $redirect_to, 'about.php?updated' ) )
|
||||||
$errors->add('updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to experience the awesomeness.' ), 'message' );
|
$errors->add('updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to experience the awesomeness.' ), 'message' );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue