Make WordPress Core

Changeset 30091


Ignore:
Timestamp:
10/29/2014 07:01:15 PM (12 years ago)
Author:
johnbillion
Message:

Introduce some actions and filters which aid plugins in revisioning post meta.

  • wp_save_post_revision_post_has_changed filter which can be used to determine if a post has been changed, and therefore if a revision should be created for a post.
  • wp_get_revision_ui_diff filter which can be used to filter the fields displayed in the post revision diff UI.
  • wp_creating_autosave action which is fired just before an autosave is created.

See #20564.
Props mattheu, adamsilverstein.

Location:
trunk/src
Files:
3 edited

Legend:

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

    r30034 r30091  
    15421542                }
    15431543
     1544                /**
     1545                 * Fires before an autosave is stored.
     1546                 *
     1547                 * @since 4.1.0
     1548                 *
     1549                 * @param array $new_autosave Post array - the autosave that is about to be saved.
     1550                 */
     1551                do_action( 'wp_creating_autosave', $new_autosave );
     1552
    15441553                return wp_update_post( $new_autosave );
    15451554        }
  • trunk/src/wp-admin/includes/revision.php

    r29206 r30091  
    9393                }
    9494        }
    95         return $return;
     95
     96        /**
     97         * Filter the fields displayed in the post revision diff UI.
     98         *
     99         * @since 4.1.0
     100         *
     101         * @param array   $return       Revision UI fields. Each item is an array of id, name and diff.
     102         * @param WP_Post $compare_from The revision post to compare from.
     103         * @param WP_Post $compare_to   The revision post to compare to.
     104         */
     105        return apply_filters( 'wp_get_revision_ui_diff', $return, $compare_from, $compare_to );
     106
    96107}
    97108
  • trunk/src/wp-includes/revision.php

    r28976 r30091  
    134134                                }
    135135                        }
     136
     137                        /**
     138                         * Filter whether a post has changed.
     139                         *
     140                         * By default a revision is saved only if one of the revisioned fields has changed.
     141                         * This filter allows for additional checks to determine if there were changes.
     142                         *
     143                         * @since 4.1.0
     144                         *
     145                         * @param bool    $post_has_changed Whether the post has changed.
     146                         * @param WP_Post $last_revision    The the last revision post object.
     147                         * @param WP_Post $post             The post object.
     148                         *
     149                         */
     150                        $post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post );
     151
    136152                        //don't save revision if post unchanged
    137                         if( ! $post_has_changed )
     153                        if( ! $post_has_changed ) {
    138154                                return;
     155                        }
    139156                }
    140157        }
Note: See TracChangeset for help on using the changeset viewer.