Ticket #22289: 22289.5.patch
File 22289.5.patch, 6.0 KB (added by , 10 years ago) |
---|
-
wp-admin/revision.php
29 29 break; 30 30 31 31 // 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 ) ) { 33 33 $redirect = 'edit.php?post_type=' . $post->post_type; 34 34 break; 35 35 } … … 70 70 else 71 71 break; // Don't diff two unrelated revisions 72 72 73 if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') ) { // Revisions disabled73 if ( ! wp_revisions_enabled( $post ) ) { // Revisions disabled 74 74 if ( 75 75 // 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 ) ) 77 77 || 78 78 // we're not comparing an autosave to the current post 79 79 ( $post->ID !== $left_revision->ID && $post->ID !== $right_revision->ID ) … … 112 112 break; 113 113 114 114 // 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 ) ) { 116 116 $redirect = 'edit.php?post_type=' . $post->post_type; 117 117 break; 118 118 } … … 210 210 <?php 211 211 212 212 $args = array( 'format' => 'form-table', 'parent' => true, 'right' => $right, 'left' => $left ); 213 if ( ! WP_POST_REVISIONS || !post_type_supports($post->post_type, 'revisions') )213 if ( ! wp_revisions_enabled( $post ) ) 214 214 $args['type'] = 'autosave'; 215 215 216 216 wp_list_post_revisions( $post, $args ); -
wp-includes/class-wp-xmlrpc-server.php
3441 3441 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); 3442 3442 3443 3443 // Check if revisions are enabled. 3444 if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions') )3444 if ( ! wp_revisions_enabled( $post ) ) 3445 3445 return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); 3446 3446 3447 3447 $revisions = wp_get_post_revisions( $post_id ); … … 3506 3506 return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) ); 3507 3507 3508 3508 // Check if revisions are disabled. 3509 if ( ! WP_POST_REVISIONS || ! post_type_supports( $post->post_type, 'revisions') )3509 if ( ! wp_revisions_enabled( $post ) ) 3510 3510 return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); 3511 3511 3512 3512 $post = wp_restore_post_revision( $revision_id ); -
wp-includes/revision.php
78 78 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 79 79 return; 80 80 81 // WP_POST_REVISIONS = 0, false 82 if ( ! WP_POST_REVISIONS ) 81 if ( ! $post = get_post( $post_id, ARRAY_A ) ) 83 82 return; 84 83 85 if ( ! $post = get_post( $post_id, ARRAY_A) )84 if ( ! wp_revisions_enabled( (object) $post ) ) 86 85 return; 87 86 88 87 if ( 'auto-draft' == $post['post_status'] ) 89 88 return; 90 89 91 if ( ! post_type_supports($post['post_type'], 'revisions') )90 if ( ! post_type_supports( $post['post_type'], 'revisions' ) ) 92 91 return; 93 92 94 93 // if new data is supplied, check that it is different from last saved revision, unless a plugin tells us to always save regardless … … 107 106 108 107 $return = _wp_put_post_revision( $post ); 109 108 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 ) 112 112 return $return; 113 113 114 114 // all revisions and (possibly) one autosave 115 115 $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) ); 116 116 117 // WP_POST_REVISIONS = (int) (# of autosaves to save) 118 $delete = count($revisions) - WP_POST_REVISIONS; 117 $delete = count($revisions) - $revisions_to_keep; 119 118 120 119 if ( $delete < 1 ) 121 120 return $return; … … 371 370 * @return array empty if no revisions 372 371 */ 373 372 function 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 ) ) 375 375 return array(); 376 if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) ) 376 377 if ( ! wp_revisions_enabled( $post ) ) 377 378 return array(); 378 379 379 380 $defaults = array( 'order' => 'DESC', 'orderby' => 'date' ); 380 381 $args = wp_parse_args( $args, $defaults ); 381 382 $args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) ); 382 383 383 if ( ! $revisions = get_children( $args ) )384 if ( ! $revisions = get_children( $args ) ) 384 385 return array(); 386 385 387 return $revisions; 386 388 } 387 389 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 */ 400 function 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 */ 416 function 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 388 430 function _set_preview($post) { 389 431 390 432 if ( ! is_object($post) )