diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 1dd9b3b2ae..17771408c3 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -1352,15 +1352,16 @@ function post_preview() { $post = get_post($post_ID); if ( 'page' == $post->post_type ) { - if ( !current_user_can('edit_page', $post_ID) ) - wp_die(__('You are not allowed to edit this page.')); + if ( ! current_user_can('edit_page', $post_ID) ) + wp_die( __('You are not allowed to edit this page.') ); } else { - if ( !current_user_can('edit_post', $post_ID) ) - wp_die(__('You are not allowed to edit this post.')); + if ( ! current_user_can('edit_post', $post_ID) ) + wp_die( __('You are not allowed to edit this post.') ); } $user_id = get_current_user_id(); - if ( 'draft' == $post->post_status && $user_id == $post->post_author ) { + $locked = wp_check_post_lock( $post->ID ); + if ( ! $locked && 'draft' == $post->post_status && $user_id == $post->post_author ) { $id = edit_post(); } else { // Non drafts are not overwritten. The autosave is stored in a special post revision. $id = wp_create_post_autosave( $post->ID ); @@ -1371,11 +1372,20 @@ function post_preview() { if ( is_wp_error($id) ) wp_die( $id->get_error_message() ); - if ( $_POST['post_status'] == 'draft' && $user_id == $post->post_author ) { + if ( ! $locked && $_POST['post_status'] == 'draft' && $user_id == $post->post_author ) { $url = add_query_arg( 'preview', 'true', get_permalink($id) ); } else { $nonce = wp_create_nonce('post_preview_' . $id); - $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $id, 'preview_nonce' => $nonce ), get_permalink($id) ); + $args = array( + 'preview' => 'true', + 'preview_id' => $id, + 'preview_nonce' => $nonce, + ); + + if ( isset( $_POST['post_format'] ) ) + $args['post_format'] = empty( $_POST['post_format'] ) ? 'standard' : sanitize_key( $_POST['post_format'] ); + + $url = add_query_arg( $args, get_permalink($id) ); } return apply_filters( 'preview_post_link', $url ); diff --git a/wp-admin/js/post.js b/wp-admin/js/post.js index 160b8c73fa..dd3a427345 100644 --- a/wp-admin/js/post.js +++ b/wp-admin/js/post.js @@ -898,5 +898,20 @@ jQuery(document).ready( function($) { }); }); }); + + // When changing post formats, change the editor body class + $('#post-formats-select input.post-format').on( 'change.set-editor-class', function( event ) { + var editor, body, format = this.id; + + if ( format && $( this ).prop('checked') ) { + editor = tinymce.get( 'content' ); + + if ( editor ) { + body = editor.getBody(); + body.className = body.className.replace( /\bpost-format-[^ ]+/, '' ); + editor.dom.addClass( body, format == 'post-format-0' ? 'post-format-standard' : format ); + } + } + }); } }); diff --git a/wp-includes/revision.php b/wp-includes/revision.php index 277d097d5f..341ebb17fe 100644 --- a/wp-includes/revision.php +++ b/wp-includes/revision.php @@ -444,6 +444,8 @@ function _set_preview($post) { $post->post_title = $preview->post_title; $post->post_excerpt = $preview->post_excerpt; + add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); + return $post; } @@ -465,6 +467,27 @@ function _show_post_preview() { } } +/** + * Filters terms lookup to set the post format. + * + * @since 3.6.0 + * @access private + */ +function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) { + if ( ! $post = get_post() ) + return $terms; + + if ( empty( $_REQUEST['post_format'] ) || $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type ) + return $terms; + + if ( 'standard' == $_REQUEST['post_format'] ) + $terms = array(); + elseif ( $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ) ) + $terms = array( $term ); // Can only have one post format + + return $terms; +} + /** * Gets the post revision version. *