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: http://core.svn.wordpress.org/trunk@23818 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d8116e7786
commit
acfeb6f20f
|
@ -48,7 +48,7 @@ default :
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Revisions disabled and we're not looking at an autosave
|
// 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;
|
$redirect = 'edit.php?post_type=' . $post->post_type;
|
||||||
break;
|
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.' ) );
|
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) );
|
||||||
|
|
||||||
// Check if revisions are enabled.
|
// 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.' ) );
|
return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
|
||||||
|
|
||||||
$revisions = wp_get_post_revisions( $post_id );
|
$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.' ) );
|
return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) );
|
||||||
|
|
||||||
// Check if revisions are disabled.
|
// 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.' ) );
|
return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
|
||||||
|
|
||||||
$post = wp_restore_post_revision( $revision_id );
|
$post = wp_restore_post_revision( $revision_id );
|
||||||
|
|
|
@ -78,17 +78,16 @@ function wp_save_post_revision( $post_id, $new_data = null ) {
|
||||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// WP_POST_REVISIONS = 0, false
|
if ( ! $post = get_post( $post_id, ARRAY_A ) )
|
||||||
if ( ! WP_POST_REVISIONS )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( !$post = get_post( $post_id, ARRAY_A ) )
|
if ( ! wp_revisions_enabled( (object) $post ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( 'auto-draft' == $post['post_status'] )
|
if ( 'auto-draft' == $post['post_status'] )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( !post_type_supports($post['post_type'], 'revisions') )
|
if ( ! post_type_supports( $post['post_type'], 'revisions' ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// if new data is supplied, check that it is different from last saved revision, unless a plugin tells us to always save regardless
|
// if new data is supplied, check that it is different from last saved revision, unless a plugin tells us to always save regardless
|
||||||
|
@ -107,15 +106,15 @@ function wp_save_post_revision( $post_id, $new_data = null ) {
|
||||||
|
|
||||||
$return = _wp_put_post_revision( $post );
|
$return = _wp_put_post_revision( $post );
|
||||||
|
|
||||||
// WP_POST_REVISIONS = true (default), -1
|
$revisions_to_keep = wp_revisions_to_keep( (object) $post );
|
||||||
if ( !is_numeric( WP_POST_REVISIONS ) || WP_POST_REVISIONS < 0 )
|
|
||||||
|
if ( $revisions_to_keep < 0 )
|
||||||
return $return;
|
return $return;
|
||||||
|
|
||||||
// all revisions and (possibly) one autosave
|
// all revisions and (possibly) one autosave
|
||||||
$revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
|
$revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
|
||||||
|
|
||||||
// WP_POST_REVISIONS = (int) (# of autosaves to save)
|
$delete = count($revisions) - $revisions_to_keep;
|
||||||
$delete = count($revisions) - WP_POST_REVISIONS;
|
|
||||||
|
|
||||||
if ( $delete < 1 )
|
if ( $delete < 1 )
|
||||||
return $return;
|
return $return;
|
||||||
|
@ -368,19 +367,61 @@ function wp_delete_post_revision( $revision_id ) {
|
||||||
* @return array empty if no revisions
|
* @return array empty if no revisions
|
||||||
*/
|
*/
|
||||||
function wp_get_post_revisions( $post_id = 0, $args = null ) {
|
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();
|
return array();
|
||||||
|
|
||||||
$defaults = array( 'order' => 'DESC', 'orderby' => 'date' );
|
$defaults = array( 'order' => 'DESC', 'orderby' => 'date' );
|
||||||
$args = wp_parse_args( $args, $defaults );
|
$args = wp_parse_args( $args, $defaults );
|
||||||
$args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) );
|
$args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) );
|
||||||
|
|
||||||
if ( !$revisions = get_children( $args ) )
|
if ( ! $revisions = get_children( $args ) )
|
||||||
return array();
|
return array();
|
||||||
|
|
||||||
return $revisions;
|
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) {
|
function _set_preview($post) {
|
||||||
|
|
||||||
if ( ! is_object($post) )
|
if ( ! is_object($post) )
|
||||||
|
|
Loading…
Reference in New Issue