From 2429659e9b5a7cd8fd1cffc3788f1a4e2a829872 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 12 Jun 2012 22:51:55 +0000 Subject: [PATCH] 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 git-svn-id: http://core.svn.wordpress.org/trunk@21071 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-ajax.php | 2 +- wp-admin/includes/ajax-actions.php | 4 ++ wp-admin/js/customize-controls.dev.js | 62 +++++++++++++++++++++------ 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 099a66f64..db44df78c 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -38,7 +38,7 @@ do_action( 'admin_init' ); $core_actions_get = array( 'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed-cache', - 'autocomplete-user', 'dashboard-widgets', + 'autocomplete-user', 'dashboard-widgets', 'logged-in', ); $core_actions_post = array( diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 9666ce798..5ced90166 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -212,6 +212,10 @@ function wp_ajax_dashboard_widgets() { wp_die(); } +function wp_ajax_logged_in() { + wp_die( 1 ); +} + /* * Ajax helper. */ diff --git a/wp-admin/js/customize-controls.dev.js b/wp-admin/js/customize-controls.dev.js index 1318e26c7..cb4e6e20a 100644 --- a/wp-admin/js/customize-controls.dev.js +++ b/wp-admin/js/customize-controls.dev.js @@ -288,9 +288,7 @@ sensitivity: 2000, initialize: function( params, options ) { - var loaded = false, - ready = false, - deferred = $.Deferred(), + var deferred = $.Deferred(), self = this; // This is the promise object. @@ -304,18 +302,31 @@ this.add( 'previewUrl', params.previewUrl ); - this.bind( 'ready', function() { + this.query = $.extend( params.query || {}, { customize_messenger_channel: this.channel() }); + + this.run( deferred ); + }, + + run: function( deferred ) { + var self = this, + loaded = false, + ready = false; + + if ( this._ready ) + this.unbind( 'ready', this._ready ); + + this._ready = function() { ready = true; if ( loaded ) deferred.resolveWith( self ); - }); + }; - params.query = $.extend( params.query || {}, { customize_messenger_channel: this.channel() }); + this.bind( 'ready', this._ready ); this.request = $.ajax( this.previewUrl(), { type: 'POST', - data: params.query, + data: this.query, xhrFields: { withCredentials: true } @@ -339,7 +350,7 @@ // Check if the user is not logged in. if ( '0' === response ) { - deferred.rejectWith( self, [ 'logged out' ] ); + self.login( deferred ); return; } @@ -359,10 +370,6 @@ // Strip the signature from the request. response = response.slice( 0, index ) + response.slice( index + signature.length ); - // Create the iframe and inject the html content. - // Strip the signature from the request. - response = response.slice( 0, index ) + response.slice( index + signature.length ); - // Create the iframe and inject the html content. self.iframe = $('