Changeset 47122 for trunk/src/wp-includes/revision.php
- Timestamp:
- 01/29/2020 12:43:23 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/revision.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/revision.php
r47060 r47122 30 30 31 31 if ( is_null( $fields ) ) { 32 // Allow these to be versioned 32 // Allow these to be versioned. 33 33 $fields = array( 34 34 'post_title' => __( 'Title' ), … … 56 56 $fields = apply_filters( '_wp_post_revision_fields', $fields, $post ); 57 57 58 // WP uses these internally either in versioning or elsewhere - they cannot be versioned 58 // WP uses these internally either in versioning or elsewhere - they cannot be versioned. 59 59 foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) { 60 60 unset( $fields[ $protect ] ); … … 91 91 $revision_data['post_status'] = 'inherit'; 92 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 93 $revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version. 94 94 $revision_data['post_date'] = isset( $post['post_modified'] ) ? $post['post_modified'] : ''; 95 95 $revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : ''; … … 131 131 } 132 132 133 // Compare the proposed update with the last stored revision verifying that 134 // they are different, unless a plugin tells us to always save regardless. 135 // If no previous revisions, save one 133 /* 134 * Compare the proposed update with the last stored revision verifying that 135 * they are different, unless a plugin tells us to always save regardless. 136 * If no previous revisions, save one. 137 */ 136 138 $revisions = wp_get_post_revisions( $post_id ); 137 139 if ( $revisions ) { 138 // grab the last revision, but not an autosave140 // Grab the last revision, but not an autosave. 139 141 foreach ( $revisions as $revision ) { 140 142 if ( false !== strpos( $revision->post_name, "{$revision->post_parent}-revision" ) ) { … … 181 183 $post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post ); 182 184 183 // don't save revision if post unchanged185 // Don't save revision if post unchanged. 184 186 if ( ! $post_has_changed ) { 185 187 return; … … 312 314 313 315 $post = _wp_post_revision_data( $post, $autosave ); 314 $post = wp_slash( $post ); // since data is from db316 $post = wp_slash( $post ); // Since data is from DB. 315 317 316 318 $revision_id = wp_insert_post( $post ); … … 398 400 $update['ID'] = $revision['post_parent']; 399 401 400 $update = wp_slash( $update ); // since data is from db402 $update = wp_slash( $update ); // Since data is from DB. 401 403 402 404 $post_id = wp_update_post( $update ); … … 405 407 } 406 408 407 // Update last edit user 409 // Update last edit user. 408 410 update_post_meta( $post_id, '_edit_last', get_current_user_id() ); 409 411 … … 624 626 $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ); 625 627 if ( $term ) { 626 $terms = array( $term ); // Can only have one post format 628 $terms = array( $term ); // Can only have one post format. 627 629 } 628 630 } … … 704 706 global $wpdb; 705 707 706 // Add post option exclusively 708 // Add post option exclusively. 707 709 $lock = "revision-upgrade-{$post->ID}"; 708 710 $now = time(); 709 711 $result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now ) ); 710 712 if ( ! $result ) { 711 // If we couldn't get a lock, see how old the previous lock is 713 // If we couldn't get a lock, see how old the previous lock is. 712 714 $locked = get_option( $lock ); 713 715 if ( ! $locked ) { 714 716 // Can't write to the lock, and can't read the lock. 715 // Something broken has happened 717 // Something broken has happened. 716 718 return false; 717 719 } 718 720 719 721 if ( $locked > $now - 3600 ) { 720 // Lock is not too old: some other process may be upgrading this post. Bail.722 // Lock is not too old: some other process may be upgrading this post. Bail. 721 723 return false; 722 724 } 723 725 724 // Lock is too old - update it (below) and continue 726 // Lock is too old - update it (below) and continue. 725 727 } 726 728 … … 737 739 $this_revision_version = _wp_get_post_revision_version( $this_revision ); 738 740 739 // Something terrible happened 741 // Something terrible happened. 740 742 if ( false === $this_revision_version ) { 741 743 continue; … … 749 751 } 750 752 751 // Always update the revision version 753 // Always update the revision version. 752 754 $update = array( 753 755 'post_name' => preg_replace( '/^(\d+-(?:autosave|revision))[\d-]*$/', '$1-v1', $this_revision->post_name ), 754 756 ); 755 757 756 // If this revision is the oldest revision of the post, i.e. no $prev_revision, 757 // the correct post_author is probably $post->post_author, but that's only a good guess. 758 // Update the revision version only and Leave the author as-is. 758 /* 759 * If this revision is the oldest revision of the post, i.e. no $prev_revision, 760 * the correct post_author is probably $post->post_author, but that's only a good guess. 761 * Update the revision version only and Leave the author as-is. 762 */ 759 763 if ( $prev_revision ) { 760 764 $prev_revision_version = _wp_get_post_revision_version( $prev_revision ); … … 766 770 } 767 771 768 // Upgrade this revision 772 // Upgrade this revision. 769 773 $result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) ); 770 774
Note: See TracChangeset
for help on using the changeset viewer.