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
This commit is contained in:
ryan 2012-06-08 18:45:12 +00:00
parent c819e450a1
commit 69ad7a68ff
4 changed files with 28 additions and 8 deletions

View File

@ -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 );
?>
<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" />
<a class="back button" href="<?php echo esc_url( admin_url( 'themes.php' ) ); ?>">
<a class="back button" href="<?php echo esc_url( $return ? $return : admin_url( 'themes.php' ) ); ?>">
<?php _e( 'Cancel' ); ?>
</a>
</div>
@ -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(),

View File

@ -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() {

View File

@ -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',
),

View File

@ -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' );