WordPress.org

Make WordPress Core

Ticket #22289: 22289.3.patch

File 22289.3.patch, 5.2 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 ) && !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 ) ) { // 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 ) && !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 ) )
    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 ) )
    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 ) )
    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( (object) $post ) )
    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( (object) $post );
     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 ) )
     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.
     5333 *
     5334 * @since 3.6
     5335 *
     5336 * @uses wp_revisions_to_keep
     5337 *
     5338 * @param object $post
     5339 * @return bool
     5340 */
     5341function wp_revisions_enabled( $post ) {
     5342        return wp_revisions_to_keep( $post ) != 0;
     5343}
     5344
     5345/**
     5346 * Determine how many revisions to retain for a given post.
     5347 * By default, an infinite number of revisions are stored if a post type supports revisions.
     5348 *
     5349 * @since 3.6
     5350 *
     5351 * @uses post_type_supports
     5352 * @uses apply_filters
     5353 *
     5354 * @param object $post
     5355 * @return int
     5356 */
     5357function wp_revisions_to_keep( $post ) {
     5358        $num = WP_POST_REVISIONS;
     5359
     5360        if ( true === $num )
     5361                $num = -1;
     5362        else
     5363                $num = intval( $num );
     5364
     5365        if ( ! post_type_supports( $post->post_type, 'revisions' ) )
     5366                $num = 0;
     5367
     5368        return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
     5369}
     5370
    53315371function _set_preview($post) {
    53325372
    53335373        if ( ! is_object($post) )