Ticket #13382: 13382.4.diff
File 13382.4.diff, 10.4 KB (added by , 9 years ago) |
---|
-
src/wp-admin/edit-form-advanced.php
197 197 198 198 // Detect if there exists an autosave newer than the post and if that autosave is different than the post 199 199 if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) { 200 foreach ( _wp_post_revision_fields( ) as $autosave_field => $_autosave_field ) {200 foreach ( _wp_post_revision_fields( $post ) as $autosave_field => $_autosave_field ) { 201 201 if ( normalize_whitespace( $autosave->$autosave_field ) != normalize_whitespace( $post->$autosave_field ) ) { 202 202 $notice = sprintf( __( 'There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>' ), get_edit_post_link( $autosave->ID ) ); 203 203 break; -
src/wp-admin/includes/post.php
1665 1665 1666 1666 // Store one autosave per author. If there is already an autosave, overwrite it. 1667 1667 if ( $old_autosave = wp_get_post_autosave( $post_id, $post_author ) ) { 1668 $new_autosave = _wp_post_revision_ fields( $post_data, true );1668 $new_autosave = _wp_post_revision_data( $post_data, true ); 1669 1669 $new_autosave['ID'] = $old_autosave->ID; 1670 1670 $new_autosave['post_author'] = $post_author; 1671 1671 … … 1672 1672 // If the new autosave has the same content as the post, delete the autosave. 1673 1673 $post = get_post( $post_id ); 1674 1674 $autosave_is_different = false; 1675 foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields( ) ) ) as $field ) {1675 foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields( $post ) ) ) as $field ) { 1676 1676 if ( normalize_whitespace( $new_autosave[ $field ] ) != normalize_whitespace( $post->$field ) ) { 1677 1677 $autosave_is_different = true; 1678 1678 break; -
src/wp-admin/includes/revision.php
54 54 55 55 $return = array(); 56 56 57 foreach ( _wp_post_revision_fields( ) as $field => $name ) {57 foreach ( _wp_post_revision_fields( $post ) as $field => $name ) { 58 58 /** 59 59 * Contextually filter a post revision field. 60 60 * -
src/wp-includes/revision.php
9 9 /** 10 10 * Determines which fields of posts are to be saved in revisions. 11 11 * 12 * Does two things. If passed a post *array*, it will return a post array ready13 * to be inserted into the posts table as a post revision. Otherwise, returns14 * an array whose keys are the post fields to be saved for post revisions.15 *16 12 * @since 2.6.0 13 * @since 4.4.0 A `WP_Post` object can now be passed to the `$post` parameter. 14 * @since 4.4.0 The optional `$autosave` parameter was deprecated and renamed to `$deprecated`. 17 15 * @access private 18 16 * 19 17 * @staticvar array $fields 20 18 * 21 * @param array|null $post Optional. A post array to be processed for insertion as a post revision. Default null. 22 * @param bool $autosave Optional. Is the revision an autosave? Default false. 23 * @return array Post array ready to be inserted as a post revision or array of fields that can be versioned. 19 * @param array|WP_Post $post Optional. A post array or a WP_Post object being processed 20 * for insertion as a post revision. Default empty array. 21 * @param bool $deprecated Not used. 22 * @return array Array of fields that can be versioned. 24 23 */ 25 function _wp_post_revision_fields( $post = null, $autosave= false ) {24 function _wp_post_revision_fields( $post = array(), $deprecated = false ) { 26 25 static $fields = null; 27 26 27 if ( ! is_array( $post ) ) { 28 $post = get_post( $post, ARRAY_A ); 29 } 30 28 31 if ( is_null( $fields ) ) { 29 32 // Allow these to be versioned 30 33 $fields = array( … … 32 35 'post_content' => __( 'Content' ), 33 36 'post_excerpt' => __( 'Excerpt' ), 34 37 ); 38 } 35 39 36 /** 37 * Filter the list of fields saved in post revisions. 38 * 39 * Included by default: 'post_title', 'post_content' and 'post_excerpt'. 40 * 41 * Disallowed fields: 'ID', 'post_name', 'post_parent', 'post_date', 42 * 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 43 * and 'post_author'. 44 * 45 * @since 2.6.0 46 * 47 * @param array $fields List of fields to revision. Contains 'post_title', 48 * 'post_content', and 'post_excerpt' by default. 49 */ 50 $fields = apply_filters( '_wp_post_revision_fields', $fields ); 40 /** 41 * Filter the list of fields saved in post revisions. 42 * 43 * Included by default: 'post_title', 'post_content' and 'post_excerpt'. 44 * 45 * Disallowed fields: 'ID', 'post_name', 'post_parent', 'post_date', 46 * 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 47 * and 'post_author'. 48 * 49 * @since 2.6.0 50 * @since 4.4.0 The `$post` parameter was added. 51 * 52 * @param array $fields List of fields to revision. Contains 'post_title', 53 * 'post_content', and 'post_excerpt' by default. 54 * @param array $post A post array being processed for insertion as a post revision. 55 */ 56 $fields = apply_filters( '_wp_post_revision_fields', $fields, $post ); 51 57 52 53 foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect )54 unset( $fields[$protect] );58 // WP uses these internally either in versioning or elsewhere - they cannot be versioned 59 foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) { 60 unset( $fields[ $protect ] ); 55 61 } 56 62 57 if ( !is_array($post) )58 return $fields;59 63 60 $return = array(); 61 foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) 62 $return[$field] = $post[$field]; 64 return $fields; 65 } 63 66 64 $return['post_parent'] = $post['ID']; 65 $return['post_status'] = 'inherit'; 66 $return['post_type'] = 'revision'; 67 $return['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version 68 $return['post_date'] = isset($post['post_modified']) ? $post['post_modified'] : ''; 69 $return['post_date_gmt'] = isset($post['post_modified_gmt']) ? $post['post_modified_gmt'] : ''; 67 /** 68 * Returns a post array ready to be inserted into the posts table as a post revision. 69 * 70 * @since 4.4.0 71 * @access private 72 * 73 * @param array|WP_Post $post Optional. A post array or a WP_Post object to be processed 74 * for insertion as a post revision. Default empty array. 75 * @param bool $autosave Optional. Is the revision an autosave? Default false. 76 * @return array Post array ready to be inserted as a post revision. 77 */ 78 function _wp_post_revision_data( $post = array(), $autosave = false ) { 79 if ( ! is_array( $post ) ) { 80 $post = get_post( $post, ARRAY_A ); 81 } 70 82 71 return $return; 83 $fields = _wp_post_revision_fields( $post ); 84 85 $revision_data = array(); 86 87 foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) { 88 $revision_data[ $field ] = $post[ $field ]; 89 } 90 91 $revision_data['post_parent'] = $post['ID']; 92 $revision_data['post_status'] = 'inherit'; 93 $revision_data['post_type'] = 'revision'; 94 $revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version 95 $revision_data['post_date'] = isset( $post['post_modified'] ) ? $post['post_modified'] : ''; 96 $revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : ''; 97 98 return $revision_data; 72 99 } 73 100 74 101 /** … … 127 154 if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', $check_for_changes = true, $last_revision, $post ) ) { 128 155 $post_has_changed = false; 129 156 130 foreach ( array_keys( _wp_post_revision_fields( ) ) as $field ) {157 foreach ( array_keys( _wp_post_revision_fields( $post ) ) as $field ) { 131 158 if ( normalize_whitespace( $post->$field ) != normalize_whitespace( $last_revision->$field ) ) { 132 159 $post_has_changed = true; 133 160 break; … … 267 294 if ( isset($post['post_type']) && 'revision' == $post['post_type'] ) 268 295 return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) ); 269 296 270 $post = _wp_post_revision_ fields( $post, $autosave );297 $post = _wp_post_revision_data( $post, $autosave ); 271 298 $post = wp_slash($post); //since data is from db 272 299 273 300 $revision_id = wp_insert_post( $post ); … … 333 360 return $revision; 334 361 335 362 if ( !is_array( $fields ) ) 336 $fields = array_keys( _wp_post_revision_fields( ) );363 $fields = array_keys( _wp_post_revision_fields( $revision ) ); 337 364 338 365 $update = array(); 339 366 foreach ( array_intersect( array_keys( $revision ), $fields ) as $field ) { -
tests/phpunit/tests/post/revisions.php
340 340 $post = self::factory()->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) ); 341 341 342 342 $post = (array) $post; 343 $post_revision_fields = _wp_post_revision_ fields( $post );343 $post_revision_fields = _wp_post_revision_data( $post ); 344 344 $post_revision_fields = wp_slash( $post_revision_fields ); 345 345 346 346 $revision_ids = array(); … … 368 368 $post = self::factory()->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) ); 369 369 370 370 $post = (array) $post; 371 $post_revision_fields = _wp_post_revision_ fields( $post );371 $post_revision_fields = _wp_post_revision_data( $post ); 372 372 $post_revision_fields = wp_slash( $post_revision_fields ); 373 373 374 374 $revision_ids = array();