WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/16/2013 09:15:43 PM (8 years ago)
Author:
azaozz
Message:

Create one autosave per user rather than a single autosave for all users. Remove unused code from autosave.js and wp_ajax_autosave(). See #23665.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/revision.php

    r23594 r23735  
    136136 *
    137137 * Returns a post object containing the information that was autosaved for the
    138  * specified post.
    139  *
    140  * @package WordPress
    141  * @subpackage Post_Revisions
    142  * @since 2.6.0
    143  *
     138 * specified post. If the optional $user_id is passed, returns the autosave for that user
     139 * otherwise returns the latest autosave.
     140 *
     141 * @package WordPress
     142 * @subpackage Post_Revisions
     143 * @since 2.6.0
     144 * @uses wp_get_post_revisions()
     145 * 
    144146 * @param int $post_id The post ID.
     147 * @param int $user_id optional The post author ID.
    145148 * @return object|bool The autosaved data or false on failure or when no autosave exists.
    146149 */
    147 function wp_get_post_autosave( $post_id ) {
    148 
    149     if ( !$post = get_post( $post_id ) )
    150         return false;
    151 
    152     $q = array(
    153         'name' => "{$post->ID}-autosave",
    154         'post_parent' => $post->ID,
    155         'post_type' => 'revision',
    156         'post_status' => 'inherit'
    157     );
    158 
    159     // Use WP_Query so that the result gets cached
    160     $autosave_query = new WP_Query;
    161 
    162     add_action( 'parse_query', '_wp_get_post_autosave_hack' );
    163     $autosave = $autosave_query->query( $q );
    164     remove_action( 'parse_query', '_wp_get_post_autosave_hack' );
    165 
    166     if ( $autosave && is_array($autosave) && is_object($autosave[0]) )
    167         return $autosave[0];
     150function wp_get_post_autosave( $post_id, $user_id = 0 ) {
     151    $revisions = wp_get_post_revisions($post_id);
     152
     153    foreach ( $revisions as $revision ) {
     154        if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) {
     155            if ( $user_id && $user_id != $revision->post_author )
     156                continue;
     157
     158            return $revision;
     159            break;
     160        }
     161    }
    168162
    169163    return false;
    170 }
    171 
    172 /**
    173  * Internally used to hack WP_Query into submission.
    174  *
    175  * @package WordPress
    176  * @subpackage Post_Revisions
    177  * @since 2.6.0
    178  *
    179  * @param object $query WP_Query object
    180  */
    181 function _wp_get_post_autosave_hack( $query ) {
    182     $query->is_single = false;
    183164}
    184165
     
    196177    if ( !$post = wp_get_post_revision( $post ) )
    197178        return false;
     179
    198180    return (int) $post->post_parent;
    199181}
     
    212194    if ( !$post = wp_get_post_revision( $post ) )
    213195        return false;
    214     if ( "{$post->post_parent}-autosave" !== $post->post_name )
    215         return false;
    216     return (int) $post->post_parent;
     196
     197    if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) )
     198        return (int) $post->post_parent;
     199
     200    return false;
    217201}
    218202
     
    235219    elseif ( !is_array($post) )
    236220        $post = get_post($post, ARRAY_A);
     221
    237222    if ( !$post || empty($post['ID']) )
    238223        return;
     
    250235    if ( $revision_id )
    251236        do_action( '_wp_put_post_revision', $revision_id );
     237
    252238    return $revision_id;
    253239}
     
    313299
    314300    $update = array();
    315     foreach( array_intersect( array_keys( $revision ), $fields ) as $field )
     301    foreach( array_intersect( array_keys( $revision ), $fields ) as $field ) {
    316302        $update[$field] = $revision[$field];
     303    }
    317304
    318305    if ( !$update )
     
    375362 */
    376363function wp_get_post_revisions( $post_id = 0, $args = null ) {
    377     if ( ! WP_POST_REVISIONS )
    378         return array();
    379364    if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) )
    380365        return array();
     
    386371    if ( !$revisions = get_children( $args ) )
    387372        return array();
     373
    388374    return $revisions;
    389375}
Note: See TracChangeset for help on using the changeset viewer.