Make WordPress Core


Ignore:
Timestamp:
03/01/2013 01:55:33 AM (12 years ago)
Author:
azaozz
Message:

Logged out warnings: restructure the PHP code (no need for a class), props nacin, see #23295

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r23519 r23543  
    38953895 */
    38963896function wp_auth_check_load() {
    3897     if ( ! class_exists('WP_Auth_Check') ) {
    3898         require( ABSPATH . WPINC . '/class-wp-auth-check.php' );
    3899         WP_Auth_Check::get_instance();
    3900     }
    3901 }
     3897    wp_enqueue_script( 'heartbeat' );
     3898    add_filter( 'heartbeat_received', 'wp_auth_check', 10, 2 );
     3899    add_filter( 'heartbeat_nopriv_received', 'wp_auth_check', 10, 2 );
     3900
     3901    if ( is_admin() )
     3902        add_action( 'admin_print_footer_scripts', 'wp_auth_check_js' );
     3903    elseif ( is_user_logged_in() )
     3904        add_action( 'wp_print_footer_scripts', 'wp_auth_check_js' );
     3905}
     3906
     3907/**
     3908 * Output the JS that shows the wp-login iframe when the user is no longer logged in
     3909 */
     3910function wp_auth_check_js() {
     3911    ?>
     3912    <script type="text/javascript">
     3913    (function($){
     3914    $( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) {
     3915        var wrap = $('#wp-auth-check-notice-wrap');
     3916
     3917        if ( data['wp-auth-check-html'] && ! wrap.length ) {
     3918            $('body').append( data['wp-auth-check-html'] );
     3919        } else if ( !data['wp-auth-check-html'] && wrap.length && ! wrap.data('logged-in') ) {
     3920            wrap.remove();
     3921        }
     3922    }).on( 'heartbeat-send.wp-auth-check', function( e, data ) {
     3923        data['wp-auth-check'] = 1;
     3924    });
     3925    }(jQuery));
     3926    </script>
     3927    <?php
     3928}
     3929
     3930/**
     3931 * Check whether a user is still logged in, and act accordingly if not.
     3932 *
     3933 * @since 3.6.0
     3934 */
     3935function wp_auth_check( $response, $data ) {
     3936    if ( ! isset( $data['wp-auth-check'] ) )
     3937        return $response;
     3938
     3939    // If the user is logged in and we are outside the login grace period, bail.
     3940    if ( is_user_logged_in() && empty( $GLOBALS['login_grace_period'] ) )
     3941        return $response;
     3942
     3943    return array_merge( $response, array(
     3944        'wp-auth-check-html' => '<div id="wp-auth-check-notice-wrap">
     3945<style type="text/css" scoped>
     3946#wp-auth-check {
     3947    position: fixed;
     3948    height: 90%;
     3949    left: 50%;
     3950    max-height: 415px;
     3951    overflow: auto;
     3952    top: 35px;
     3953    width: 300px;
     3954    margin: 0 0 0 -160px;
     3955    padding: 12px 20px;
     3956    border: 1px solid #ddd;
     3957    background-color: #fbfbfb;
     3958    -webkit-border-radius: 3px;
     3959    border-radius: 3px;
     3960    z-index: 1000000000;
     3961}
     3962#wp-auth-check-form {
     3963    background: url("' . admin_url('/images/wpspin_light-2x.gif') . '") no-repeat center center;
     3964    background-size: 16px 16px;
     3965}
     3966#wp-auth-check-form iframe {
     3967    height: 100%;
     3968    overflow: hidden;
     3969}
     3970#wp-auth-check a.wp-auth-check-close {
     3971    position: absolute;
     3972    right: 8px;
     3973    top: 8px;
     3974    width: 24px;
     3975    height: 24px;
     3976    background: url("' . includes_url('images/uploader-icons.png') . '") no-repeat scroll -95px center transparent;
     3977}
     3978#wp-auth-check h3 {
     3979    margin: 0 0 12px;
     3980    padding: 0;
     3981    font-size: 1.25em;
     3982}
     3983@media print,
     3984  (-o-min-device-pixel-ratio: 5/4),
     3985  (-webkit-min-device-pixel-ratio: 1.25),
     3986  (min-resolution: 120dpi) {
     3987    #wp-auth-check a.wp-auth-check-close {
     3988        background-image: url("' . includes_url('images/uploader-icons-2x.png') . '");
     3989        background-size: 134px 15px;
     3990    }
     3991}
     3992</style>
     3993<div id="wp-auth-check" tabindex="0">
     3994<h3>' .  __('Session expired') . '</h3>
     3995<a href="#" class="wp-auth-check-close"><span class="screen-reader-text">' . __('close') . '</span></a>
     3996<div id="wp-auth-check-form">
     3997    <iframe src="' . esc_url( add_query_arg( array( 'interim-login' => 1 ), wp_login_url() ) ) . '" frameborder="0"></iframe>
     3998</div>
     3999</div>
     4000<script type="text/javascript">
     4001(function($){
     4002var el, wrap = $("#wp-auth-check-notice-wrap");
     4003el = $("#wp-auth-check").focus().find("a.wp-auth-check-close").on("click", function(e){
     4004    el.fadeOut(200, function(){ wrap.remove(); });
     4005    e.preventDefault();
     4006});
     4007$("#wp-auth-check-form iframe").load(function(){
     4008    var height;
     4009    try { height = $(this.contentWindow.document).find("#login").height(); } catch(er){}
     4010    if ( height ) {
     4011        $("#wp-auth-check").css("max-height", height + 40 + "px");
     4012        $(this).css("height", height + 5 + "px");
     4013        if ( height < 200 ) {
     4014            wrap.data("logged-in", true);
     4015            setTimeout( function(){ wrap.fadeOut(200, function(){ wrap.remove(); }); }, 5000 );
     4016        }
     4017    }
     4018});
     4019}(jQuery));
     4020</script>
     4021</div>' ) );
     4022}
Note: See TracChangeset for help on using the changeset viewer.