Ticket #23295: 23295.3.diff
File 23295.3.diff, 5.1 KB (added by , 11 years ago) |
---|
-
wp-includes/default-filters.php
295 295 add_filter( 'heartbeat_settings', 'wp_heartbeat_settings' ); 296 296 297 297 // Check if the user is logged out 298 add_action( 'admin_init', 'wp_auth_check_load' ); 298 add_action( 'admin_enqueue_scripts', 'wp_auth_check_load' ); 299 add_filter( 'heartbeat_received', 'wp_auth_check', 10, 2 ); 300 add_filter( 'heartbeat_nopriv_received', 'wp_auth_check', 10, 2 ); 299 301 300 302 unset($filter, $action); -
wp-includes/functions.php
3916 3916 3917 3917 /** 3918 3918 * Load the auth check for monitoring whether the user is still logged in. 3919 * Can be disabled with remove_action( 'admin_init', 'wp_auth_check_load' );3920 3919 * 3920 * Can be disabled with remove_action( 'admin_enqueue_scripts', 'wp_auth_check_load' ); 3921 * 3922 * This is disabled for certain screens where a login screen could cause an 3923 * inconvenient interruption. A filter called wp_auth_check_load can be used 3924 * for fine-grained control. 3925 * 3921 3926 * @since 3.6.0 3922 *3923 * @return void3924 3927 */ 3925 3928 function wp_auth_check_load() { 3926 global $pagenow; 3929 if ( ! is_admin() && ! is_user_logged_in() ) 3930 return; 3927 3931 3928 // Don't load for these types of requests 3929 if ( defined('XMLRPC_REQUEST') || defined('IFRAME_REQUEST') || 'wp-login.php' == $pagenow ) 3932 if ( defined( 'IFRAME_REQUEST' ) ) 3930 3933 return; 3931 3934 3932 if ( is_admin() || is_user_logged_in() ) { 3933 if ( defined('DOING_AJAX') ) { 3934 add_filter( 'heartbeat_received', 'wp_auth_check', 10, 2 ); 3935 add_filter( 'heartbeat_nopriv_received', 'wp_auth_check', 10, 2 ); 3936 } else { 3937 wp_enqueue_style( 'wp-auth-check' ); 3938 wp_enqueue_script( 'wp-auth-check' ); 3935 $screen = get_current_screen(); 3936 $hidden = array( 'update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network' ); 3937 $show = ! in_array( $screen->id, $hidden ); 3939 3938 3940 if ( is_admin() ) 3941 add_action( 'admin_print_footer_scripts', 'wp_auth_check_html', 5 ); 3942 else 3943 add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 ); 3944 } 3939 if ( apply_filters( 'wp_auth_check_load', $show, $screen ) ) { 3940 wp_enqueue_style( 'wp-auth-check' ); 3941 wp_enqueue_script( 'wp-auth-check' ); 3942 3943 add_action( 'admin_print_footer_scripts', 'wp_auth_check_html', 5 ); 3944 add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 ); 3945 3945 } 3946 3946 } 3947 3947 3948 3948 /** 3949 * Output the HTML that shows the wp-login dialog when the user is no longer logged in 3949 * Output the HTML that shows the wp-login dialog when the user is no longer logged in. 3950 * 3951 * @since 3.6.0 3950 3952 */ 3951 3953 function wp_auth_check_html() { 3952 3954 $login_url = wp_login_url(); … … 3985 3987 } 3986 3988 3987 3989 /** 3988 * Check whether a user is still logged in, and act accordingly if not.3990 * Check whether a user is still logged in, for the heartbeat. 3989 3991 * 3992 * Send a result that shows a log-in box if the user is no longer logged in, 3993 * or if their cookie is within the grace period. 3994 * 3990 3995 * @since 3.6.0 3991 3996 */ 3992 3997 function wp_auth_check( $response, $data ) { 3993 if ( ! isset( $data['wp-auth-check'] ) ) 3994 return $response; 3995 3996 // If the user is logged in and we are outside the login grace period, bail. 3997 if ( is_user_logged_in() && empty( $GLOBALS['login_grace_period'] ) ) 3998 return array_merge( $response, array( 'wp-auth-check' => '1' ) ); 3999 4000 return array_merge( $response, array( 'wp-auth-check' => 'show' ) ); 3998 $response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] ); 3999 return $response; 4001 4000 } 4002 4001 4003 4002 /** -
wp-includes/js/wp-auth-check.js
1 1 // Interim login dialog 2 2 (function($){ 3 var wrap, check , next;3 var wrap, check; 4 4 5 5 function show() { 6 6 var parent = $('#wp-auth-check'), form = $('#wp-auth-check-form'), noframe = wrap.find('.wp-auth-fallback-expired'), frame, loaded = false; … … 79 79 }); 80 80 } 81 81 82 function schedule() {83 var interval = parseInt( window.authcheckL10n.interval, 10 ) || 180; // in seconds, default 3 min.84 next = ( new Date() ).getTime() + ( interval * 1000 );85 }86 87 82 $( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) { 88 if ( data['wp-auth-check'] ) { 89 schedule(); 90 91 if ( data['wp-auth-check'] == 'show' && wrap.hasClass('hidden') ) 83 if ( 'wp-auth-check' in data ) { 84 if ( ! data['wp-auth-check'] && wrap.hasClass('hidden') ) 92 85 show(); 93 else if ( data['wp-auth-check'] != 'show'&& ! wrap.hasClass('hidden') )86 else if ( data['wp-auth-check'] && ! wrap.hasClass('hidden') ) 94 87 hide(); 95 88 } 96 }).on( 'heartbeat-send.wp-auth-check', function( e, data ) {97 if ( ( new Date() ).getTime() > next )98 data['wp-auth-check'] = 1;99 89 }).ready( function() { 100 schedule();101 90 wrap = $('#wp-auth-check-wrap'); 102 91 wrap.find('.wp-auth-check-close').on( 'click', function(e) { 103 92 hide();