Ticket #13382: 13382.3.diff
File 13382.3.diff, 10.3 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. 17 14 * @access private 18 15 * 19 16 * @staticvar array $fields 20 17 * 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. 18 * @param array|WP_Post $post Optional. A post array or a WP_Post object being processed 19 * for insertion as a post revision. Default empty array. 20 * @param bool $deprecated Not used. 21 * @return array Array of fields that can be versioned. 24 22 */ 25 function _wp_post_revision_fields( $post = null, $autosave= false ) {23 function _wp_post_revision_fields( $post = array(), $deprecated = false ) { 26 24 static $fields = null; 27 25 26 if ( ! is_array( $post ) ) { 27 $post = get_post( $post, ARRAY_A ); 28 } 29 28 30 if ( is_null( $fields ) ) { 29 31 // Allow these to be versioned 30 32 $fields = array( … … 32 34 'post_content' => __( 'Content' ), 33 35 'post_excerpt' => __( 'Excerpt' ), 34 36 ); 37 } 35 38 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 ); 39 /** 40 * Filter the list of fields saved in post revisions. 41 * 42 * Included by default: 'post_title', 'post_content' and 'post_excerpt'. 43 * 44 * Disallowed fields: 'ID', 'post_name', 'post_parent', 'post_date', 45 * 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 46 * and 'post_author'. 47 * 48 * @since 2.6.0 49 * @since 4.4.0 The `$post` parameter was added. 50 * 51 * @param array $fields List of fields to revision. Contains 'post_title', 52 * 'post_content', and 'post_excerpt' by default. 53 * @param array $post A post array being processed for insertion as a post revision. 54 */ 55 $fields = apply_filters( '_wp_post_revision_fields', $fields, $post ); 51 56 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] );57 // WP uses these internally either in versioning or elsewhere - they cannot be versioned 58 foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) { 59 unset( $fields[ $protect ] ); 55 60 } 56 61 57 if ( !is_array($post) )58 return $fields;59 62 60 $return = array(); 61 foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) 62 $return[$field] = $post[$field]; 63 return $fields; 64 } 63 65 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'] : ''; 66 /** 67 * Returns a post array ready to be inserted into the posts table as a post revision. 68 * 69 * @since 4.4.0 70 * @access private 71 * 72 * @param array|WP_Post $post Optional. A post array or a WP_Post object to be processed 73 * for insertion as a post revision. Default empty array. 74 * @param bool $autosave Optional. Is the revision an autosave? Default false. 75 * @return array Post array ready to be inserted as a post revision. 76 */ 77 function _wp_post_revision_data( $post = array(), $autosave = false ) { 78 if ( ! is_array( $post ) ) { 79 $post = get_post( $post, ARRAY_A ); 80 } 70 81 71 return $return; 82 $fields = _wp_post_revision_fields( $post ); 83 84 $revision_data = array(); 85 86 foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) { 87 $revision_data[ $field ] = $post[ $field ]; 88 } 89 90 $revision_data['post_parent'] = $post['ID']; 91 $revision_data['post_status'] = 'inherit'; 92 $revision_data['post_type'] = 'revision'; 93 $revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version 94 $revision_data['post_date'] = isset( $post['post_modified'] ) ? $post['post_modified'] : ''; 95 $revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : ''; 96 97 return $revision_data; 72 98 } 73 99 74 100 /** … … 127 153 if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', $check_for_changes = true, $last_revision, $post ) ) { 128 154 $post_has_changed = false; 129 155 130 foreach ( array_keys( _wp_post_revision_fields( ) ) as $field ) {156 foreach ( array_keys( _wp_post_revision_fields( $post ) ) as $field ) { 131 157 if ( normalize_whitespace( $post->$field ) != normalize_whitespace( $last_revision->$field ) ) { 132 158 $post_has_changed = true; 133 159 break; … … 267 293 if ( isset($post['post_type']) && 'revision' == $post['post_type'] ) 268 294 return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) ); 269 295 270 $post = _wp_post_revision_ fields( $post, $autosave );296 $post = _wp_post_revision_data( $post, $autosave ); 271 297 $post = wp_slash($post); //since data is from db 272 298 273 299 $revision_id = wp_insert_post( $post ); … … 333 359 return $revision; 334 360 335 361 if ( !is_array( $fields ) ) 336 $fields = array_keys( _wp_post_revision_fields( ) );362 $fields = array_keys( _wp_post_revision_fields( $revision ) ); 337 363 338 364 $update = array(); 339 365 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();