Ticket #23295: 23295.patch

File 23295.patch, 12.3 KB (added by mintindeed, 3 months ago)
  • wp-includes/default-filters.php

     
    293293// Default settings for heartbeat 
    294294add_filter( 'heartbeat_settings', 'wp_heartbeat_settings' ); 
    295295 
     296// Ready WP_Auth_Check 
     297add_action( 'init', 'wp_auth_check_load' ); 
     298 
     299 
    296300unset($filter, $action); 
     301 
     302//EOF 
  • wp-includes/js/wp-auth-check.js

     
     1/** 
     2 * WP Auth Check object 
     3 */ 
     4wp_auth_check = { 
     5 
     6        /** 
     7         * Holds the button state so we aren't unnecessarily enabling/disabling 
     8         * and so we don't have to continually check a bunch of stuff 
     9         * 
     10         * @var bool 
     11         */ 
     12        buttons_disabled: false, 
     13 
     14        /** 
     15         * Holds the ID of the notice container so that the notice parts can be abstracted out 
     16         * 
     17         * @var string 
     18         */ 
     19        notice_container_id: "wp-auth-check-notice", 
     20 
     21        /** 
     22         * Holds the notice container's jQuery object 
     23         * 
     24         * @var obj|null 
     25         */ 
     26        notice_container: null, 
     27 
     28        /** 
     29         * Boots up the wp_auth_check object and heartbeat listener 
     30         * 
     31         * @return void 
     32         */ 
     33        init: function() { 
     34                if ( "true" == wp_auth_check_opts.is_interim_login ) { 
     35                        this.hijack_interim_login_close_button(); 
     36                        return; // no auth check on the login screen 
     37                } 
     38 
     39                jQuery( document ).on( "heartbeat-tick.auth-check", function( e, data ) { 
     40                        if ( ! data["auth-check"] ) { 
     41                                wp_auth_check.show_login_notice(); 
     42                                return; 
     43                        } 
     44 
     45                        if ( "logged_in" == data["auth-check"] ) { 
     46                                wp_auth_check.hide_login_notice(); 
     47                                return; 
     48                        } 
     49 
     50                        var container_html = ( data["auth-check-html"] ) ? data["auth-check-html"] : ""; 
     51 
     52                        wp_auth_check.show_login_notice( container_html ); 
     53                } ); 
     54 
     55        }, 
     56 
     57        /** 
     58         * Display a login window and disable the save buttons 
     59         * show_notice() has been abstracted out to make it easier to refactor it 
     60         * into a more generic notification object for general use. 
     61         * 
     62         * @return void 
     63         */ 
     64        show_login_notice: function( container_html ) { 
     65                if ( this.notice_is_visible() ) { 
     66                        return; 
     67                } 
     68 
     69                var message = "<p>" + wp_auth_check_text.not_logged_in + "</p>"; 
     70                message += '<p><a href="#" class="button" onclick="wp_auth_check.show_interim_login();">' + wp_auth_check_text.log_in + '</a></p>'; 
     71                message += "<p>" + wp_auth_check_text.after_login_button + "</p>"; 
     72 
     73                wp_auth_check.show_notice( message, container_html ); 
     74 
     75                wp_auth_check.disable_action_buttons(); 
     76        }, 
     77 
     78        /** 
     79         * Hides the notice container and re-enables action buttons 
     80         * hide_notice() has been abstracted out to make it easier to refactor it 
     81         * into a more generic notification object for general use. 
     82         * 
     83         * @return void 
     84         */ 
     85        hide_login_notice: function() { 
     86                if ( ! this.notice_is_visible() ) { 
     87                        return; 
     88                } 
     89 
     90                this.hide_notice(); 
     91 
     92                this.enable_action_buttons(); 
     93        }, 
     94 
     95        /** 
     96         * Fills the notice window with the interim login page 
     97         * 
     98         * @return void 
     99         */ 
     100        show_interim_login: function() { 
     101                this.notice_container.html( "" ).html( '<iframe width="' + this.notice_container.width() + '" height="' + this.notice_container.height() + '" src="' + wp_auth_check_opts.login_url + '"></iframe>' ); 
     102        }, 
     103 
     104        /** 
     105         * Targets the "Close" button on wp-login.php's "interim login" 
     106         * screen, and binds the click event to close the modal dialogue. 
     107         * 
     108         * @return void 
     109         */ 
     110        hijack_interim_login_close_button: function() { 
     111                jQuery( "#login :button" ).click( function( e ) { 
     112                        parent.window.wp_auth_check.hide_notice(); 
     113                        e.preventDefault(); 
     114                        return false; 
     115                } ); 
     116        }, 
     117 
     118        /** 
     119         * Creates a nice notice overlay on the screen. 
     120         * Based on P2's newNotification() function 
     121         * 
     122         * @param message HTML to put in the notice container 
     123         * @param container_html 
     124         * @return void 
     125         */ 
     126        show_notice: function( message, container_html ) { 
     127                if ( this.notice_is_visible() ) { 
     128                        return; 
     129                } 
     130 
     131                jQuery("body").append( container_html ); 
     132 
     133                this.notice_container = jQuery( "#" + this.notice_container_id ); 
     134 
     135                // Calculate the highest z-index on the page, so that this can overlay 
     136                // on top of it 
     137                var highest_z_index = parseInt( this.notice_container.css( "z-index" ) ); 
     138                jQuery( "body" ).find( "*" ).each( function() { 
     139                        var this_z_index = parseInt( jQuery( this ).css( "z-index" ) ); 
     140                        if ( ( ! isNaN( this_z_index ) ) && this_z_index > highest_z_index ) { 
     141                                highest_z_index = this_z_index; 
     142                        } 
     143                } ); 
     144 
     145                this.notice_container 
     146                        .css( "z-index", ( highest_z_index + 1 ) ) 
     147                        .stop( true ) 
     148                        .prepend( message ) 
     149                        .fadeIn(); 
     150        }, 
     151 
     152        /** 
     153         * Hides the #wp-auth-check-notice modal dialogue and re-enables save buttons 
     154         * 
     155         * @return void 
     156         */ 
     157        hide_notice: function() { 
     158                if ( ! this.notice_is_visible() ) { 
     159                        return; 
     160                } 
     161 
     162                this.notice_container 
     163                        .stop( true ) 
     164                        .fadeOut( "fast" ) 
     165                        .remove(); 
     166 
     167                this.notice_container = null; 
     168        }, 
     169 
     170        /** 
     171         * Helper method for checking whether the notice container is present and visible 
     172         * 
     173         * @return bool 
     174         */ 
     175        notice_is_visible: function() { 
     176                return ( this.notice_container && this.notice_container.is( ":visible" ) ); 
     177        }, 
     178 
     179        /** 
     180         * Disable the save/publish/update/move to trash buttons. 
     181         * 
     182         * @return void 
     183         */ 
     184        disable_action_buttons: function() { 
     185                if ( true == wp_auth_check.buttons_disabled ) { 
     186                        return; 
     187                } 
     188 
     189                blockSave = true; 
     190 
     191                jQuery( ":button, :submit, #post-preview, .submitdelete", "#submitpost" ).each( function() { 
     192                        var t = jQuery( this ); 
     193                        if ( t.hasClass( "button-primary" ) ) 
     194                                t.addClass( "button-primary-disabled" ); 
     195                        else 
     196                                t.addClass( "button-disabled" ); 
     197 
     198                        t.prop( "disabled", true ); 
     199                } ); 
     200 
     201                wp_auth_check.buttons_disabled = true; 
     202        }, 
     203 
     204        /** 
     205         * Re-enable the save/publish/update/move to trash buttons. 
     206         * 
     207         * @return void 
     208         */ 
     209        enable_action_buttons: function() { 
     210                if ( false == wp_auth_check.buttons_disabled ) { 
     211                        return; 
     212                } 
     213 
     214                blockSave = false; 
     215 
     216                jQuery( ":button, :submit, #post-preview, .submitdelete", "#submitpost" ).each( function() { 
     217                        var t = jQuery( this ); 
     218                        if ( t.hasClass( "button-primary-disabled" ) ) 
     219                                t.removeClass( "button-primary-disabled" ); 
     220                        else 
     221                                t.removeClass( "button-disabled" ); 
     222 
     223                        t.prop( "disabled", false ); 
     224                } ); 
     225 
     226                wp_auth_check.buttons_disabled = false; 
     227        } 
     228 
     229} 
     230 
     231jQuery( document ).ready( function() { 
     232        wp_auth_check.init(); 
     233} ); 
     234 
     235//EOF 
     236 No newline at end of file 
  • wp-includes/functions.php

     
    38833883 */ 
    38843884function wp_checkdate( $month, $day, $year, $source_date ) { 
    38853885        return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date ); 
    3886 } 
    3887  No newline at end of file 
     3886} 
     3887 
     3888/** 
     3889 * Load the auth check, for monitoring whether the user is still logged in 
     3890 * 
     3891 * @since 3.6.0 
     3892 * 
     3893 * @return void 
     3894 */ 
     3895function wp_auth_check_load() { 
     3896        WP_Auth_Check::get_instance(); 
     3897} 
     3898 
     3899//EOF 
     3900 No newline at end of file 
  • wp-includes/class-wp-auth-check.php

     
     1<?php 
     2/** 
     3 * Test the user's current authorization state 
     4 * 
     5 * @package WordPress 
     6 * @since 3.6.0 
     7 */ 
     8class WP_Auth_Check { 
     9 
     10        /** 
     11         * Holds the singleton instance of this object 
     12         */ 
     13        private static $_instance = null; 
     14 
     15        /** 
     16         * Private constructor because we're a singleton 
     17         */ 
     18        private function __construct() {} 
     19 
     20        /** 
     21         * Initialize the singleton 
     22         */ 
     23        public static function get_instance() { 
     24                $this_class = get_called_class(); // gets the right class when this is extended 
     25                if ( ! ( self::$_instance instanceof $this_class ) ) { 
     26                        self::$_instance = new $this_class; 
     27                        self::$_instance->_init(); 
     28                } 
     29 
     30                return self::$_instance; 
     31        } 
     32 
     33        /** 
     34         * Object init, sets up hooks. Not done in the constructor so that the 
     35         * _init() method may be extended without breaking the singleton. 
     36         */ 
     37        protected function _init() { 
     38                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 
     39 
     40                add_action( 'login_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 
     41 
     42                add_action( 'admin_footer', array( $this, 'render_notice_container' ) ); 
     43 
     44                add_filter( 'heartbeat_send', array( $this, 'test_login' ) ); 
     45 
     46        } 
     47 
     48        public function test_login( $response ) { 
     49                // There are 2 known instances of being logged out: 
     50                // 1) User's login has expired 
     51                // 2) User's /wp-admin/ auth cookie is missing 
     52                // Checking for those two scenarios in case we want to take different 
     53                // action for them in the future. 
     54                if ( ! isset( $_COOKIE[LOGGED_IN_COOKIE] ) ) { 
     55                        $response['auth-check'] = 'not_logged_in'; 
     56                        $response['auth-check-html'] = $this->notice_container(); 
     57                } elseif ( ! wp_validate_auth_cookie() ) { 
     58                        $response['auth-check'] = 'no_admin_auth'; 
     59                        $response['auth-check-html'] = $this->notice_container(); 
     60                } else { 
     61                        $response['auth-check'] = 'logged_in'; // This is what the AJAX poll looks for 
     62                } 
     63 
     64                return $response; 
     65        } 
     66 
     67        /** 
     68         * Enqueue styles, scripts and script data as needed 
     69         */ 
     70        public function enqueue_scripts() { 
     71                wp_enqueue_script( 'wp-auth-check' ); 
     72 
     73                $login_url = add_query_arg( array( 
     74                        'interim-login' => 'true', 
     75                ), wp_login_url( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) ); 
     76 
     77                // Overloading l10n to port variables from PHP to JS 
     78                wp_localize_script( 'wp-auth-check', 'wp_auth_check_opts', array( 
     79                        'login_url' => $login_url, 
     80                        'is_interim_login' => ( isset($GLOBALS['interim_login']) ) ? 'true' : 'false', 
     81                ) ); 
     82 
     83        } 
     84 
     85        /** 
     86         * Enqueue javascript for the interim login screen 
     87         */ 
     88        public function interim_login_enqueue() { 
     89                wp_enqueue_script( 'wp-auth-check' ); 
     90        } 
     91 
     92        /** 
     93         * Adds a div for displaying the login notice 
     94         */ 
     95        public function notice_container() { 
     96                // Inline CSS because it doesn't make sense to use a separate CSS file 
     97                // for 1 rule, and keeps the notice container portable. 
     98                $html = ' 
     99<style> 
     100#wp-auth-check-notice { 
     101        background-color: rgba(0, 0, 0, 0.7); 
     102        color: #FFFFFF; 
     103        font-size: 1.5em; 
     104        text-align: center; 
     105        position: fixed; 
     106        display: none; 
     107        top: 30%; 
     108        left: 33%; 
     109        width: 50%; 
     110        height: 66%; 
     111        margin: -10% 0 0 -10%; 
     112        padding: 30px; 
     113        -webkit-border-radius: 10px; 
     114        -moz-border-radius: 10px; 
     115        border-radius: 10px; 
     116} 
     117</style> 
     118'; 
     119                $html .= '<div id="wp-auth-check-notice"></div>'; 
     120 
     121                return $html; 
     122        } 
     123 
     124} 
     125 
     126// EOF 
     127 No newline at end of file 
  • wp-includes/script-loader.php

     
    348348        $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 ); 
    349349        $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'media-models' ), false, 1 ); 
    350350 
     351        $scripts->add( 'wp-auth-check', "/wp-includes/js/wp-auth-check$suffix.js", array( 'jquery', 'heartbeat' ), false, 1 ); 
     352        did_action( 'init' ) && $scripts->localize( 'wp-auth-check', 'wp_auth_check_text', array( 
     353                'not_logged_in'      => __( 'Oops! Looks like you are not logged in.' ), 
     354                'log_in'             => __( 'Log in' ), 
     355                'after_login_button' => __( 'You will not leave this screen.' ), 
     356        ) ); 
     357 
    351358        if ( is_admin() ) { 
    352359                $scripts->add( 'ajaxcat', "/wp-admin/js/cat$suffix.js", array( 'wp-lists' ) ); 
    353360                $scripts->add_data( 'ajaxcat', 'group', 1 ); 
     
    876883 
    877884add_action( 'wp_default_styles', 'wp_default_styles' ); 
    878885add_filter( 'style_loader_src', 'wp_style_loader_src', 10, 2 ); 
     886 
     887//EOF 
     888 No newline at end of file 
  • wp-settings.php

     
    142142require( ABSPATH . WPINC . '/nav-menu.php' ); 
    143143require( ABSPATH . WPINC . '/nav-menu-template.php' ); 
    144144require( ABSPATH . WPINC . '/admin-bar.php' ); 
     145require( ABSPATH . WPINC . '/class-wp-auth-check.php' ); 
    145146 
    146147// Load multisite-specific files. 
    147148if ( is_multisite() ) { 
     
    325326 * @since 3.0.0 
    326327 */ 
    327328do_action('wp_loaded'); 
     329 
     330//EOF