WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/06/2010 10:07:57 AM (11 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/edit-form-advanced.php

    r12937 r12987  
    6161
    6262$notice = false;
    63 if ( 0 == $post_ID ) {
    64     $form_action = 'post';
    65     $nonce_action = 'add-' . $post_type;
    66     $temp_ID = -1 * time(); // don't change this formula without looking at wp_write_post()
    67     $form_extra = "<input type='hidden' id='post_ID' name='temp_ID' value='" . esc_attr($temp_ID) . "' />";
     63$form_extra = '';
     64if ( 'auto-draft' == $post->post_status ) {
     65    if ( 'edit' == $action )
     66        $post->post_title = '';
    6867    $autosave = false;
     68    $form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />";
    6969} else {
    70     $form_action = 'editpost';
    71     $nonce_action = 'update-' . $post_type . '_' . $post_ID;
    72     $form_extra = "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr($post_ID) . "' />";
    7370    $autosave = wp_get_post_autosave( $post_ID );
    74 
    75     // Detect if there exists an autosave newer than the post and if that autosave is different than the post
    76     if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) {
    77         foreach ( _wp_post_revision_fields() as $autosave_field => $_autosave_field ) {
    78             if ( normalize_whitespace( $autosave->$autosave_field ) != normalize_whitespace( $post->$autosave_field ) ) {
    79                 $notice = sprintf( __( 'There is an autosave of this post that is more recent than the version below.  <a href="%s">View the autosave</a>' ), get_edit_post_link( $autosave->ID ) );
    80                 break;
    81             }
     71}
     72
     73$form_action = 'editpost';
     74$nonce_action = 'update-' . $post_type . '_' . $post_ID;
     75$form_extra .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr($post_ID) . "' />";
     76
     77// Detect if there exists an autosave newer than the post and if that autosave is different than the post
     78if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) {
     79    foreach ( _wp_post_revision_fields() as $autosave_field => $_autosave_field ) {
     80        if ( normalize_whitespace( $autosave->$autosave_field ) != normalize_whitespace( $post->$autosave_field ) ) {
     81            $notice = sprintf( __( 'There is an autosave of this post that is more recent than the version below.  <a href="%s">View the autosave</a>' ), get_edit_post_link( $autosave->ID ) );
     82            break;
    8283        }
    83         unset($autosave_field, $_autosave_field);
    8484    }
     85    unset($autosave_field, $_autosave_field);
    8586}
    8687
     
    198199    <div id="edit-slug-box">
    199200<?php
    200     if ( ! empty($post->ID) && ! empty($sample_permalink_html) ) :
     201    if ( ! empty($post->ID) && ! empty($sample_permalink_html) && 'auto-draft' != $post->post_status ) :
    201202        echo $sample_permalink_html;
    202203endif; ?>
     
    216217    <span id="autosave">&nbsp;</span>
    217218<?php
    218     if ( $post_ID ) {
     219    if ( 'auto-draft' != $post->post_status ) {
    219220        echo '<span id="last-edit">';
    220221        if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) {
Note: See TracChangeset for help on using the changeset viewer.