Make WordPress Core

Changeset 21071


Ignore:
Timestamp:
06/12/2012 10:51:55 PM (14 years ago)
Author:
ryan
Message:

Customize: If the preview is not logged in but the admin is, perform a front page request to setup any mapped domain cookies and then retry loading the preview.

Props nacin, koopersmith
fixes #20926

Location:
trunk/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r21003 r21071  
    3939$core_actions_get = array(
    4040        'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed-cache',
    41         'autocomplete-user', 'dashboard-widgets',
     41        'autocomplete-user', 'dashboard-widgets', 'logged-in',
    4242);
    4343
  • trunk/wp-admin/includes/ajax-actions.php

    r21003 r21071  
    211211        }
    212212        wp_die();
     213}
     214
     215function wp_ajax_logged_in() {
     216        wp_die( 1 );
    213217}
    214218
  • trunk/wp-admin/js/customize-controls.dev.js

    r21037 r21071  
    289289
    290290                initialize: function( params, options ) {
    291                         var loaded   = false,
    292                                 ready    = false,
    293                                 deferred = $.Deferred(),
     291                        var deferred = $.Deferred(),
    294292                                self     = this;
    295293
    … …  
    305303                        this.add( 'previewUrl', params.previewUrl );
    306304
    307                         this.bind( 'ready', function() {
     305                        this.query = $.extend( params.query || {}, { customize_messenger_channel: this.channel() });
     306
     307                        this.run( deferred );
     308                },
     309
     310                run: function( deferred ) {
     311                        var self   = this,
     312                                loaded = false,
     313                                ready  = false;
     314
     315                        if ( this._ready )
     316                                this.unbind( 'ready', this._ready );
     317
     318                        this._ready = function() {
    308319                                ready = true;
    309320
    310321                                if ( loaded )
    311322                                        deferred.resolveWith( self );
    312                         });
    313 
    314                         params.query = $.extend( params.query || {}, { customize_messenger_channel: this.channel() });
     323                        };
     324
     325                        this.bind( 'ready', this._ready );
    315326
    316327                        this.request = $.ajax( this.previewUrl(), {
    317328                                type: 'POST',
    318                                 data: params.query,
     329                                data: this.query,
    319330                                xhrFields: {
    320331                                        withCredentials: true
    … …  
    340351                                // Check if the user is not logged in.
    341352                                if ( '0' === response ) {
    342                                         deferred.rejectWith( self, [ 'logged out' ] );
     353                                        self.login( deferred );
    343354                                        return;
    344355                                }
    … …  
    357368                                }
    358369
    359                                 // Strip the signature from the request.
    360                                 response = response.slice( 0, index ) + response.slice( index + signature.length );
    361 
    362                                 // Create the iframe and inject the html content.
    363370                                // Strip the signature from the request.
    364371                                response = response.slice( 0, index ) + response.slice( index + signature.length );
    … …  
    386393                                self.targetWindow().document.write( response );
    387394                                self.targetWindow().document.close();
     395                        });
     396                },
     397
     398                login: function( deferred ) {
     399                        var self = this,
     400                                reject;
     401
     402                        reject = function() {
     403                                deferred.rejectWith( self, [ 'logged out' ] );
     404                        };
     405
     406                        if ( this.triedLogin )
     407                                return reject();
     408
     409                        // Check if we have an admin cookie.
     410                        $.get( api.settings.url.ajax, {
     411                                action: 'logged-in'
     412                        }).fail( reject ).done( function( response ) {
     413                                var iframe;
     414
     415                                if ( '1' !== response )
     416                                        reject();
     417
     418                                iframe = $('<iframe src="' + self.previewUrl() + '" />').hide();
     419                                iframe.appendTo( self.previewer.container );
     420                                iframe.load( function() {
     421                                        self.triedLogin = true;
     422
     423                                        iframe.remove();
     424                                        self.run( deferred );
     425                                });
    388426                        });
    389427                },
Note: See TracChangeset for help on using the changeset viewer.