Make WordPress Core

Ticket #11889: 11889-3.diff

File 11889-3.diff, 1.6 KB (added by azaozz, 16 years ago)

Perhaps something like this

  • wp-admin/includes/post.php

     
    335335 * @return object stdClass object containing all the default post data as attributes
    336336 */
    337337function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
    338         global $wpdb;
     338        global $wpdb, $user_ID;
    339339
    340340        $post_title = '';
    341341        if ( !empty( $_REQUEST['post_title'] ) )
     
    349349        if ( !empty( $_REQUEST['excerpt'] ) )
    350350                $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
    351351
    352         if ( $create_in_db ) {
     352        if ( $create_in_db && $user_ID ) {
    353353                // Cleanup old auto-drafts more than 7 days old
    354354                $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 ) {
    356356                        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 );
    358365        } else {
    359366                $post->ID = 0;
    360367                $post->post_author = '';