Make WordPress Core

Ticket #26979: 26979.3.diff

File 26979.3.diff, 4.5 KB (added by DrewAPicture, 12 years ago)

Final pass.

  • src/wp-includes/revision.php

     
    1616 * @since 2.6.0
    1717 * @access private
    1818 *
    19  * @uses apply_filters() Calls '_wp_post_revision_fields' on 'title', 'content' and 'excerpt' fields.
    20  *
    2119 * @param array $post Optional a post array to be processed for insertion as a post revision.
    2220 * @param bool $autosave optional Is the revision an autosave?
    2321 * @return array Post array ready to be inserted as a post revision or array of fields that can be versioned.
     
    3331                        'post_excerpt' => __( 'Excerpt' ),
    3432                );
    3533
    36                 // Runs only once
     34                /**
     35                 * Filter the list of fields saved in post revisions.
     36                 *
     37                 * Included by default: 'post_title', 'post_content' and 'post_excerpt'.
     38                 *
     39                 * Disallowed fields: 'ID', 'post_name', 'post_parent', 'post_date',
     40                 * 'post_date_gmt', 'post_status', 'post_type', 'comment_count',
     41                 * and 'post_author'.
     42                 *
     43                 * @since 2.6.0
     44                 *
     45                 * @param array $fields List of fields to revision. Contains 'post_title',
     46                 *                      'post_content', and 'post_excerpt' by default.
     47                 *
     48                 */
    3749                $fields = apply_filters( '_wp_post_revision_fields', $fields );
    3850
    3951                // WP uses these internally either in versioning or elsewhere - they cannot be versioned
     
    99111                        }
    100112                }
    101113
    102                 if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', true, $last_revision, $post ) ) {
     114                /**
     115                 * Filter whether the post has changed since the last revision.
     116                 *
     117                 * By default a revision is saved only if one of the revisioned fields has changed.
     118                 * This filter can override that so a revision is saved even if nothing has changed.
     119                 *
     120                 * @since 3.6.0
     121                 *
     122                 * @param bool $check_for_changes Whether to check for changes before saving a new revision.
     123                 *                                Default true.
     124                 * @param int  $last_revision     ID of the last revision.
     125                 * @param int  $post              Post ID.
     126                 *
     127                 */
     128                if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', $check_for_changes = true, $last_revision, $post ) ) {
    103129                        $post_has_changed = false;
    104130
    105131                        foreach ( array_keys( _wp_post_revision_fields() ) as $field ) {
     
    237263        if ( is_wp_error($revision_id) )
    238264                return $revision_id;
    239265
    240         if ( $revision_id )
     266        if ( $revision_id ) {
     267                /**
     268                 * Fires once a revision has been saved.
     269                 *
     270                 * @since 2.6.0
     271                 *
     272                 * @param int $revision_id Post revision ID.
     273                 */
    241274                do_action( '_wp_put_post_revision', $revision_id );
     275        }
    242276
    243277        return $revision_id;
    244278}
     
    283317 *
    284318 * @uses wp_get_post_revision()
    285319 * @uses wp_update_post()
    286  * @uses do_action() Calls 'wp_restore_post_revision' on post ID and revision ID if wp_update_post()
    287  *  is successful.
    288320 *
    289321 * @param int|object $revision_id Revision ID or revision object.
    290322 * @param array $fields Optional. What fields to restore from. Defaults to all.
     
    324356        // Update last edit user
    325357        update_post_meta( $post_id, '_edit_last', get_current_user_id() );
    326358
     359        /**
     360         * Fires after a post revision has been restored.
     361         *
     362         * @since 2.6.0
     363         *
     364         * @param int $post_id     Post ID.
     365         * @param int $revision_id Post revision ID.
     366         */
    327367        do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] );
    328368
    329369        return $post_id;
     
    350390        if ( is_wp_error( $delete ) )
    351391                return $delete;
    352392
    353         if ( $delete )
     393        if ( $delete ) {
     394                /**
     395                 * Fires once a post revision has been deleted.
     396                 *
     397                 * @since 2.6.0
     398                 *
     399                 * @param int          $revision_id Post revision ID.
     400                 * @param object|array $revision    Post revision object or array.
     401                 */
    354402                do_action( 'wp_delete_post_revision', $revision->ID, $revision );
     403        }
    355404
    356405        return $delete;
    357406}
     
    406455 * @since 3.6.0
    407456 *
    408457 * @uses post_type_supports()
    409  * @uses apply_filters() Calls 'wp_revisions_to_keep' hook on the number of revisions.
    410458 *
    411459 * @param object $post The post object.
    412460 * @return int The number of revisions to keep.
     
    422470        if ( ! post_type_supports( $post->post_type, 'revisions' ) )
    423471                $num = 0;
    424472
     473        /**
     474         * Filter the number of revisions to save for the given post.
     475         *
     476         * Overrides the value of WP_POST_REVISIONS.
     477         *
     478         * @since 3.6.0
     479         *
     480         * @param int     $num  Number of revisions to store.
     481         * @param WP_Post $post Post object.
     482         */
    425483        return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
    426484}
    427485