Make WordPress Core

Changeset 23818


Ignore:
Timestamp:
03/27/2013 06:11:56 PM (12 years ago)
Author:
markjaquith
Message:

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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/revision.php

    r23769 r23818  
    4949
    5050    // Revisions disabled and we're not looking at an autosave
    51     if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
     51    if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
    5252        $redirect = 'edit.php?post_type=' . $post->post_type;
    5353        break;
  • trunk/wp-includes/class-wp-xmlrpc-server.php

    r23636 r23818  
    35363536
    35373537        // Check if revisions are enabled.
    3538         if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) )
     3538        if ( ! wp_revisions_enabled( $post ) )
    35393539            return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
    35403540
     
    36033603
    36043604        // Check if revisions are disabled.
    3605         if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) )
     3605        if ( ! wp_revisions_enabled( $post ) )
    36063606            return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
    36073607
  • trunk/wp-includes/revision.php

    r23811 r23818  
    7979        return;
    8080
    81     // WP_POST_REVISIONS = 0, false
    82     if ( ! WP_POST_REVISIONS )
     81    if ( ! $post = get_post( $post_id, ARRAY_A ) )
    8382        return;
    8483
    85     if ( !$post = get_post( $post_id, ARRAY_A ) )
     84    if ( ! wp_revisions_enabled( (object) $post ) )
    8685        return;
    8786
     
    8988        return;
    9089
    91     if ( !post_type_supports($post['post_type'], 'revisions') )
     90    if ( ! post_type_supports( $post['post_type'], 'revisions' ) )
    9291        return;
    9392
     
    108107    $return = _wp_put_post_revision( $post );
    109108
    110     // WP_POST_REVISIONS = true (default), -1
    111     if ( !is_numeric( WP_POST_REVISIONS ) || WP_POST_REVISIONS < 0 )
     109    $revisions_to_keep = wp_revisions_to_keep( (object) $post );
     110
     111    if ( $revisions_to_keep < 0 )
    112112        return $return;
    113113
     
    115115    $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
    116116
    117     // WP_POST_REVISIONS = (int) (# of autosaves to save)
    118     $delete = count($revisions) - WP_POST_REVISIONS;
     117    $delete = count($revisions) - $revisions_to_keep;
    119118
    120119    if ( $delete < 1 )
     
    369368 */
    370369function wp_get_post_revisions( $post_id = 0, $args = null ) {
    371     if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) )
     370    $post = get_post( $post_id );
     371    if ( ! $post || empty( $post->ID ) || ! wp_revisions_enabled( $post ) )
    372372        return array();
    373373
     
    376376    $args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) );
    377377
    378     if ( !$revisions = get_children( $args ) )
     378    if ( ! $revisions = get_children( $args ) )
    379379        return array();
    380380
    381381    return $revisions;
    382382}
     383
     384/**
     385 * Determine if revisions are enabled for a given post.
     386 *
     387 * @since 3.6.0
     388 *
     389 * @uses wp_revisions_to_keep()
     390 *
     391 * @param object $post
     392 * @return bool
     393 */
     394function wp_revisions_enabled( $post ) {
     395    return wp_revisions_to_keep( $post ) != 0;
     396}
     397
     398/**
     399 * Determine how many revisions to retain for a given post.
     400 * By default, an infinite number of revisions are stored if a post type supports revisions.
     401 *
     402 * @since 3.6.0
     403 *
     404 * @uses post_type_supports()
     405 * @uses apply_filters() Calls 'wp_revisions_to_keep' hook on the number of revisions.
     406 *
     407 * @param object $post
     408 * @return int
     409 */
     410function wp_revisions_to_keep( $post ) {
     411    $num = WP_POST_REVISIONS;
     412
     413    if ( true === $num )
     414        $num = -1;
     415    else
     416        $num = intval( $num );
     417
     418    if ( ! post_type_supports( $post->post_type, 'revisions' ) )
     419        $num = 0;
     420
     421    return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
     422}
     423
    383424
    384425function _set_preview($post) {
Note: See TracChangeset for help on using the changeset viewer.