Make WordPress Core

Ticket #24455: 24455.patch

File 24455.patch, 6.2 KB (added by azaozz, 12 years ago)
  • wp-includes/class-wp-editor.php

     
    397397
    398398                        $body_class = $editor_id;
    399399
    400                         if ( $post = get_post() ) {
     400                        if ( $post = get_post() )
    401401                                $body_class .= ' post-type-' . sanitize_html_class( $post->post_type ) . ' post-status-' . sanitize_html_class( $post->post_status );
    402                                 if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
    403                                         $post_format = get_post_format( $post );
    404                                         if ( $post_format && ! is_wp_error( $post_format ) )
    405                                                 $body_class .= ' post-format-' . sanitize_html_class( $post_format );
    406                                         else
    407                                                 $body_class .= ' post-format-standard';
    408                                 }
    409                         }
    410402
    411403                        if ( !empty($set['tinymce']['body_class']) ) {
    412404                                $body_class .= ' ' . $set['tinymce']['body_class'];
  • wp-includes/js/autosave.js

     
    304304(function($){
    305305// Returns the data for saving in both localStorage and autosaves to the server
    306306wp.autosave.getPostData = function() {
    307         var ed = typeof tinymce != 'undefined' ? tinymce.activeEditor : null, post_name, parent_id, post_format, cats = [],
     307        var ed = typeof tinymce != 'undefined' ? tinymce.activeEditor : null, post_name, parent_id, cats = [],
    308308                data = {
    309309                        action: 'autosave',
    310310                        autosave: true,
     
    363363        if ( $('#auto_draft').val() == '1' )
    364364                data['auto_draft'] = '1';
    365365
    366         post_format = $('#post_format').val() || '';
    367         data['post_format'] = post_format == 'standard' ? '' : post_format;
    368 
    369         $('.post-formats-fields').find('input[name^="_format_"], textarea[name^="_format_"]').each( function(i, field) {
    370                 data[ field.name ] = field.value || '';
    371         });
    372 
    373366        return data;
    374367}
    375368
  • wp-includes/revision.php

     
    5959}
    6060
    6161/**
    62  * Determines which post meta fields are revisioned.
    63  *
    64  * @since 3.6
    65  * @access private
    66  *
    67  * @return array An array of meta keys that should be revisioned.
    68  */
    69 function _wp_post_revision_meta_keys() {
    70         return array(
    71                 '_format_url',
    72                 '_format_link_url',
    73                 '_format_quote_source_url',
    74                 '_format_quote_source_name',
    75                 '_format_image',
    76                 '_format_gallery',
    77                 '_format_audio_embed',
    78                 '_format_video_embed',
    79         );
    80 }
    81 
    82 /**
    8362 * Saves an already existing post as a post revision.
    8463 *
    8564 * Typically used immediately after post updates.
     
    129108                                        break;
    130109                                }
    131110                        }
    132 
    133                         // Check whether revisioned meta fields have changed.
    134                         foreach ( _wp_post_revision_meta_keys() as $meta_key ) {
    135                                 if ( get_post_meta( $post->ID, $meta_key, true ) != get_post_meta( $last_revision->ID, $meta_key, true ) ) {
    136                                         $post_has_changed = true;
    137                                         break;
    138                                 }
    139                         }
    140 
    141                         // Check whether the post format has changed
    142                         if ( get_post_format( $post->ID ) != get_post_meta( $last_revision->ID, '_revision_post_format', true ) )
    143                                 $post_has_changed = true;
    144 
    145111                        //don't save revision if post unchanged
    146112                        if( ! $post_has_changed )
    147113                                return;
     
    274240        if ( $revision_id )
    275241                do_action( '_wp_put_post_revision', $revision_id );
    276242
    277         // Save revisioned meta fields.
    278         foreach ( _wp_post_revision_meta_keys() as $meta_key ) {
    279                 $meta_value = get_post_meta( $post_id, $meta_key, true );
    280                 if ( empty( $meta_value ) )
    281                         continue;
    282 
    283                 // Use the underlying add_metadata vs add_post_meta to make sure
    284                 // metadata is added to the revision post and not its parent.
    285                 add_metadata( 'post', $revision_id, $meta_key, wp_slash( $meta_value ) );
    286         }
    287 
    288         // Save the post format
    289         if ( $post_format = get_post_format( $post_id ) )
    290                 add_metadata( 'post', $revision_id, '_revision_post_format', $post_format );
    291 
    292243        return $revision_id;
    293244}
    294245
     
    359310
    360311        $update = wp_slash( $update ); //since data is from db
    361312
    362         // Restore revisioned meta fields.
    363         foreach ( _wp_post_revision_meta_keys() as $meta_key ) {
    364                 $meta_value = get_post_meta( $revision['ID'], $meta_key, true );
    365                 if ( empty( $meta_value ) )
    366                         $meta_value = '';
    367                 // Add slashes to data pulled from the db
    368                 update_post_meta( $update['ID'], $meta_key, wp_slash( $meta_value ) );
    369         }
    370 
    371         // Restore post format
    372         set_post_format( $update['ID'], get_post_meta( $revision['ID'], '_revision_post_format', true ) );
    373 
    374313        $post_id = wp_update_post( $update );
    375314        if ( ! $post_id || is_wp_error( $post_id ) )
    376315                return $post_id;
     
    505444        $post->post_title = $preview->post_title;
    506445        $post->post_excerpt = $preview->post_excerpt;
    507446
    508         add_filter( 'get_post_metadata', '_wp_preview_meta_filter', 10, 4 );
    509         add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 );
    510 
    511447        return $post;
    512448}
    513449
     
    530466}
    531467
    532468/**
    533  * Filters post meta retrieval to get values from the actual autosave post,
    534  * and not its parent. Filters revisioned meta keys only.
    535  *
    536  * @since 3.6.0
    537  * @access private
    538  */
    539 function _wp_preview_meta_filter( $value, $object_id, $meta_key, $single ) {
    540         $post = get_post();
    541 
    542         if ( $post->ID != $object_id || ! in_array( $meta_key, _wp_post_revision_meta_keys() ) || 'revision' == $post->post_type )
    543                 return $value;
    544 
    545         $preview = wp_get_post_autosave( $post->ID );
    546         if ( ! is_object( $preview ) )
    547                 return $value;
    548 
    549         return get_post_meta( $preview->ID, $meta_key, $single );
    550 }
    551 
    552 /**
    553  * Filters terms lookup to get the post format saved with the preview revision.
    554  *
    555  * @since 3.6.0
    556  * @access private
    557  */
    558 function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
    559         $post = get_post();
    560 
    561         if ( $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type )
    562                 return $terms;
    563 
    564         if ( ! $preview = wp_get_post_autosave( $post->ID ) )
    565                 return $terms;
    566 
    567         if ( $post_format = get_post_meta( $preview->ID, '_revision_post_format', true ) ) {
    568                 if ( $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $post_format ), 'post_format' ) )
    569                         $terms = array( $term ); // Can only have one post format
    570         }
    571 
    572         return $terms;
    573 }
    574 
    575 /**
    576469 * Gets the post revision version.
    577470 *
    578471 * @since 3.6.0