]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/revision.php
WordPress 4.2.4-scripts
[autoinstalls/wordpress.git] / wp-includes / revision.php
index 48523032e7798022e8998c479e433831e04ee548..310461211a07480d4e4c962d3330236ccdf91aab 100644 (file)
@@ -70,17 +70,15 @@ function _wp_post_revision_fields( $post = null, $autosave = false ) {
 }
 
 /**
- * Saves an already existing post as a post revision.
+ * Creates a revision for the current version of a post.
  *
- * Typically used immediately after post updates.
- * Adds a copy of the current post as a revision, so latest revision always matches current post
+ * Typically used immediately after a post update, as every update is a revision,
+ * and the most recent revision always matches the current post.
  *
  * @since 2.6.0
  *
- * @uses _wp_put_post_revision()
- *
- * @param int $post_id The ID of the post to save as a revision.
- * @return mixed Null or 0 if error, new revision ID, if success.
+ * @param  int $post_id The ID of the post to save as a revision.
+ * @return null|int Null or 0 if error, new revision ID, if success.
  */
 function wp_save_post_revision( $post_id ) {
        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
@@ -118,10 +116,10 @@ function wp_save_post_revision( $post_id ) {
                 *
                 * @since 3.6.0
                 *
-                * @param bool $check_for_changes Whether to check for changes before saving a new revision.
-                *                                Default true.
-                * @param int  $last_revision     ID of the last revision.
-                * @param int  $post              Post ID.
+                * @param bool    $check_for_changes Whether to check for changes before saving a new revision.
+                *                                   Default true.
+                * @param WP_Post $last_revision     The the last revision post object.
+                * @param WP_Post $post              The post object.
                 *
                 */
                if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', $check_for_changes = true, $last_revision, $post ) ) {
@@ -133,20 +131,38 @@ function wp_save_post_revision( $post_id ) {
                                        break;
                                }
                        }
+
+                       /**
+                        * Filter whether a post has changed.
+                        *
+                        * By default a revision is saved only if one of the revisioned fields has changed.
+                        * This filter allows for additional checks to determine if there were changes.
+                        *
+                        * @since 4.1.0
+                        *
+                        * @param bool    $post_has_changed Whether the post has changed.
+                        * @param WP_Post $last_revision    The last revision post object.
+                        * @param WP_Post $post             The post object.
+                        *
+                        */
+                       $post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post );
+
                        //don't save revision if post unchanged
-                       if( ! $post_has_changed )
+                       if( ! $post_has_changed ) {
                                return;
+                       }
                }
        }
 
        $return = _wp_put_post_revision( $post );
 
+       // If a limit for the number of revisions to keep has been set,
+       // delete the oldest ones.
        $revisions_to_keep = wp_revisions_to_keep( $post );
 
        if ( $revisions_to_keep < 0 )
                return $return;
 
-       // all revisions and autosaves
        $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
 
        $delete = count($revisions) - $revisions_to_keep;
@@ -175,8 +191,6 @@ function wp_save_post_revision( $post_id ) {
  *
  * @since 2.6.0
  *
- * @uses wp_get_post_revisions()
- *
  * @param int $post_id The post ID.
  * @param int $user_id optional The post author ID.
  * @return object|bool The autosaved data or false on failure or when no autosave exists.
@@ -190,7 +204,6 @@ function wp_get_post_autosave( $post_id, $user_id = 0 ) {
                                continue;
 
                        return $revision;
-                       break;
                }
        }
 
@@ -236,8 +249,6 @@ function wp_is_post_autosave( $post ) {
  * @since 2.6.0
  * @access private
  *
- * @uses wp_insert_post()
- *
  * @param int|object|array $post Post ID, post object OR post array.
  * @param bool $autosave Optional. Is the revision an autosave?
  * @return mixed WP_Error or 0 if error, new revision ID if success.
@@ -254,7 +265,6 @@ function _wp_put_post_revision( $post = null, $autosave = false ) {
        if ( isset($post['post_type']) && 'revision' == $post['post_type'] )
                return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) );
 
-       $post_id = $post['ID'];
        $post = _wp_post_revision_fields( $post, $autosave );
        $post = wp_slash($post); //since data is from db
 
@@ -281,8 +291,6 @@ function _wp_put_post_revision( $post = null, $autosave = false ) {
  *
  * @since 2.6.0
  *
- * @uses get_post()
- *
  * @param int|object $post The post ID or object.
  * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N.
  * @param string $filter Optional sanitation filter. @see sanitize_post().
@@ -314,9 +322,6 @@ function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') {
  *
  * @since 2.6.0
  *
- * @uses wp_get_post_revision()
- * @uses wp_update_post()
- *
  * @param int|object $revision_id Revision ID or revision object.
  * @param array $fields Optional. What fields to restore from. Defaults to all.
  * @return mixed Null if error, false if no fields to restore, (int) post ID if success.
@@ -375,9 +380,6 @@ function wp_restore_post_revision( $revision_id, $fields = null ) {
  *
  * @since 2.6.0
  *
- * @uses wp_get_post_revision()
- * @uses wp_delete_post()
- *
  * @param int|object $revision_id Revision ID or revision object.
  * @return mixed Null or WP_Error if error, deleted post if success.
  */
@@ -409,9 +411,7 @@ function wp_delete_post_revision( $revision_id ) {
  *
  * @since 2.6.0
  *
- * @uses get_children()
- *
- * @param int|object $post_id Post ID or post object
+ * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
  * @return array An array of revisions, or an empty array if none.
  */
 function wp_get_post_revisions( $post_id = 0, $args = null ) {
@@ -419,7 +419,7 @@ function wp_get_post_revisions( $post_id = 0, $args = null ) {
        if ( ! $post || empty( $post->ID ) )
                return array();
 
-       $defaults = array( 'order' => 'DESC', 'orderby' => 'date', 'check_enabled' => true );
+       $defaults = array( 'order' => 'DESC', 'orderby' => 'date ID', 'check_enabled' => true );
        $args = wp_parse_args( $args, $defaults );
 
        if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) )
@@ -438,9 +438,7 @@ function wp_get_post_revisions( $post_id = 0, $args = null ) {
  *
  * @since 3.6.0
  *
- * @uses wp_revisions_to_keep()
- *
- * @param object $post The post object.
+ * @param WP_Post $post The post object.
  * @return bool True if number of revisions to keep isn't zero, false otherwise.
  */
 function wp_revisions_enabled( $post ) {
@@ -449,13 +447,15 @@ function wp_revisions_enabled( $post ) {
 
 /**
  * Determine how many revisions to retain for a given post.
- * By default, an infinite number of revisions are stored if a post type supports revisions.
  *
- * @since 3.6.0
+ * By default, an infinite number of revisions are kept.
  *
- * @uses post_type_supports()
+ * The constant WP_POST_REVISIONS can be set in wp-config to specify the limit
+ * of revisions to keep.
  *
- * @param object $post The post object.
+ * @since 3.6.0
+ *
+ * @param WP_Post $post The post object.
  * @return int The number of revisions to keep.
  */
 function wp_revisions_to_keep( $post ) {
@@ -572,9 +572,7 @@ function _wp_get_post_revision_version( $revision ) {
  * @since 3.6.0
  * @access private
  *
- * @uses wp_get_post_revisions()
- *
- * @param object $post Post object
+ * @param WP_Post $post Post object
  * @param array $revisions Current revisions of the post
  * @return bool true if the revisions were upgraded, false if problems
  */