Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/revision.php

    r47060 r47122  
    3030
    3131    if ( is_null( $fields ) ) {
    32         // Allow these to be versioned
     32        // Allow these to be versioned.
    3333        $fields = array(
    3434            'post_title'   => __( 'Title' ),
     
    5656    $fields = apply_filters( '_wp_post_revision_fields', $fields, $post );
    5757
    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.
    5959    foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) {
    6060        unset( $fields[ $protect ] );
     
    9191    $revision_data['post_status']   = 'inherit';
    9292    $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.
    9494    $revision_data['post_date']     = isset( $post['post_modified'] ) ? $post['post_modified'] : '';
    9595    $revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : '';
     
    131131    }
    132132
    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     */
    136138    $revisions = wp_get_post_revisions( $post_id );
    137139    if ( $revisions ) {
    138         // grab the last revision, but not an autosave
     140        // Grab the last revision, but not an autosave.
    139141        foreach ( $revisions as $revision ) {
    140142            if ( false !== strpos( $revision->post_name, "{$revision->post_parent}-revision" ) ) {
     
    181183            $post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post );
    182184
    183             //don't save revision if post unchanged
     185            // Don't save revision if post unchanged.
    184186            if ( ! $post_has_changed ) {
    185187                return;
     
    312314
    313315    $post = _wp_post_revision_data( $post, $autosave );
    314     $post = wp_slash( $post ); //since data is from db
     316    $post = wp_slash( $post ); // Since data is from DB.
    315317
    316318    $revision_id = wp_insert_post( $post );
     
    398400    $update['ID'] = $revision['post_parent'];
    399401
    400     $update = wp_slash( $update ); //since data is from db
     402    $update = wp_slash( $update ); // Since data is from DB.
    401403
    402404    $post_id = wp_update_post( $update );
     
    405407    }
    406408
    407     // Update last edit user
     409    // Update last edit user.
    408410    update_post_meta( $post_id, '_edit_last', get_current_user_id() );
    409411
     
    624626        $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' );
    625627        if ( $term ) {
    626             $terms = array( $term ); // Can only have one post format
     628            $terms = array( $term ); // Can only have one post format.
    627629        }
    628630    }
     
    704706    global $wpdb;
    705707
    706     // Add post option exclusively
     708    // Add post option exclusively.
    707709    $lock   = "revision-upgrade-{$post->ID}";
    708710    $now    = time();
    709711    $result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now ) );
    710712    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.
    712714        $locked = get_option( $lock );
    713715        if ( ! $locked ) {
    714716            // Can't write to the lock, and can't read the lock.
    715             // Something broken has happened
     717            // Something broken has happened.
    716718            return false;
    717719        }
    718720
    719721        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.
    721723            return false;
    722724        }
    723725
    724         // Lock is too old - update it (below) and continue
     726        // Lock is too old - update it (below) and continue.
    725727    }
    726728
     
    737739        $this_revision_version = _wp_get_post_revision_version( $this_revision );
    738740
    739         // Something terrible happened
     741        // Something terrible happened.
    740742        if ( false === $this_revision_version ) {
    741743            continue;
     
    749751        }
    750752
    751         // Always update the revision version
     753        // Always update the revision version.
    752754        $update = array(
    753755            'post_name' => preg_replace( '/^(\d+-(?:autosave|revision))[\d-]*$/', '$1-v1', $this_revision->post_name ),
    754756        );
    755757
    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         */
    759763        if ( $prev_revision ) {
    760764            $prev_revision_version = _wp_get_post_revision_version( $prev_revision );
     
    766770        }
    767771
    768         // Upgrade this revision
     772        // Upgrade this revision.
    769773        $result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) );
    770774
Note: See TracChangeset for help on using the changeset viewer.