diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index f514cf7632..a22aa76bba 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -2346,6 +2346,10 @@ api.HeaderTool.UploadsList, api.HeaderTool.DefaultsList ]); + + // Ensure custom-header-crop Ajax requests bootstrap the Customizer to activate the previewed theme. + wp.media.controller.Cropper.prototype.defaults.doCropArgs.wp_customize = 'on'; + wp.media.controller.Cropper.prototype.defaults.doCropArgs.theme = api.settings.theme.stylesheet; }, /** diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index f9c5555049..015ec23527 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -282,8 +282,10 @@ Cropper = wp.media.controller.State.extend({ toolbar: 'crop', content: 'crop', router: false, + canSkipCrop: false, - canSkipCrop: false + // Default doCrop Ajax arguments to allow the Customizer (for example) to inject state. + doCropArgs: {} }, activate: function() { @@ -367,11 +369,15 @@ Cropper = wp.media.controller.State.extend({ }, doCrop: function( attachment ) { - return wp.ajax.post( 'custom-header-crop', { - nonce: attachment.get('nonces').edit, - id: attachment.get('id'), - cropDetails: attachment.get('cropDetails') - } ); + return wp.ajax.post( 'custom-header-crop', _.extend( + {}, + this.defaults.doCropArgs, + { + nonce: attachment.get( 'nonces' ).edit, + id: attachment.get( 'id' ), + cropDetails: attachment.get( 'cropDetails' ) + } + ) ); } });