Inline documentation for hooks in wp-includes/revision.php.

Props adamsilverstein, DrewAPicture.
Fixes #26979.


git-svn-id: https://develop.svn.wordpress.org/trunk@27699 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Drew Jaynes (DrewAPicture) 2014-03-25 08:59:55 +00:00
parent 52a57b9f43
commit 16feaee19a
1 changed files with 66 additions and 9 deletions

View File

@ -16,8 +16,6 @@
* @since 2.6.0
* @access private
*
* @uses apply_filters() Calls '_wp_post_revision_fields' on 'title', 'content' and 'excerpt' fields.
*
* @param array $post Optional a post array to be processed for insertion as a post revision.
* @param bool $autosave optional Is the revision an autosave?
* @return array Post array ready to be inserted as a post revision or array of fields that can be versioned.
@ -33,7 +31,20 @@ function _wp_post_revision_fields( $post = null, $autosave = false ) {
'post_excerpt' => __( 'Excerpt' ),
);
// Runs only once
/**
* Filter the list of fields saved in post revisions.
*
* Included by default: 'post_title', 'post_content' and 'post_excerpt'.
*
* Disallowed fields: 'ID', 'post_name', 'post_parent', 'post_date',
* 'post_date_gmt', 'post_status', 'post_type', 'comment_count',
* and 'post_author'.
*
* @since 2.6.0
*
* @param array $fields List of fields to revision. Contains 'post_title',
* 'post_content', and 'post_excerpt' by default.
*/
$fields = apply_filters( '_wp_post_revision_fields', $fields );
// WP uses these internally either in versioning or elsewhere - they cannot be versioned
@ -99,7 +110,21 @@ function wp_save_post_revision( $post_id ) {
}
}
if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', true, $last_revision, $post ) ) {
/**
* Filter whether the post has changed since the last revision.
*
* By default a revision is saved only if one of the revisioned fields has changed.
* This filter can override that so a revision is saved even if nothing has changed.
*
* @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.
*
*/
if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', $check_for_changes = true, $last_revision, $post ) ) {
$post_has_changed = false;
foreach ( array_keys( _wp_post_revision_fields() ) as $field ) {
@ -237,8 +262,16 @@ function _wp_put_post_revision( $post = null, $autosave = false ) {
if ( is_wp_error($revision_id) )
return $revision_id;
if ( $revision_id )
if ( $revision_id ) {
/**
* Fires once a revision has been saved.
*
* @since 2.6.0
*
* @param int $revision_id Post revision ID.
*/
do_action( '_wp_put_post_revision', $revision_id );
}
return $revision_id;
}
@ -283,8 +316,6 @@ function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') {
*
* @uses wp_get_post_revision()
* @uses wp_update_post()
* @uses do_action() Calls 'wp_restore_post_revision' on post ID and revision ID if wp_update_post()
* is successful.
*
* @param int|object $revision_id Revision ID or revision object.
* @param array $fields Optional. What fields to restore from. Defaults to all.
@ -324,6 +355,14 @@ function wp_restore_post_revision( $revision_id, $fields = null ) {
// Update last edit user
update_post_meta( $post_id, '_edit_last', get_current_user_id() );
/**
* Fires after a post revision has been restored.
*
* @since 2.6.0
*
* @param int $post_id Post ID.
* @param int $revision_id Post revision ID.
*/
do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] );
return $post_id;
@ -350,8 +389,17 @@ function wp_delete_post_revision( $revision_id ) {
if ( is_wp_error( $delete ) )
return $delete;
if ( $delete )
if ( $delete ) {
/**
* Fires once a post revision has been deleted.
*
* @since 2.6.0
*
* @param int $revision_id Post revision ID.
* @param object|array $revision Post revision object or array.
*/
do_action( 'wp_delete_post_revision', $revision->ID, $revision );
}
return $delete;
}
@ -406,7 +454,6 @@ function wp_revisions_enabled( $post ) {
* @since 3.6.0
*
* @uses post_type_supports()
* @uses apply_filters() Calls 'wp_revisions_to_keep' hook on the number of revisions.
*
* @param object $post The post object.
* @return int The number of revisions to keep.
@ -422,6 +469,16 @@ function wp_revisions_to_keep( $post ) {
if ( ! post_type_supports( $post->post_type, 'revisions' ) )
$num = 0;
/**
* Filter the number of revisions to save for the given post.
*
* Overrides the value of WP_POST_REVISIONS.
*
* @since 3.6.0
*
* @param int $num Number of revisions to store.
* @param WP_Post $post Post object.
*/
return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
}