Make WordPress Core


Ignore:
Timestamp:
02/06/2010 10:07:57 AM (15 years ago)
Author:
markjaquith
Message:

Create post_status=auto-draft when creating a new post item. status changes to draft on first auto-save. now we always have a real post ID to work with. see #11889. fixes #11145. fixes #11990

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/post.php

    r12954 r12987  
    7777    if ( isset( $post_data['ID'] ) )
    7878        $post_id = $post_data['ID'];
    79     elseif ( isset( $post_data['temp_ID'] ) )
    80         $post_id = $post_data['temp_ID'];
    8179    else
    8280        $post_id = false;
     
    337335 * @return object stdClass object containing all the default post data as attributes
    338336 */
    339 function get_default_post_to_edit( $post_type = 'post' ) {
     337function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
     338    global $wpdb;
    340339
    341340    $post_title = '';
     
    351350        $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
    352351
    353     $post->ID = 0;
     352    if ( $create_in_db ) {
     353        // Cleanup old auto-drafts more than 7 days old
     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 )
     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' ) ) );
     358    } else {
     359        $post->ID = 0;
     360        $post->post_author = '';
     361        $post->post_date = '';
     362        $post->post_date_gmt = '';
     363        $post->post_password = '';
     364        $post->post_type = $post_type;
     365        $post->post_status = 'draft';
     366        $post->to_ping = '';
     367        $post->pinged = '';
     368        $post->comment_status = get_option( 'default_comment_status' );
     369        $post->ping_status = get_option( 'default_ping_status' );
     370        $post->post_pingback = get_option( 'default_pingback_flag' );
     371        $post->post_category = get_option( 'default_category' );
     372        $post->page_template = 'default';
     373        $post->post_parent = 0;
     374        $post->menu_order = 0;
     375    }
     376
     377    $post->post_content = apply_filters( 'default_content', $post_content );
     378    $post->post_title   = apply_filters( 'default_title',   $post_title   );
     379    $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt );
    354380    $post->post_name = '';
    355     $post->post_author = '';
    356     $post->post_date = '';
    357     $post->post_date_gmt = '';
    358     $post->post_password = '';
    359     $post->post_status = 'draft';
    360     $post->post_type = $post_type;
    361     $post->to_ping = '';
    362     $post->pinged = '';
    363     $post->comment_status = get_option( 'default_comment_status' );
    364     $post->ping_status = get_option( 'default_ping_status' );
    365     $post->post_pingback = get_option( 'default_pingback_flag' );
    366     $post->post_category = get_option( 'default_category' );
    367     $post->post_content = apply_filters( 'default_content', $post_content);
    368     $post->post_title = apply_filters( 'default_title', $post_title );
    369     $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt);
    370     $post->page_template = 'default';
    371     $post->post_parent = 0;
    372     $post->menu_order = 0;
    373381
    374382    return $post;
     
    466474
    467475    // Check for autosave collisions
     476    // Does this need to be updated? ~ Mark
    468477    $temp_id = false;
    469478    if ( isset($_POST['temp_ID']) ) {
     
    474483            if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then )
    475484                unset($draft_ids[$temp]);
    476 
     485   
    477486        if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write
    478487            $_POST['post_ID'] = $draft_ids[$temp_id];
     
    514523
    515524    // Reunite any orphaned attachments with their parent
     525    // Does this need to be udpated? ~ Mark
    516526    if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
    517527        $draft_ids = array();
Note: See TracChangeset for help on using the changeset viewer.