WordPress.org

Make WordPress Core

Ticket #22289: 22289.5.patch

File 22289.5.patch, 6.0 KB (added by SergeyBiryukov, 5 years ago)

Minor phpdoc and formatting fixes

  • 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
    76                         ( !wp_is_post_autosave( $left_revision ) && !wp_is_post_autosave( $right_revision ) )
     76                        ( ! wp_is_post_autosave( $left_revision ) && ! wp_is_post_autosave( $right_revision ) )
    7777                ||
    7878                        // we're not comparing an autosave to the current post
    7979                        ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID )
     
    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'] )
    8988                return;
    9089
    91         if ( !post_type_supports($post['post_type'], 'revisions') )
     90        if ( ! post_type_supports( $post['post_type'], 'revisions' ) )
    9291                return;
    9392
    9493        // if new data is supplied, check that it is different from last saved revision, unless a plugin tells us to always save regardless
     
    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 )
     373        $post = get_post( $post_id );
     374        if ( ! $post || empty( $post->ID ) )
    375375                return array();
    376         if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) )
     376
     377        if ( ! wp_revisions_enabled( $post ) )
    377378                return array();
    378379
    379380        $defaults = array( 'order' => 'DESC', 'orderby' => 'date' );
    380381        $args = wp_parse_args( $args, $defaults );
    381382        $args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) );
    382383
    383         if ( !$revisions = get_children( $args ) )
     384        if ( ! $revisions = get_children( $args ) )
    384385                return array();
     386
    385387        return $revisions;
    386388}
    387389
     390/**
     391 * Determine if revisions are enabled for a given post.
     392 *
     393 * @since 3.6.0
     394 *
     395 * @uses wp_revisions_to_keep()
     396 *
     397 * @param object $post
     398 * @return bool
     399 */
     400function wp_revisions_enabled( $post ) {
     401        return wp_revisions_to_keep( $post ) != 0;
     402}
     403
     404/**
     405 * Determine how many revisions to retain for a given post.
     406 * By default, an infinite number of revisions are stored if a post type supports revisions.
     407 *
     408 * @since 3.6.0
     409 *
     410 * @uses post_type_supports()
     411 * @uses apply_filters() Calls 'wp_revisions_to_keep' hook on the number of revisions.
     412 *
     413 * @param object $post
     414 * @return int
     415 */
     416function wp_revisions_to_keep( $post ) {
     417        $num = WP_POST_REVISIONS;
     418
     419        if ( true === $num )
     420                $num = -1;
     421        else
     422                $num = intval( $num );
     423
     424        if ( ! post_type_supports( $post->post_type, 'revisions' ) )
     425                $num = 0;
     426
     427        return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
     428}
     429
    388430function _set_preview($post) {
    389431
    390432        if ( ! is_object($post) )