Ticket #20564: 20564.3.diff
File 20564.3.diff, 5.5 KB (added by , 12 years ago) |
---|
-
wp-includes/post.php
1734 1734 * @return bool False on failure, true if success. 1735 1735 */ 1736 1736 function update_post_meta($post_id, $meta_key, $meta_value, $prev_value = '') { 1737 // make sure meta is added to the post, not a revision 1738 if ( $the_post = wp_is_post_revision($post_id) ) 1739 $post_id = $the_post; 1737 if ( ! apply_filters( 'wp_revisions_keep_meta', true ) ) { 1738 // make sure meta is added to the post, not a revision 1739 if ( $the_post = wp_is_post_revision($post_id) ) 1740 $post_id = $the_post; 1741 } 1740 1742 1741 1743 return update_metadata('post', $post_id, $meta_key, $meta_value, $prev_value); 1742 1744 } … … 1768 1770 */ 1769 1771 function get_post_custom( $post_id = 0 ) { 1770 1772 $post_id = absint( $post_id ); 1771 if ( ! $post_id ) 1772 $post_id = get_the_ID(); 1773 if ( ! apply_filters( 'wp_revisions_keep_meta', true ) ) { 1774 if ( ! $post_id ) 1775 $post_id = get_the_ID(); 1776 } 1773 1777 1774 1778 return get_post_meta( $post_id ); 1775 1779 } -
wp-includes/revision.php
60 60 } 61 61 62 62 /** 63 * Saves post meta as part of a revision. 64 * 65 * Called immedately after revision restore, with wp_restore_post_revision hook 66 * 67 * @package WordPress 68 * @subpackage Post_Revisions 69 * @since 3.6.0 70 * 71 * 72 * @param int $post_id The ID of the post saved as a revision. 73 * @param int $revision_id The ID of the revision. 74 * @return false error, true if success. 75 */ 76 function wp_restore_post_revision_meta( $post_id, $revision_id ) { 77 if ( ! apply_filters( 'wp_revisions_keep_meta', true ) ) 78 return false; 79 80 //revision the post format 81 $format = get_post_meta( $revision_id, '_revisioned_post_format', true); 82 if ( '' !== $format ) { 83 set_post_format( $post_id, $format ); 84 error_log('restoring ' . $format ); 85 error_log('from ' . $revision_id); 86 87 } 88 89 $current_meta = get_post_meta( $revision_id ); 90 if ( is_array( $current_meta ) ) { 91 foreach ( $current_meta as $meta_key => $meta_value ) { 92 update_post_meta( $post_id, $meta_key, $meta_value[0] ); 93 } 94 } 95 return true; 96 97 } 98 99 /** 100 * Saves post meta as part of a revision. 101 * 102 * Called immedately after revision storage 103 * 104 * @package WordPress 105 * @subpackage Post_Revisions 106 * @since 3.6.0 107 * 108 * 109 * @param int $post_id The ID of the post saved as a revision. 110 * @param int $revision_id The ID of the revision. 111 * @return false error, true if success. 112 */ 113 function wp_save_post_revision_meta( $post_id, $revision_id ) { 114 // hook for 'wp_revisions_keep_meta', return false to disable revisioning for post met 115 if ( ! apply_filters( 'wp_revisions_keep_meta', true ) ) 116 return false; 117 118 if ( ! wp_first_revision_matches_current_version( $post_id ) ) 119 return false; 120 121 // list of post meta that should be excluded from revisioning 122 // filter 'revision_meta_do_not_copy' to allow exclusion of specific meta from revisioning 123 $exclude_meta_keys = apply_filters( 'revision_meta_do_not_copy', array( 124 '_encloseme', 125 '_pingme', 126 '_edit_last', 127 '_edit_lock', 128 '_revisioned_post_format', 129 ) ); 130 131 //revision the post format 132 if ( '' !== get_post_format( $post_id ) ) 133 update_post_meta( $revision_id, '_revisioned_post_format', get_post_format( $post_id ) ); 134 135 error_log('storing ' . get_post_format( $post_id ) ); 136 error_log('on ' . $revision_id); 137 138 $current_meta = get_post_meta( $post_id ); 139 140 if ( is_array( $current_meta ) ) { 141 foreach ( $current_meta as $meta_key => $meta_value ) { 142 if ( in_array( $meta_key, $exclude_meta_keys ) ) 143 continue; 144 145 update_post_meta( $revision_id, $meta_key, $meta_value[0]); 146 } 147 148 } 149 return true; 150 } 151 152 /** 63 153 * Saves an already existing post as a post revision. 64 154 * 65 155 * Typically used immediately prior to post updates. … … 200 290 } 201 291 202 292 /** 203 * Inserts post data into the posts table as a post revision. 293 * Inserts post data into the posts table as a post revision. Since 3.6 also stores post meta. 204 294 * 205 295 * @package WordPress 206 296 * @subpackage Post_Revisions 207 297 * @since 2.6.0 208 298 * 209 299 * @uses wp_insert_post() 300 * @uses wp_save_post_revision_meta() 210 301 * 211 302 * @param int|object|array $post Post ID, post object OR post array. 212 303 * @param bool $autosave Optional. Is the revision an autosave? … … 221 312 if ( !$post || empty($post['ID']) ) 222 313 return; 223 314 315 $post_id = $post['ID']; 316 224 317 if ( isset($post['post_type']) && 'revision' == $post['post_type'] ) 225 318 return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) ); 226 319 … … 228 321 $post = wp_slash($post); //since data is from db 229 322 230 323 $revision_id = wp_insert_post( $post ); 324 if ( wp_first_revision_matches_current_version( $post_id ) ) 325 wp_save_post_revision_meta($post_id, $revision_id ); 326 231 327 if ( is_wp_error($revision_id) ) 232 328 return $revision_id; 233 329 -
wp-admin/revision.php
21 21 if ( ! current_user_can( 'edit_post', $revision->post_parent ) ) 22 22 break; 23 23 24 25 24 if ( ! $post = get_post( $revision->post_parent ) ) 26 25 break; 27 26 … … 33 32 34 33 check_admin_referer( "restore-post_{$revision->ID}" ); 35 34 35 wp_restore_post_revision_meta( $post->ID, $revision->ID ); 36 36 wp_restore_post_revision( $revision->ID ); 37 37 $redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) ); 38 38 break;