Make WordPress Core

Changeset 21031


Ignore:
Timestamp:
06/08/2012 07:22:11 PM (13 years ago)
Author:
ryan
Message:

Customizer: Gravefully handle cookie expipration. Prompt for log in in the preview. Props ocean90, koopersmith, nacin. fixes #20876

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/css/customize-controls.dev.css

    r21014 r21031  
    515515}
    516516
     517/**
     518 * Handle cheaters.
     519 */
     520body.cheatin {
     521    min-width: 0;
     522    background: #f9f9f9;
     523    padding: 50px;
     524}
     525
     526body.cheatin p {
     527    max-width: 700px;
     528    margin: 0 auto;
     529    padding: 2em;
     530    font-size: 14px;
     531
     532    background: #fff;
     533    border: 1px solid #dfdfdf;
     534
     535    -webkit-border-radius: 3px;
     536    border-radius:         3px;
     537}
  • trunk/wp-admin/customize.php

    r21028 r21031  
    149149    ), home_url( '/' ) );
    150150
     151    $login_url = add_query_arg( array(
     152        'interim-login' => 1,
     153        'customize-login' => 1
     154    ), wp_login_url() );
     155
    151156    $settings = array(
    152157        'theme'    => array(
     
    163168            'fallback'      => $fallback_url,
    164169            'home'          => esc_url( home_url( '/' ) ),
     170            'login'         => $login_url,
    165171        ),
    166172        'browser'  => array(
  • trunk/wp-admin/js/customize-controls.dev.js

    r21029 r21031  
    332332                if ( location && location != self.url() ) {
    333333                    deferred.rejectWith( self, [ 'redirect', location ] );
     334                    return;
     335                }
     336
     337                // Check if the user is not logged in.
     338                if ( '0' === response ) {
     339                    deferred.rejectWith( self, [ 'logged out' ] );
     340                    return;
     341                }
     342
     343                // Check for cheaters.
     344                if ( '-1' === response ) {
     345                    deferred.rejectWith( self, [ 'cheatin' ] );
    334346                    return;
    335347                }
     
    549561                if ( 'redirect' === reason && location )
    550562                    self.url( location );
    551             });
     563
     564                if ( 'logged out' === reason ) {
     565                    if ( self.iframe ) {
     566                        self.iframe.destroy();
     567                        delete self.iframe;
     568                    }
     569
     570                    self.login().done( self.refresh );
     571                }
     572
     573                if ( 'cheatin' === reason )
     574                    self.cheatin();
     575            });
     576        },
     577
     578        login: function() {
     579            var previewer = this,
     580                deferred, messenger, iframe;
     581
     582            if ( this._login )
     583                return this._login;
     584
     585            deferred = $.Deferred();
     586            this._login = deferred.promise();
     587
     588            messenger = new api.Messenger({
     589                channel: 'login',
     590                url:     api.settings.url.login
     591            });
     592
     593            iframe = $('<iframe src="' + api.settings.url.login + '" />').appendTo( this.container );
     594
     595            messenger.targetWindow( iframe[0].contentWindow );
     596
     597            messenger.bind( 'login', function() {
     598                iframe.remove();
     599                messenger.destroy();
     600                delete previewer._login;
     601                deferred.resolve();
     602            });
     603
     604            return this._login;
     605        },
     606
     607        cheatin: function() {
     608            $( document.body ).empty().addClass('cheatin').append( '<p>' + api.l10n.cheatin + '</p>' );
    552609        }
    553610    });
     
    606663
    607664            save: function() {
    608                 var query = $.extend( this.query(), {
     665                var self  = this,
     666                    query = $.extend( this.query(), {
    609667                        action: 'customize_save',
    610668                        nonce:  this.nonce
     
    620678                });
    621679
    622                 request.done( function() {
     680                request.done( function( response ) {
     681                    // Check if the user is logged out.
     682                    if ( '0' === response ) {
     683                        self.iframe.iframe.hide();
     684                        self.login().done( function() {
     685                            self.save();
     686                            self.iframe.iframe.show();
     687                        });
     688                        return;
     689                    }
     690
     691                    // Check for cheaters.
     692                    if ( '-1' === response ) {
     693                        self.cheatin();
     694                        return;
     695                    }
     696
    623697                    api.trigger( 'saved' );
    624698                });
  • trunk/wp-includes/class-wp-customize-manager.php

    r21027 r21031  
    3232        require( ABSPATH . WPINC . '/class-wp-customize-control.php' );
    3333
     34        add_filter( 'wp_die_handler', array( $this, 'wp_die_handler' ) );
     35
    3436        add_action( 'setup_theme',  array( $this, 'setup_theme' ) );
    3537        add_action( 'wp_loaded',    array( $this, 'wp_loaded' ) );
     
    5355    }
    5456
    55     /**
    56      * Start preview and customize theme.
    57      *
    58      * Check if customize query variable exist. Init filters to filter the current theme.
     57    /**
     58     * Return true if it's an AJAX request.
     59     *
     60     * @since 3.4.0
     61     */
     62    public function doing_ajax() {
     63        return isset( $_POST['customized'] ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX );
     64    }
     65
     66    /**
     67     * Custom wp_die wrapper. Returns either the standard message for UI
     68     * or the AJAX message.
     69     *
     70     * @param  mixed $ajax_message AJAX return
     71     * @param  mixed $message      UI message
     72     *
     73     * @since 3.4.0
     74     */
     75    private function wp_die( $ajax_message, $message ) {
     76        if ( $this->doing_ajax() )
     77            wp_die( $ajax_message );
     78
     79        wp_die( $message );
     80    }
     81
     82    /**
     83     * Return the AJAX wp_die() handler if it's a customized request.
     84     *
     85     * @since 3.4.0
     86     */
     87    public function wp_die_handler() {
     88        if ( $this->doing_ajax() )
     89            return '_ajax_wp_die_handler';
     90
     91        return '_default_wp_die_handler';
     92    }
     93    /**
     94    * Start preview and customize theme.
     95    *
     96    * Check if customize query variable exist. Init filters to filter the current theme.
    5997     *
    6098     * @since 3.4.0
    6199     */
    62100    public function setup_theme() {
    63         if ( is_admin() && ! defined( 'DOING_AJAX' ) )
    64             auth_redirect();
     101        if ( is_admin() && ! $this->doing_ajax() )
     102            auth_redirect();
     103        elseif ( $this->doing_ajax() && ! is_user_logged_in())
     104            wp_die( 0 );
    65105
    66106        send_origin_headers();
     
    72112        // You can't preview a theme if it doesn't exist, or if it is not allowed (unless active).
    73113        if ( ! $this->theme->exists() )
    74             wp_die( __( 'Cheatin&#8217; uh?' ) );
     114            $this->wp_die( -1, __( 'Cheatin&#8217; uh?' ) );
    75115
    76116        if ( $this->theme->get_stylesheet() != get_stylesheet() && ( ! $this->theme()->is_allowed() || ! current_user_can( 'switch_themes' ) ) )
    77             wp_die( __( 'Cheatin&#8217; uh?' ) );
     117            $this->wp_die( -1, __( 'Cheatin&#8217; uh?' ) );
    78118
    79119        if ( ! current_user_can( 'edit_theme_options' ) )
    80             wp_die( __( 'Cheatin&#8217; uh?' ) );
     120            $this->wp_die( -1, __( 'Cheatin&#8217; uh?' ) );
    81121
    82122        $this->start_previewing_theme();
  • trunk/wp-includes/script-loader.php

    r21003 r21031  
    306306        'cancel'    => __( 'Cancel' ),
    307307        'close'     => __( 'Close' ),
     308        'cheatin'   => __( 'Cheatin&#8217; uh?' ),
    308309    ) );
    309310
  • trunk/wp-login.php

    r20887 r21031  
    4040 */
    4141function login_header($title = 'Log In', $message = '', $wp_error = '') {
    42     global $error, $interim_login, $current_site;
     42    global $error, $interim_login, $current_site, $customize_login;
    4343
    4444    // Don't index any of these forms
     
    6969    }
    7070
     71    if ( $customize_login )
     72        wp_enqueue_script( 'customize-base' );
     73
    7174    do_action( 'login_enqueue_scripts' );
    7275    do_action( 'login_head' );
     
    8285    $login_header_url   = apply_filters( 'login_headerurl',   $login_header_url   );
    8386    $login_header_title = apply_filters( 'login_headertitle', $login_header_title );
     87
     88    // Don't allow interim logins to navigate away from the page.
     89    if ( $interim_login )
     90        $login_header_url = '#';
    8491
    8592    ?>
     
    127134 */
    128135function login_footer($input_id = '') {
    129     ?>
     136    global $interim_login;
     137
     138    // Don't allow interim logins to navigate away from the page.
     139    if ( ! $interim_login ): ?>
    130140    <p id="backtoblog"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php esc_attr_e( 'Are you lost?' ); ?>"><?php printf( __( '&larr; Back to %s' ), get_bloginfo( 'title', 'display' ) ); ?></a></p>
     141    <?php endif; ?>
     142
    131143    </div>
    132144
     
    556568    $secure_cookie = '';
    557569    $interim_login = isset($_REQUEST['interim-login']);
     570    $customize_login = isset( $_REQUEST['customize-login'] );
    558571
    559572    // If the user wants ssl but the session is not ssl, force a secure cookie.
     
    592605        if ( $interim_login ) {
    593606            $message = '<p class="message">' . __('You have logged in successfully.') . '</p>';
    594             login_header( '', $message ); ?>
    595             <script type="text/javascript">setTimeout( function(){window.close()}, 8000);</script>
    596             <p class="alignright">
    597             <input type="button" class="button-primary" value="<?php esc_attr_e('Close'); ?>" onclick="window.close()" /></p>
    598             </div></body></html>
     607            login_header( '', $message );
     608
     609            if ( ! $customize_login ) : ?>
     610                <script type="text/javascript">setTimeout( function(){window.close()}, 8000);</script>
     611                <p class="alignright">
     612                <input type="button" class="button-primary" value="<?php esc_attr_e('Close'); ?>" onclick="window.close()" /></p>
     613<?php       endif;
     614
     615            ?></div><?php
     616
     617            do_action('login_footer');
     618
     619            if ( $customize_login ) : ?>
     620                <script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo wp_customize_url(); ?>', channel: 'login' }).send('login') }, 1000 );</script>
     621<?php       endif; ?>
     622            </body></html>
    599623<?php       exit;
    600624        }
     
    667691        <input type="hidden" name="redirect_to" value="<?php echo esc_attr($redirect_to); ?>" />
    668692<?php   } ?>
     693<?php   if ( $customize_login ) : ?>
     694        <input type="hidden" name="customize-login" value="1" />
     695<?php   endif; ?>
    669696        <input type="hidden" name="testcookie" value="1" />
    670697    </p>
Note: See TracChangeset for help on using the changeset viewer.