WordPress.org

Make WordPress Core

Ticket #23295: 23295.2.diff

File 23295.2.diff, 5.0 KB (added by nacin, 9 months ago)
  • wp-includes/default-filters.php

     
    295295add_filter( 'heartbeat_settings', 'wp_heartbeat_settings' ); 
    296296 
    297297// Check if the user is logged out 
    298 add_action( 'admin_init', 'wp_auth_check_load' ); 
     298add_action( 'admin_enqueue_scripts',     'wp_auth_check_load'   ); 
     299add_filter( 'heartbeat_received',        'wp_auth_check', 10, 2 ); 
     300add_filter( 'heartbeat_nopriv_received', 'wp_auth_check', 10, 2 ); 
    299301 
    300302unset($filter, $action); 
  • wp-includes/functions.php

     
    39163916 
    39173917/** 
    39183918 * 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' ); 
    39203919 * 
     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 * 
    39213926 * @since 3.6.0 
    3922  * 
    3923  * @return void 
    39243927 */ 
    39253928function wp_auth_check_load() { 
    3926         global $pagenow; 
    3927  
    3928         // Don't load for these types of requests 
    3929         if ( defined('XMLRPC_REQUEST') || defined('IFRAME_REQUEST') || 'wp-login.php' == $pagenow ) 
     3929        if ( ! is_admin() && ! is_user_logged_in() ) 
    39303930                return; 
    39313931 
    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' ); 
     3932        $screen = get_current_screen(); 
     3933        $hidden = array( 'update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network' ); 
     3934        $show = ! in_array( $screen->id, $hidden ); 
    39393935 
    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                 } 
     3936        if ( apply_filters( 'wp_auth_check_load', $show, $screen ) ) { 
     3937                wp_enqueue_style( 'wp-auth-check' ); 
     3938                wp_enqueue_script( 'wp-auth-check' ); 
     3939 
     3940                add_action( 'admin_print_footer_scripts', 'wp_auth_check_html', 5 ); 
     3941                add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 ); 
    39453942        } 
    39463943} 
    39473944 
    39483945/** 
    3949  * Output the HTML that shows the wp-login dialog when the user is no longer logged in 
     3946 * Output the HTML that shows the wp-login dialog when the user is no longer logged in. 
     3947 * 
     3948 * @since 3.6.0 
    39503949 */ 
    39513950function wp_auth_check_html() { 
    39523951        $login_url = wp_login_url(); 
     
    39853984} 
    39863985 
    39873986/** 
    3988  * Check whether a user is still logged in, and act accordingly if not. 
     3987 * Check whether a user is still logged in, for the heartbeat. 
    39893988 * 
     3989 * Send a result that shows a log-in box if the user is no longer logged in, 
     3990 * or if their cookie is within the grace period. 
     3991 * 
    39903992 * @since 3.6.0 
    39913993 */ 
    39923994function 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' ) ); 
     3995        $response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] ); 
     3996        return $response; 
    40013997} 
    40023998 
    40033999/** 
  • wp-includes/js/wp-auth-check.js

     
    11// Interim login dialog 
    22(function($){ 
    3         var wrap, check, next; 
     3        var wrap, check; 
    44 
    55        function show() { 
    66                var parent = $('#wp-auth-check'), form = $('#wp-auth-check-form'), noframe = wrap.find('.wp-auth-fallback-expired'), frame, loaded = false; 
     
    7979                }); 
    8080        } 
    8181 
    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  
    8782        $( 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') ) 
    9285                                show(); 
    93                         else if ( data['wp-auth-check'] != 'show' && ! wrap.hasClass('hidden') ) 
     86                        else if ( data['wp-auth-check'] && ! wrap.hasClass('hidden') ) 
    9487                                hide(); 
    9588                } 
    96         }).on( 'heartbeat-send.wp-auth-check', function( e, data ) { 
    97                 if ( ( new Date() ).getTime() > next ) 
    98                         data['wp-auth-check'] = 1; 
    9989        }).ready( function() { 
    100                 schedule(); 
    10190                wrap = $('#wp-auth-check-wrap'); 
    10291                wrap.find('.wp-auth-check-close').on( 'click', function(e) { 
    10392                        hide();