@@ -38,7 +38,8 @@ var EditPostPreviewAdmin = (function( $ ) {
3838 wasMobile ,
3939 parentId ,
4040 menuOrder ,
41- request ;
41+ request ,
42+ postFormat ;
4243
4344 event . preventDefault ( ) ;
4445
@@ -75,9 +76,17 @@ var EditPostPreviewAdmin = (function( $ ) {
7576 ping_status : $ ( '#ping_status' ) . prop ( 'checked' ) ? 'open' : 'closed' ,
7677 post_author : parseInt ( $ ( '#post_author_override' ) . val ( ) , 10 )
7778 } ;
78- postSettingId = 'post[' + postType + '][' + postId + ']' ;
79+ postSettingId = 'post[' + postType + '][' + String ( postId ) + ']' ;
7980 settings [ postSettingId ] = postSettingValue ;
8081
82+ postFormat = $ ( '#post-formats-select input[name=post_format]:checked' ) . val ( ) ;
83+ if ( '0' === postFormat ) {
84+ postFormat = 'standard' ;
85+ }
86+ if ( postFormat ) {
87+ settings [ 'post_terms[' + postType + '][' + String ( postId ) + '][post_format]' ] = postFormat ;
88+ }
89+
8190 // Allow plugins to inject additional settings to preview.
8291 wp . customize . trigger ( 'settings-from-edit-post-screen' , settings ) ;
8392
@@ -86,15 +95,15 @@ var EditPostPreviewAdmin = (function( $ ) {
8695 sessionStorage . setItem ( 'previewedCustomizePostSettings[' + postId + ']' , JSON . stringify ( settings ) ) ;
8796 wp . customize . Loader . open ( component . data . customize_url ) ;
8897 wp . customize . Loader . settings . browser . mobile = wasMobile ;
89- component . bindChangesFromCustomizer ( postSettingId , editor ) ;
98+ component . bindChangesFromCustomizer ( postId , postType , editor ) ;
9099 } else {
91100 $btn . addClass ( 'disabled' ) ;
92101 component . previewButtonSpinner . addClass ( 'is-active is-active-preview' ) ;
93102 request = wp . ajax . post ( 'customize_posts_update_changeset' , {
94103 customize_posts_update_changeset_nonce : component . data . customize_posts_update_changeset_nonce ,
95104 previewed_post : component . data . previewed_post ,
96105 customize_url : component . data . customize_url ,
97- input_data : postSettingValue
106+ settings : JSON . stringify ( settings )
98107 } ) ;
99108
100109 request . fail ( function ( resp ) {
@@ -108,7 +117,7 @@ var EditPostPreviewAdmin = (function( $ ) {
108117 request . done ( function ( resp ) {
109118 wp . customize . Loader . open ( resp . customize_url ) ;
110119 wp . customize . Loader . settings . browser . mobile = wasMobile ;
111- component . bindChangesFromCustomizer ( postSettingId , editor ) ;
120+ component . bindChangesFromCustomizer ( postId , postType , editor ) ;
112121 } ) ;
113122
114123 request . always ( function ( ) {
@@ -121,13 +130,17 @@ var EditPostPreviewAdmin = (function( $ ) {
121130 /**
122131 * Sync changes from the Customizer to the post input fields.
123132 *
124- * @param {string } postSettingId post setting id.
125- * @param {object } editor Tinymce object.
133+ * @param {int } postId - Post ID.
134+ * @param {string } postType - Post type.
135+ * @param {object } editor - Tinymce object.
126136 * @return {void }
127137 */
128- component . bindChangesFromCustomizer = function ( postSettingId , editor ) {
138+ component . bindChangesFromCustomizer = function ( postId , postType , editor ) {
139+ var postSettingId , postFormatSettingId ;
140+ postSettingId = 'post[' + postType + '][' + String ( postId ) + ']' ;
141+ postFormatSettingId = 'post_terms[' + postType + '][' + String ( postId ) + '][post_format]' ;
129142 wp . customize . Loader . messenger . bind ( 'customize-post-settings-data' , function ( data ) {
130- var settingParentId ;
143+ var settingParentId , postFormatRadioSelector ;
131144 if ( data [ postSettingId ] ) {
132145 $ ( '#title' ) . val ( data [ postSettingId ] . post_title ) . trigger ( 'change' ) ;
133146 if ( editor ) {
@@ -147,6 +160,14 @@ var EditPostPreviewAdmin = (function( $ ) {
147160 $ ( '#new-post-slug' ) . val ( data [ postSettingId ] . post_name ) ;
148161 $ ( '#editable-post-name, #editable-post-name-full' ) . text ( data [ postSettingId ] . post_name ) ;
149162 }
163+ if ( data [ postFormatSettingId ] ) {
164+ if ( 'standard' === data [ postFormatSettingId ] ) {
165+ postFormatRadioSelector = '#post-format-0' ;
166+ } else {
167+ postFormatRadioSelector = '#post-format-' + data [ postFormatSettingId ] ;
168+ }
169+ $ ( postFormatRadioSelector ) . prop ( 'checked' , true ) . trigger ( 'change' ) ;
170+ }
150171
151172 // Let plugins handle updates.
152173 wp . customize . trigger ( 'settings-from-customizer' , data ) ;
0 commit comments