Take revision control out of the realm of a pure constant. Make it filterable.
* New filter: wp_revisions_to_keep props ethitter, SergeyBiryukov. fixes #22289. git-svn-id: https://develop.svn.wordpress.org/trunk@23818 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
17d4a3302b
commit
404aa52ea2
|
@ -48,7 +48,7 @@ default :
|
|||
break;
|
||||
|
||||
// Revisions disabled and we're not looking at an autosave
|
||||
if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
|
||||
if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
|
||||
$redirect = 'edit.php?post_type=' . $post->post_type;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -3535,7 +3535,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) );
|
||||
|
||||
// Check if revisions are enabled.
|
||||
if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) )
|
||||
if ( ! wp_revisions_enabled( $post ) )
|
||||
return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
|
||||
|
||||
$revisions = wp_get_post_revisions( $post_id );
|
||||
|
@ -3602,7 +3602,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) );
|
||||
|
||||
// Check if revisions are disabled.
|
||||
if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) )
|
||||
if ( ! wp_revisions_enabled( $post ) )
|
||||
return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
|
||||
|
||||
$post = wp_restore_post_revision( $revision_id );
|
||||
|
|
|
@ -78,11 +78,10 @@ function wp_save_post_revision( $post_id, $new_data = null ) {
|
|||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
||||
return;
|
||||
|
||||
// WP_POST_REVISIONS = 0, false
|
||||
if ( ! WP_POST_REVISIONS )
|
||||
if ( ! $post = get_post( $post_id, ARRAY_A ) )
|
||||
return;
|
||||
|
||||
if ( !$post = get_post( $post_id, ARRAY_A ) )
|
||||
if ( ! wp_revisions_enabled( (object) $post ) )
|
||||
return;
|
||||
|
||||
if ( 'auto-draft' == $post['post_status'] )
|
||||
|
@ -107,15 +106,15 @@ function wp_save_post_revision( $post_id, $new_data = null ) {
|
|||
|
||||
$return = _wp_put_post_revision( $post );
|
||||
|
||||
// WP_POST_REVISIONS = true (default), -1
|
||||
if ( !is_numeric( WP_POST_REVISIONS ) || WP_POST_REVISIONS < 0 )
|
||||
$revisions_to_keep = wp_revisions_to_keep( (object) $post );
|
||||
|
||||
if ( $revisions_to_keep < 0 )
|
||||
return $return;
|
||||
|
||||
// all revisions and (possibly) one autosave
|
||||
$revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
|
||||
|
||||
// WP_POST_REVISIONS = (int) (# of autosaves to save)
|
||||
$delete = count($revisions) - WP_POST_REVISIONS;
|
||||
$delete = count($revisions) - $revisions_to_keep;
|
||||
|
||||
if ( $delete < 1 )
|
||||
return $return;
|
||||
|
@ -368,7 +367,8 @@ function wp_delete_post_revision( $revision_id ) {
|
|||
* @return array empty if no revisions
|
||||
*/
|
||||
function wp_get_post_revisions( $post_id = 0, $args = null ) {
|
||||
if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) )
|
||||
$post = get_post( $post_id );
|
||||
if ( ! $post || empty( $post->ID ) || ! wp_revisions_enabled( $post ) )
|
||||
return array();
|
||||
|
||||
$defaults = array( 'order' => 'DESC', 'orderby' => 'date' );
|
||||
|
@ -381,6 +381,47 @@ function wp_get_post_revisions( $post_id = 0, $args = null ) {
|
|||
return $revisions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if revisions are enabled for a given post.
|
||||
*
|
||||
* @since 3.6.0
|
||||
*
|
||||
* @uses wp_revisions_to_keep()
|
||||
*
|
||||
* @param object $post
|
||||
* @return bool
|
||||
*/
|
||||
function wp_revisions_enabled( $post ) {
|
||||
return wp_revisions_to_keep( $post ) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @uses post_type_supports()
|
||||
* @uses apply_filters() Calls 'wp_revisions_to_keep' hook on the number of revisions.
|
||||
*
|
||||
* @param object $post
|
||||
* @return int
|
||||
*/
|
||||
function wp_revisions_to_keep( $post ) {
|
||||
$num = WP_POST_REVISIONS;
|
||||
|
||||
if ( true === $num )
|
||||
$num = -1;
|
||||
else
|
||||
$num = intval( $num );
|
||||
|
||||
if ( ! post_type_supports( $post->post_type, 'revisions' ) )
|
||||
$num = 0;
|
||||
|
||||
return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
|
||||
}
|
||||
|
||||
|
||||
function _set_preview($post) {
|
||||
|
||||
if ( ! is_object($post) )
|
||||
|
|
Loading…
Reference in New Issue