Skip to content

Commit 53b24b5

Browse files
authored
Merge pull request #7 from tarosky/issue#5
Fix css preview when not yet published.
2 parents f718ce8 + 1390cba commit 53b24b5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

includes/post-meta-box.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,26 @@
2828
/**
2929
* Save css
3030
*/
31-
add_action( 'save_post', function( $post_id, $post ) {
31+
add_action( 'save_post', function( $post_id, $post, $update ) {
3232
if ( ! wp_verify_nonce( filter_input( INPUT_POST, '_tcsnonce' ), 'tcs_post_css' ) ) {
3333
return;
3434
}
35+
3536
if ( wp_is_post_revision( $post ) && wp_is_post_autosave( $post ) ) {
36-
$key = '_css_preview';
37+
// Post already published, when viewing update preview.
38+
$keys = [ '_css_preview' ];
3739
$post_id = $post->post_parent;
3840
} elseif ( tcs_post_type_supported( $post->post_type ) ) {
39-
$key = '_css';
41+
// Post not yet published
42+
$keys = [ '_css_preview', '_css' ];
43+
//}
4044
} else {
4145
// Do nothing.
4246
return;
4347
}
48+
4449
// Save CSS
45-
update_post_meta( $post_id, $key, filter_input( INPUT_POST, 'tcs-css' ) );
46-
}, 10, 2 );
50+
foreach ( $keys as $key ) {
51+
update_post_meta( $post_id, $key, filter_input( INPUT_POST, 'tcs-css' ) );
52+
}
53+
}, 10, 3 );

0 commit comments

Comments
 (0)