From 9115435213949dc6687c7a7581dffd91b5139f3f Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 8 Jun 2012 19:22:11 +0000 Subject: [PATCH] Customizer: Gravefully handle cookie expipration. Prompt for log in in the preview. Props ocean90, koopersmith, nacin. fixes #20876 git-svn-id: http://core.svn.wordpress.org/trunk@21031 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/css/customize-controls.dev.css | 21 ++++++ wp-admin/customize.php | 6 ++ wp-admin/js/customize-controls.dev.js | 78 +++++++++++++++++++++- wp-includes/class-wp-customize-manager.php | 58 +++++++++++++--- wp-includes/script-loader.php | 1 + wp-login.php | 41 ++++++++++-- 6 files changed, 187 insertions(+), 18 deletions(-) diff --git a/wp-admin/css/customize-controls.dev.css b/wp-admin/css/customize-controls.dev.css index ba8f71de59..908caa2d8f 100644 --- a/wp-admin/css/customize-controls.dev.css +++ b/wp-admin/css/customize-controls.dev.css @@ -514,3 +514,24 @@ body { -webkit-overflow-scrolling: touch; } +/** + * Handle cheaters. + */ +body.cheatin { + min-width: 0; + background: #f9f9f9; + padding: 50px; +} + +body.cheatin p { + max-width: 700px; + margin: 0 auto; + padding: 2em; + font-size: 14px; + + background: #fff; + border: 1px solid #dfdfdf; + + -webkit-border-radius: 3px; + border-radius: 3px; +} \ No newline at end of file diff --git a/wp-admin/customize.php b/wp-admin/customize.php index b631f9f515..d60c99330d 100644 --- a/wp-admin/customize.php +++ b/wp-admin/customize.php @@ -148,6 +148,11 @@ do_action( 'customize_controls_print_scripts' ); 'TB_iframe' => 'true' ), home_url( '/' ) ); + $login_url = add_query_arg( array( + 'interim-login' => 1, + 'customize-login' => 1 + ), wp_login_url() ); + $settings = array( 'theme' => array( 'stylesheet' => $wp_customize->get_stylesheet(), @@ -162,6 +167,7 @@ do_action( 'customize_controls_print_scripts' ); 'isCrossDomain' => $cross_domain, 'fallback' => $fallback_url, 'home' => esc_url( home_url( '/' ) ), + 'login' => $login_url, ), 'browser' => array( 'mobile' => wp_is_mobile(), diff --git a/wp-admin/js/customize-controls.dev.js b/wp-admin/js/customize-controls.dev.js index 4e54c1866c..a6af649b4f 100644 --- a/wp-admin/js/customize-controls.dev.js +++ b/wp-admin/js/customize-controls.dev.js @@ -334,6 +334,18 @@ return; } + // Check if the user is not logged in. + if ( '0' === response ) { + deferred.rejectWith( self, [ 'logged out' ] ); + return; + } + + // Check for cheaters. + if ( '-1' === response ) { + deferred.rejectWith( self, [ 'cheatin' ] ); + return; + } + // Check for a signature in the request. index = response.lastIndexOf( signature ); if ( -1 === index || index < response.lastIndexOf('') ) { @@ -548,7 +560,52 @@ this.loading.fail( function( reason, location ) { if ( 'redirect' === reason && location ) self.url( location ); + + if ( 'logged out' === reason ) { + if ( self.iframe ) { + self.iframe.destroy(); + delete self.iframe; + } + + self.login().done( self.refresh ); + } + + if ( 'cheatin' === reason ) + self.cheatin(); }); + }, + + login: function() { + var previewer = this, + deferred, messenger, iframe; + + if ( this._login ) + return this._login; + + deferred = $.Deferred(); + this._login = deferred.promise(); + + messenger = new api.Messenger({ + channel: 'login', + url: api.settings.url.login + }); + + iframe = $('