Fire wp_auth_check_load() from admin_enqueue_scripts instead of admin_init so that it can access the current screen object.

Black list the update and upgrade screens.

Allow plugins to white/black list screens via the wp_auth_check_load filter.

Props nacin

see #23295


git-svn-id: http://core.svn.wordpress.org/trunk@24738 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Ryan Boren 2013-07-18 19:06:35 +00:00
parent e66153a110
commit cbf77c6523
3 changed files with 35 additions and 35 deletions

View File

@ -295,6 +295,8 @@ add_filter( 'default_option_embed_autourls', '__return_true' );
add_filter( 'heartbeat_settings', 'wp_heartbeat_settings' ); add_filter( 'heartbeat_settings', 'wp_heartbeat_settings' );
// Check if the user is logged out // Check if the user is logged out
add_action( 'admin_init', 'wp_auth_check_load' ); add_action( 'admin_enqueue_scripts', 'wp_auth_check_load' );
add_filter( 'heartbeat_received', 'wp_auth_check', 10, 2 );
add_filter( 'heartbeat_nopriv_received', 'wp_auth_check', 10, 2 );
unset($filter, $action); unset($filter, $action);

View File

@ -3916,37 +3916,39 @@ function wp_checkdate( $month, $day, $year, $source_date ) {
/** /**
* Load the auth check for monitoring whether the user is still logged in. * Load the auth check for monitoring whether the user is still logged in.
* Can be disabled with remove_action( 'admin_init', 'wp_auth_check_load' ); *
* Can be disabled with remove_action( 'admin_enqueue_scripts', 'wp_auth_check_load' );
*
* This is disabled for certain screens where a login screen could cause an
* inconvenient interruption. A filter called wp_auth_check_load can be used
* for fine-grained control.
* *
* @since 3.6.0 * @since 3.6.0
*
* @return void
*/ */
function wp_auth_check_load() { function wp_auth_check_load() {
global $pagenow; if ( ! is_admin() && ! is_user_logged_in() )
// Don't load for these types of requests
if ( defined('XMLRPC_REQUEST') || defined('IFRAME_REQUEST') || 'wp-login.php' == $pagenow )
return; return;
if ( is_admin() || is_user_logged_in() ) { if ( defined( 'IFRAME_REQUEST' ) )
if ( defined('DOING_AJAX') ) { return;
add_filter( 'heartbeat_received', 'wp_auth_check', 10, 2 );
add_filter( 'heartbeat_nopriv_received', 'wp_auth_check', 10, 2 );
} else {
wp_enqueue_style( 'wp-auth-check' );
wp_enqueue_script( 'wp-auth-check' );
if ( is_admin() ) $screen = get_current_screen();
add_action( 'admin_print_footer_scripts', 'wp_auth_check_html', 5 ); $hidden = array( 'update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network' );
else $show = ! in_array( $screen->id, $hidden );
add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 );
} if ( apply_filters( 'wp_auth_check_load', $show, $screen ) ) {
wp_enqueue_style( 'wp-auth-check' );
wp_enqueue_script( 'wp-auth-check' );
add_action( 'admin_print_footer_scripts', 'wp_auth_check_html', 5 );
add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 );
} }
} }
/** /**
* Output the HTML that shows the wp-login dialog when the user is no longer logged in * Output the HTML that shows the wp-login dialog when the user is no longer logged in.
*
* @since 3.6.0
*/ */
function wp_auth_check_html() { function wp_auth_check_html() {
$login_url = wp_login_url(); $login_url = wp_login_url();
@ -3985,19 +3987,16 @@ function wp_auth_check_html() {
} }
/** /**
* Check whether a user is still logged in, and act accordingly if not. * Check whether a user is still logged in, for the heartbeat.
*
* Send a result that shows a log-in box if the user is no longer logged in,
* or if their cookie is within the grace period.
* *
* @since 3.6.0 * @since 3.6.0
*/ */
function wp_auth_check( $response, $data ) { function wp_auth_check( $response, $data ) {
if ( ! isset( $data['wp-auth-check'] ) ) $response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] );
return $response; return $response;
// If the user is logged in and we are outside the login grace period, bail.
if ( is_user_logged_in() && empty( $GLOBALS['login_grace_period'] ) )
return array_merge( $response, array( 'wp-auth-check' => '1' ) );
return array_merge( $response, array( 'wp-auth-check' => 'show' ) );
} }
/** /**

View File

@ -85,17 +85,16 @@
} }
$( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) { $( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) {
if ( data['wp-auth-check'] ) { if ( 'wp-auth-check' in data ) {
schedule(); schedule();
if ( ! data['wp-auth-check'] && wrap.hasClass('hidden') )
if ( data['wp-auth-check'] == 'show' && wrap.hasClass('hidden') )
show(); show();
else if ( data['wp-auth-check'] != 'show' && ! wrap.hasClass('hidden') ) else if ( data['wp-auth-check'] && ! wrap.hasClass('hidden') )
hide(); hide();
} }
}).on( 'heartbeat-send.wp-auth-check', function( e, data ) { }).on( 'heartbeat-send.wp-auth-check', function( e, data ) {
if ( ( new Date() ).getTime() > next ) if ( ( new Date() ).getTime() > next )
data['wp-auth-check'] = 1; data['wp-auth-check'] = true;
}).ready( function() { }).ready( function() {
schedule(); schedule();
wrap = $('#wp-auth-check-wrap'); wrap = $('#wp-auth-check-wrap');