Make WordPress Core

Ticket #23295: 23295.3.diff

File 23295.3.diff, 5.1 KB (added by nacin, 11 years 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;
     3929        if ( ! is_admin() && ! is_user_logged_in() )
     3930                return;
    39273931
    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' ) )
    39303933                return;
    39313934
    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 );
    39393938
    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 );
    39453945        }
    39463946}
    39473947
    39483948/**
    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
    39503952 */
    39513953function wp_auth_check_html() {
    39523954        $login_url = wp_login_url();
     
    39853987}
    39863988
    39873989/**
    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.
    39893991 *
     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 *
    39903995 * @since 3.6.0
    39913996 */
    39923997function 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;
    40014000}
    40024001
    40034002/**
  • 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();