Changeset 23735 for trunk/wp-includes/revision.php
- Timestamp:
- 03/16/2013 09:15:43 PM (13 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/revision.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/revision.php
r23594 r23735 136 136 * 137 137 * 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 * 144 146 * @param int $post_id The post ID. 147 * @param int $user_id optional The post author ID. 145 148 * @return object|bool The autosaved data or false on failure or when no autosave exists. 146 149 */ 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]; 150 function 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 } 168 162 169 163 return false; 170 }171 172 /**173 * Internally used to hack WP_Query into submission.174 *175 * @package WordPress176 * @subpackage Post_Revisions177 * @since 2.6.0178 *179 * @param object $query WP_Query object180 */181 function _wp_get_post_autosave_hack( $query ) {182 $query->is_single = false;183 164 } 184 165 … … 196 177 if ( !$post = wp_get_post_revision( $post ) ) 197 178 return false; 179 198 180 return (int) $post->post_parent; 199 181 } … … 212 194 if ( !$post = wp_get_post_revision( $post ) ) 213 195 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; 217 201 } 218 202 … … 235 219 elseif ( !is_array($post) ) 236 220 $post = get_post($post, ARRAY_A); 221 237 222 if ( !$post || empty($post['ID']) ) 238 223 return; … … 250 235 if ( $revision_id ) 251 236 do_action( '_wp_put_post_revision', $revision_id ); 237 252 238 return $revision_id; 253 239 } … … 313 299 314 300 $update = array(); 315 foreach( array_intersect( array_keys( $revision ), $fields ) as $field ) 301 foreach( array_intersect( array_keys( $revision ), $fields ) as $field ) { 316 302 $update[$field] = $revision[$field]; 303 } 317 304 318 305 if ( !$update ) … … 375 362 */ 376 363 function wp_get_post_revisions( $post_id = 0, $args = null ) { 377 if ( ! WP_POST_REVISIONS )378 return array();379 364 if ( ( !$post = get_post( $post_id ) ) || empty( $post->ID ) ) 380 365 return array(); … … 386 371 if ( !$revisions = get_children( $args ) ) 387 372 return array(); 373 388 374 return $revisions; 389 375 }
Note: See TracChangeset
for help on using the changeset viewer.