From 69ad7a68ff89e54454575fe44b13b87bb1d8ee47 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 8 Jun 2012 18:45:12 +0000 Subject: [PATCH] Customizer: Redirect back to referrer. If referrer is a front end page, load that page in the customizer preview. Props nacin, koopersmith. fixes #20877 git-svn-id: http://core.svn.wordpress.org/trunk@21028 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/customize.php | 13 +++++++++++-- wp-admin/js/customize-controls.dev.js | 18 ++++++++++++++---- wp-includes/admin-bar.php | 3 ++- wp-includes/js/customize-base.dev.js | 2 +- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/wp-admin/customize.php b/wp-admin/customize.php index e7885cf1d6..b631f9f515 100644 --- a/wp-admin/customize.php +++ b/wp-admin/customize.php @@ -11,6 +11,14 @@ require_once( './admin.php' ); if ( ! current_user_can( 'edit_theme_options' ) ) wp_die( __( 'Cheatin’ uh?' ) ); +wp_reset_vars( array( 'url', 'return' ) ); +$url = urldecode( $url ); +$url = wp_validate_redirect( $url, home_url( '/' ) ); +if ( $return ) + $return = wp_validate_redirect( urldecode( $return ) ); +if ( ! $return ) + $return = $url; + global $wp_scripts, $wp_customize; $registered = $wp_scripts->registered; @@ -64,7 +72,7 @@ do_action( 'customize_controls_print_scripts' ); submit_button( $save_text, 'primary', 'save', false ); ?> - + @@ -146,13 +154,14 @@ do_action( 'customize_controls_print_scripts' ); 'active' => $wp_customize->is_theme_active(), ), 'url' => array( - 'preview' => esc_url( home_url( '/' ) ), + 'preview' => esc_url( $url ? $url : home_url( '/' ) ), 'parent' => esc_url( admin_url() ), 'activated' => esc_url( admin_url( 'themes.php?activated=true' ) ), 'ajax' => esc_url( admin_url( 'admin-ajax.php', 'relative' ) ), 'allowed' => array_map( 'esc_url', $allowed_urls ), 'isCrossDomain' => $cross_domain, 'fallback' => $fallback_url, + 'home' => esc_url( home_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 449b564b2c..24d647011f 100644 --- a/wp-admin/js/customize-controls.dev.js +++ b/wp-admin/js/customize-controls.dev.js @@ -403,7 +403,8 @@ */ initialize: function( params, options ) { var self = this, - rscheme = /^https?/; + rscheme = /^https?/, + url; $.extend( this, options || {} ); @@ -444,6 +445,9 @@ this.container = api.ensure( params.container ); this.allowedUrls = params.allowedUrls; + url = params.url; + delete params.url; + api.Messenger.prototype.initialize.call( this, params ); // We're dynamically generating the iframe, so the origin is set @@ -488,7 +492,10 @@ return result ? result : null; }); - // Refresh the preview when the URL is changed. + // Set the url. + this.url( url ); + + // Refresh the preview when the URL is changed (but not yet). this.url.bind( this.refresh ); this.scroll = 0; @@ -635,8 +642,11 @@ } ) ); }); - // Load the preview frame. - previewer.refresh(); + // Check if preview url is valid and load the preview frame. + if ( previewer.url() ) + previewer.refresh(); + else + previewer.url( api.settings.url.home ); // Save and activated states (function() { diff --git a/wp-includes/admin-bar.php b/wp-includes/admin-bar.php index b196e3ce92..1b23dad80f 100644 --- a/wp-includes/admin-bar.php +++ b/wp-includes/admin-bar.php @@ -576,11 +576,12 @@ function wp_admin_bar_appearance_menu( $wp_admin_bar ) { if ( ! current_user_can( 'edit_theme_options' ) ) return; + $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'customize', 'title' => __('Customize'), - 'href' => wp_customize_url(), + 'href' => add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ), 'meta' => array( 'class' => 'hide-if-no-customize', ), diff --git a/wp-includes/js/customize-base.dev.js b/wp-includes/js/customize-base.dev.js index bbebc541aa..588efafc15 100644 --- a/wp-includes/js/customize-base.dev.js +++ b/wp-includes/js/customize-base.dev.js @@ -498,7 +498,7 @@ if ( typeof wp === 'undefined' ) $.extend( this, options || {} ); this.add( 'channel', params.channel ); - this.add( 'url', params.url ); + this.add( 'url', params.url || '' ); this.add( 'targetWindow', params.targetWindow || defaultTarget ); this.add( 'origin', this.url() ).link( this.url ).setter( function( to ) { return to.replace( /([^:]+:\/\/[^\/]+).*/, '$1' );