WordPress.org

Make WordPress Core

Ticket #22289: 22289.2.patch

File 22289.2.patch, 5.8 KB (added by ethitter, 5 years ago)
  • wp-admin/revision.php

     
    2929                break;
    3030
    3131        // Revisions disabled and we're not looking at an autosave
    32         if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
     32        if ( ! wp_revisions_enabled( $post->post_type ) && !wp_is_post_autosave( $revision ) ) {
    3333                $redirect = 'edit.php?post_type=' . $post->post_type;
    3434                break;
    3535        }
     
    7070        else
    7171                break; // Don't diff two unrelated revisions
    7272
    73         if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) { // Revisions disabled
     73        if ( ! wp_revisions_enabled( $post->post_type ) ) { // Revisions disabled
    7474                if (
    7575                        // we're not looking at an autosave
    7676                        ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )
     
    112112                break;
    113113
    114114        // Revisions disabled and we're not looking at an autosave
    115         if ( ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) && !wp_is_post_autosave( $revision ) ) {
     115        if ( ! wp_revisions_enabled( $post->post_type ) && !wp_is_post_autosave( $revision ) ) {
    116116                $redirect = 'edit.php?post_type=' . $post->post_type;
    117117                break;
    118118        }
     
    210210<?php
    211211
    212212$args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left );
    213 if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') )
     213if ( ! wp_revisions_enabled( $post->post_type ) )
    214214        $args['type'] = 'autosave';
    215215
    216216wp_list_post_revisions( $post, $args );
  • wp-includes/class-wp-xmlrpc-server.php

     
    34413441                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) );
    34423442
    34433443                // Check if revisions are enabled.
    3444                 if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) )
     3444                if ( ! wp_revisions_enabled( $post->post_type ) )
    34453445                        return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
    34463446
    34473447                $revisions = wp_get_post_revisions( $post_id );
     
    35063506                        return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) );
    35073507
    35083508                // Check if revisions are disabled.
    3509                 if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions' ) )
     3509                if ( ! wp_revisions_enabled( $post->post_type ) )
    35103510                        return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
    35113511
    35123512                $post = wp_restore_post_revision( $revision_id );
  • wp-includes/post.php

     
    50215021        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    50225022                return;
    50235023
    5024         // WP_POST_REVISIONS = 0, false
    5025         if ( ! WP_POST_REVISIONS )
     5024        if ( !$post = get_post( $post_id, ARRAY_A ) )
    50265025                return;
    50275026
    5028         if ( !$post = get_post( $post_id, ARRAY_A ) )
     5027        if ( ! wp_revisions_enabled( $post['post_type'] ) )
    50295028                return;
    50305029
    50315030        if ( 'auto-draft' == $post['post_status'] )
     
    50505049
    50515050        $return = _wp_put_post_revision( $post );
    50525051
    5053         // WP_POST_REVISIONS = true (default), -1
    5054         if ( !is_numeric( WP_POST_REVISIONS ) || WP_POST_REVISIONS < 0 )
     5052        $revisions_to_keep = wp_revisions_to_keep( $post['post_type'] );
     5053
     5054        if ( $revisions_to_keep < 0 )
    50555055                return $return;
    50565056
    50575057        // all revisions and (possibly) one autosave
    50585058        $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
    50595059
    5060         // WP_POST_REVISIONS = (int) (# of autosaves to save)
    5061         $delete = count($revisions) - WP_POST_REVISIONS;
     5060        $delete = count($revisions) - $revisions_to_keep;
    50625061
    50635062        if ( $delete < 1 )
    50645063                return $return;
     
    53145313 * @return array empty if no revisions
    53155314 */
    53165315function wp_get_post_revisions( $post_id = 0, $args = null ) {
    5317         if ( ! WP_POST_REVISIONS )
    5318                 return array();
    53195316        if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) )
    53205317                return array();
    53215318
     5319        if ( ! wp_revisions_enabled( $post->post_type ) )
     5320                return array();
     5321
    53225322        $defaults = array( 'order' => 'DESC', 'orderby' => 'date' );
    53235323        $args = wp_parse_args( $args, $defaults );
    53245324        $args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) );
     
    53285328        return $revisions;
    53295329}
    53305330
     5331/**
     5332 * Determine if revisions are enabled for a given post type.
     5333 *
     5334 * @package WordPress
     5335 * @subpackage  Post_Revisions
     5336 * @since 3.6
     5337 *
     5338 * @uses wp_revisions_to_keep
     5339 *
     5340 * @param string $post_type
     5341 * @return bool
     5342 */
     5343function wp_revisions_enabled( $post_type = 'post' ) {
     5344        return wp_revisions_to_keep( $post_type ) > 0;
     5345}
     5346
     5347/**
     5348 * Determine how many revisions to retain for a given post type.
     5349 * By default, an infinite number of revisions are stored if a post type supports revisions.
     5350 *
     5351 * @package WordPress
     5352 * @subpackage  Post_Revisions
     5353 * @since 3.6
     5354 *
     5355 * @uses absint
     5356 * @uses post_type_supports
     5357 * @uses apply_filters
     5358 *
     5359 * @param string $post_type
     5360 * @return int
     5361 */
     5362function wp_revisions_to_keep( $post_type = 'post' ) {
     5363        $num = WP_POST_REVISIONS;
     5364
     5365        if ( true === $num )
     5366                $num = INF;
     5367        else
     5368                $num = intval( $num );
     5369
     5370        if ( $num > 0 && ! post_type_supports( $post_type, 'revisions' ) )
     5371                $num = 0;
     5372
     5373        $num = apply_filters( 'wp_revisions_to_keep', $num, $post_type );
     5374
     5375        if ( -INF === $num )
     5376                $num = 0;
     5377        elseif ( INF !== $num )
     5378                $num = intval( $num );
     5379
     5380        if ( $num < 0 ) {
     5381                _doing_it_wrong( __FUNCTION__, sprintf( __( 'The number of revisions to keep for the post type "%s" must be true, false, or a positive integer. The value "%s" is invalid, so 0 is assumed.' ), $post_type, $num ), '3.6' );
     5382
     5383                $num = 0;
     5384        }
     5385
     5386        return $num;
     5387}
     5388
    53315389function _set_preview($post) {
    53325390
    53335391        if ( ! is_object($post) )