Changeset 36659
- Timestamp:
- 02/24/2016 12:43:31 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/edit-form-advanced.php
r35883 r36659 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 ) ); -
trunk/src/wp-admin/includes/post.php
r36584 r36659 1663 1663 // Store one autosave per author. If there is already an autosave, overwrite it. 1664 1664 if ( $old_autosave = wp_get_post_autosave( $post_id, $post_author ) ) { 1665 $new_autosave = _wp_post_revision_ fields( $post_data, true );1665 $new_autosave = _wp_post_revision_data( $post_data, true ); 1666 1666 $new_autosave['ID'] = $old_autosave->ID; 1667 1667 $new_autosave['post_author'] = $post_author; … … 1670 1670 $post = get_post( $post_id ); 1671 1671 $autosave_is_different = false; 1672 foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields( ) ) ) as $field ) {1672 foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields( $post ) ) ) as $field ) { 1673 1673 if ( normalize_whitespace( $new_autosave[ $field ] ) != normalize_whitespace( $post->$field ) ) { 1674 1674 $autosave_is_different = true; -
trunk/src/wp-admin/includes/revision.php
r35387 r36659 56 56 $return = array(); 57 57 58 foreach ( _wp_post_revision_fields( ) as $field => $name ) {58 foreach ( _wp_post_revision_fields( $post ) as $field => $name ) { 59 59 /** 60 60 * Contextually filter a post revision field. -
trunk/src/wp-includes/revision.php
r35981 r36659 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 ready 13 * to be inserted into the posts table as a post revision. Otherwise, returns 14 * an array whose keys are the post fields to be saved for post revisions. 15 * 16 * @since 2.6.0 12 * @since 2.6.0 13 * @since 4.5.0 A `WP_Post` object can now be passed to the `$post` parameter. 14 * @since 4.5.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. 24 */ 25 function _wp_post_revision_fields( $post = null, $autosave = false ) { 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. 23 */ 24 function _wp_post_revision_fields( $post = array(), $deprecated = false ) { 26 25 static $fields = null; 26 27 if ( ! is_array( $post ) ) { 28 $post = get_post( $post, ARRAY_A ); 29 } 27 30 28 31 if ( is_null( $fields ) ) { … … 33 36 'post_excerpt' => __( 'Excerpt' ), 34 37 ); 35 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 ); 51 52 // WP uses these internally either in versioning or elsewhere - they cannot be versioned 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] ); 55 } 56 57 if ( !is_array($post) ) 58 return $fields; 59 60 $return = array(); 61 foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) 62 $return[$field] = $post[$field]; 63 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'] : ''; 70 71 return $return; 38 } 39 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.5.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 ); 57 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 ] ); 61 } 62 63 64 return $fields; 65 } 66 67 /** 68 * Returns a post array ready to be inserted into the posts table as a post revision. 69 * 70 * @since 4.5.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 } 82 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 … … 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; … … 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 … … 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(); -
trunk/tests/phpunit/tests/post/revisions.php
r35242 r36659 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 … … 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
Note: See TracChangeset
for help on using the changeset viewer.