WordPress.org

Make WordPress Core

Ticket #22289: 22289.4.patch

File 22289.4.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/revision.php

     
    7878        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    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
    8887        if ( 'auto-draft' == $post['post_status'] )
     
    107106
    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
    114114        // all revisions and (possibly) one autosave
    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 )
    121120                return $return;
     
    371370 * @return array empty if no revisions
    372371 */
    373372function wp_get_post_revisions( $post_id = 0, $args = null ) {
    374         if ( ! WP_POST_REVISIONS )
    375                 return array();
    376373        if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) )
    377374                return array();
    378375
     376        if ( ! wp_revisions_enabled( $post ) )
     377                return array();
     378
    379379        $defaults = array( 'order' => 'DESC', 'orderby' => 'date' );
    380380        $args = wp_parse_args( $args, $defaults );
    381381        $args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) );
     
    385385        return $revisions;
    386386}
    387387
     388/**
     389 * Determine if revisions are enabled for a given post.
     390 *
     391 * @since 3.6
     392 *
     393 * @uses wp_revisions_to_keep
     394 *
     395 * @param object $post
     396 * @return bool
     397 */
     398function wp_revisions_enabled( $post ) {
     399        return wp_revisions_to_keep( $post ) != 0;
     400}
     401
     402/**
     403 * Determine how many revisions to retain for a given post.
     404 * By default, an infinite number of revisions are stored if a post type supports revisions.
     405 *
     406 * @since 3.6
     407 *
     408 * @uses post_type_supports
     409 * @uses apply_filters
     410 *
     411 * @param object $post
     412 * @return int
     413 */
     414function wp_revisions_to_keep( $post ) {
     415        $num = WP_POST_REVISIONS;
     416
     417        if ( true === $num )
     418                $num = -1;
     419        else
     420                $num = intval( $num );
     421
     422        if ( ! post_type_supports( $post->post_type, 'revisions' ) )
     423                $num = 0;
     424
     425        return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
     426}
     427
    388428function _set_preview($post) {
    389429
    390430        if ( ! is_object($post) )