Restore post format previewing.

props azaozz. fixes #24483

git-svn-id: http://core.svn.wordpress.org/trunk@24414 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Mark Jaquith 2013-06-06 14:39:08 +00:00
parent a98047f084
commit 5626969d0b
3 changed files with 55 additions and 7 deletions

View File

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

View File

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

View File

@ -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.
*