WordPress.org

Make WordPress Core

Changeset 24414


Ignore:
Timestamp:
06/06/2013 02:39:08 PM (5 years ago)
Author:
markjaquith
Message:

Restore post format previewing.

props azaozz. fixes #24483

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/post.php

    r24408 r24414  
    13531353
    13541354    if ( 'page' == $post->post_type ) {
    1355         if ( !current_user_can('edit_page', $post_ID) )
    1356             wp_die(__('You are not allowed to edit this page.'));
     1355        if ( ! current_user_can('edit_page', $post_ID) )
     1356            wp_die( __('You are not allowed to edit this page.') );
    13571357    } else {
    1358         if ( !current_user_can('edit_post', $post_ID) )
    1359             wp_die(__('You are not allowed to edit this post.'));
     1358        if ( ! current_user_can('edit_post', $post_ID) )
     1359            wp_die( __('You are not allowed to edit this post.') );
    13601360    }
    13611361
    13621362    $user_id = get_current_user_id();
    1363     if ( 'draft' == $post->post_status && $user_id == $post->post_author ) {
     1363    $locked = wp_check_post_lock( $post->ID );
     1364    if ( ! $locked && 'draft' == $post->post_status && $user_id == $post->post_author ) {
    13641365        $id = edit_post();
    13651366    } else { // Non drafts are not overwritten. The autosave is stored in a special post revision.
     
    13721373        wp_die( $id->get_error_message() );
    13731374
    1374     if ( $_POST['post_status'] == 'draft' && $user_id == $post->post_author ) {
     1375    if ( ! $locked && $_POST['post_status'] == 'draft' && $user_id == $post->post_author ) {
    13751376        $url = add_query_arg( 'preview', 'true', get_permalink($id) );
    13761377    } else {
    13771378        $nonce = wp_create_nonce('post_preview_' . $id);
    1378         $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $id, 'preview_nonce' => $nonce ), get_permalink($id) );
     1379        $args = array(
     1380            'preview' => 'true',
     1381            'preview_id' => $id,
     1382            'preview_nonce' => $nonce,
     1383        );
     1384
     1385        if ( isset( $_POST['post_format'] ) )
     1386            $args['post_format'] = empty( $_POST['post_format'] ) ? 'standard' : sanitize_key( $_POST['post_format'] );
     1387
     1388        $url = add_query_arg( $args, get_permalink($id) );
    13791389    }
    13801390
  • trunk/wp-admin/js/post.js

    r24304 r24414  
    899899            });
    900900        });
     901
     902        // When changing post formats, change the editor body class
     903        $('#post-formats-select input.post-format').on( 'change.set-editor-class', function( event ) {
     904            var editor, body, format = this.id;
     905
     906            if ( format && $( this ).prop('checked') ) {
     907                editor = tinymce.get( 'content' );
     908
     909                if ( editor ) {
     910                    body = editor.getBody();
     911                    body.className = body.className.replace( /\bpost-format-[^ ]+/, '' );
     912                    editor.dom.addClass( body, format == 'post-format-0' ? 'post-format-standard' : format );
     913                }
     914            }
     915        });
    901916    }
    902917});
  • trunk/wp-includes/revision.php

    r24397 r24414  
    445445    $post->post_excerpt = $preview->post_excerpt;
    446446
     447    add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 );
     448
    447449    return $post;
    448450}
     
    464466        add_filter('the_preview', '_set_preview');
    465467    }
     468}
     469
     470/**
     471 * Filters terms lookup to set the post format.
     472 *
     473 * @since 3.6.0
     474 * @access private
     475 */
     476function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
     477    if ( ! $post = get_post() )
     478        return $terms;
     479
     480    if ( empty( $_REQUEST['post_format'] ) || $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type )
     481        return $terms;
     482
     483    if ( 'standard' == $_REQUEST['post_format'] )
     484        $terms = array();
     485    elseif ( $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ) )
     486        $terms = array( $term ); // Can only have one post format
     487
     488    return $terms;
    466489}
    467490
Note: See TracChangeset for help on using the changeset viewer.