Ticket #11889: 11889-3.diff
| File 11889-3.diff, 1.6 KB (added by , 16 years ago) |
|---|
-
wp-admin/includes/post.php
335 335 * @return object stdClass object containing all the default post data as attributes 336 336 */ 337 337 function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) { 338 global $wpdb ;338 global $wpdb, $user_ID; 339 339 340 340 $post_title = ''; 341 341 if ( !empty( $_REQUEST['post_title'] ) ) … … 349 349 if ( !empty( $_REQUEST['excerpt'] ) ) 350 350 $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] )); 351 351 352 if ( $create_in_db ) {352 if ( $create_in_db && $user_ID ) { 353 353 // Cleanup old auto-drafts more than 7 days old 354 354 $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" ); 355 foreach ( (array) $old_posts as $delete ) 355 foreach ( (array) $old_posts as $delete ) { 356 356 wp_delete_post( $delete, true ); // Force delete 357 $post = get_post( wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) ) ); 357 } 358 359 $auto_draft_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND post_author = %d", $user_ID ) ); 360 361 if ( empty($auto_draft_id) ) 362 $auto_draft_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft', 'post_author' => $user_ID ) ); 363 364 $post = get_post( $auto_draft_id ); 358 365 } else { 359 366 $post->ID = 0; 360 367 $post->post_author = '';