diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php
index e2afc9da0..77648633d 100644
--- a/wp-admin/admin-ajax.php
+++ b/wp-admin/admin-ajax.php
@@ -887,57 +887,54 @@ case 'autosave' : // The name of this action is hardcoded in edit_post()
$supplemental['session_expired'] = add_query_arg( 'interim-login', 1, wp_login_url() );
$id = $revision_id = 0;
- if ( $_POST['post_ID'] < 0 ) {
+
+ $post_ID = (int) $_POST['post_ID'];
+ $_POST['ID'] = $post_ID;
+ $post = get_post($post_ID);
+ if ( 'auto-draft' == $post->post_status )
$_POST['post_status'] = 'draft';
- $_POST['temp_ID'] = $_POST['post_ID'];
- if ( $do_autosave ) {
- $id = wp_write_post();
- $data = $message;
- }
- } else {
- $post_ID = (int) $_POST['post_ID'];
- $_POST['ID'] = $post_ID;
- $post = get_post($post_ID);
- if ( $last = wp_check_post_lock( $post->ID ) ) {
- $do_autosave = $do_lock = false;
+ if ( $last = wp_check_post_lock( $post->ID ) ) {
+ $do_autosave = $do_lock = false;
- $last_user = get_userdata( $last );
- $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
- $data = new WP_Error( 'locked', sprintf(
- $_POST['post_type'] == 'page' ? __( 'Autosave disabled: %s is currently editing this page.' ) : __( 'Autosave disabled: %s is currently editing this post.' ),
- esc_html( $last_user_name )
- ) );
+ $last_user = get_userdata( $last );
+ $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
+ $data = new WP_Error( 'locked', sprintf(
+ $_POST['post_type'] == 'page' ? __( 'Autosave disabled: %s is currently editing this page.' ) : __( 'Autosave disabled: %s is currently editing this post.' ),
+ esc_html( $last_user_name )
+ ) );
- $supplemental['disable_autosave'] = 'disable';
- }
-
- if ( 'page' == $post->post_type ) {
- if ( !current_user_can('edit_page', $post_ID) )
- die(__('You are not allowed to edit this page.'));
- } else {
- if ( !current_user_can('edit_post', $post_ID) )
- die(__('You are not allowed to edit this post.'));
- }
-
- if ( $do_autosave ) {
- // Drafts are just overwritten by autosave
- if ( 'draft' == $post->post_status ) {
- $id = edit_post();
- } else { // Non drafts are not overwritten. The autosave is stored in a special post revision.
- $revision_id = wp_create_post_autosave( $post->ID );
- if ( is_wp_error($revision_id) )
- $id = $revision_id;
- else
- $id = $post->ID;
- }
- $data = $message;
- } else {
- $id = $post->ID;
- }
+ $supplemental['disable_autosave'] = 'disable';
}
- if ( $do_lock && $id && is_numeric($id) )
+ if ( 'page' == $post->post_type ) {
+ if ( !current_user_can('edit_page', $post_ID) )
+ die(__('You are not allowed to edit this page.'));
+ } else {
+ if ( !current_user_can('edit_post', $post_ID) )
+ die(__('You are not allowed to edit this post.'));
+ }
+
+ if ( $do_autosave ) {
+ // Drafts and auto-drafts are just overwritten by autosave
+ if ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) {
+ $id = edit_post();
+ } else { // Non drafts are not overwritten. The autosave is stored in a special post revision.
+ $revision_id = wp_create_post_autosave( $post->ID );
+ if ( is_wp_error($revision_id) )
+ $id = $revision_id;
+ else
+ $id = $post->ID;
+ }
+ $data = $message;
+ } else {
+ if ( '1' == $_POST['auto_draft'] )
+ $id = 0; // This tells us it didn't actually save
+ else
+ $id = $post->ID;
+ }
+
+ if ( $do_lock && $_POST['auto_draft'] != '1' && $id && is_numeric($id) )
wp_set_post_lock( $id );
if ( $nonce_age == 2 ) {
@@ -961,18 +958,6 @@ case 'autosave' : // The name of this action is hardcoded in edit_post()
) );
$x->send();
break;
-case 'autosave-generate-nonces' :
- check_ajax_referer( 'autosave', 'autosavenonce' );
- $ID = (int) $_POST['post_ID'];
- $post_type = $_POST['post_type'];
- $post_type_object = get_post_type_object($post_type);
- if ( !$post_type_object )
- die('0');
- if ( current_user_can( $post_type_object->edit_cap, $ID ) )
- die( json_encode( array( 'updateNonce' => wp_create_nonce( "update-{$post_type}_{$ID}" ), 'deleteURL' => str_replace( '&', '&', wp_nonce_url( admin_url( $post_type . '.php?action=trash&post=' . $ID ), "trash-{$post_type}_{$ID}" ) ) ) ) );
- do_action('autosave_generate_nonces');
- die('0');
-break;
case 'closed-postboxes' :
check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' );
$closed = isset( $_POST['closed'] ) ? $_POST['closed'] : '';
diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php
index 5a3377194..78cbde795 100644
--- a/wp-admin/edit-form-advanced.php
+++ b/wp-admin/edit-form-advanced.php
@@ -60,28 +60,29 @@ if ( isset($_GET['message']) ) {
}
$notice = false;
-if ( 0 == $post_ID ) {
- $form_action = 'post';
- $nonce_action = 'add-' . $post_type;
- $temp_ID = -1 * time(); // don't change this formula without looking at wp_write_post()
- $form_extra = "";
+$form_extra = '';
+if ( 'auto-draft' == $post->post_status ) {
+ if ( 'edit' == $action )
+ $post->post_title = '';
$autosave = false;
+ $form_extra .= "";
} else {
- $form_action = 'editpost';
- $nonce_action = 'update-' . $post_type . '_' . $post_ID;
- $form_extra = "";
$autosave = wp_get_post_autosave( $post_ID );
+}
- // Detect if there exists an autosave newer than the post and if that autosave is different than the post
- if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) {
- foreach ( _wp_post_revision_fields() as $autosave_field => $_autosave_field ) {
- if ( normalize_whitespace( $autosave->$autosave_field ) != normalize_whitespace( $post->$autosave_field ) ) {
- $notice = sprintf( __( 'There is an autosave of this post that is more recent than the version below. View the autosave' ), get_edit_post_link( $autosave->ID ) );
- break;
- }
+$form_action = 'editpost';
+$nonce_action = 'update-' . $post_type . '_' . $post_ID;
+$form_extra .= "";
+
+// Detect if there exists an autosave newer than the post and if that autosave is different than the post
+if ( $autosave && mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) {
+ foreach ( _wp_post_revision_fields() as $autosave_field => $_autosave_field ) {
+ if ( normalize_whitespace( $autosave->$autosave_field ) != normalize_whitespace( $post->$autosave_field ) ) {
+ $notice = sprintf( __( 'There is an autosave of this post that is more recent than the version below. View the autosave' ), get_edit_post_link( $autosave->ID ) );
+ break;
}
- unset($autosave_field, $_autosave_field);
}
+ unset($autosave_field, $_autosave_field);
}
$post_type_object = get_post_type_object($post_type);
@@ -197,7 +198,7 @@ $sample_permalink_html = get_sample_permalink_html($post->ID);
if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object->publish_cap ) ) ) { ?>
ID) && ! empty($sample_permalink_html) ) :
+ if ( ! empty($post->ID) && ! empty($sample_permalink_html) && 'auto-draft' != $post->post_status ) :
echo $sample_permalink_html;
endif; ?>
@@ -215,7 +216,7 @@ endif; ?>
post_status ) {
echo '';
if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) {
$last_user = get_userdata($last_id);
diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php
index 67dbdade9..483de415b 100644
--- a/wp-admin/includes/meta-boxes.php
+++ b/wp-admin/includes/meta-boxes.php
@@ -71,8 +71,12 @@ switch ( $post->post_status ) {
_e('Pending Review');
break;
case 'draft':
+ case 'auto-draft':
_e('Draft');
break;
+ case 'auto-draft':
+ _e('Unsaved');
+ break;
}
?>
@@ -80,7 +84,7 @@ switch ( $post->post_status ) {
post_status ) { ?>style="display:none;" class="edit-post-status hide-if-no-js" tabindex='4'>
-
+
diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php
index e64a9aa3c..a11b110c8 100644
--- a/wp-admin/includes/post.php
+++ b/wp-admin/includes/post.php
@@ -76,8 +76,6 @@ function _wp_translate_postdata( $update = false, $post_data = null ) {
if ( isset( $post_data['ID'] ) )
$post_id = $post_data['ID'];
- elseif ( isset( $post_data['temp_ID'] ) )
- $post_id = $post_data['temp_ID'];
else
$post_id = false;
$previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;
@@ -336,7 +334,8 @@ function bulk_edit_posts( $post_data = null ) {
*@param string A post type string, defaults to 'post'.
* @return object stdClass object containing all the default post data as attributes
*/
-function get_default_post_to_edit( $post_type = 'post' ) {
+function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
+ global $wpdb;
$post_title = '';
if ( !empty( $_REQUEST['post_title'] ) )
@@ -350,26 +349,35 @@ function get_default_post_to_edit( $post_type = 'post' ) {
if ( !empty( $_REQUEST['excerpt'] ) )
$post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
- $post->ID = 0;
+ if ( $create_in_db ) {
+ // Cleanup old auto-drafts more than 7 days old
+ $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
+ foreach ( (array) $old_posts as $delete )
+ wp_delete_post( $delete, true ); // Force delete
+ $post = get_post( wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) ) );
+ } else {
+ $post->ID = 0;
+ $post->post_author = '';
+ $post->post_date = '';
+ $post->post_date_gmt = '';
+ $post->post_password = '';
+ $post->post_type = $post_type;
+ $post->post_status = 'draft';
+ $post->to_ping = '';
+ $post->pinged = '';
+ $post->comment_status = get_option( 'default_comment_status' );
+ $post->ping_status = get_option( 'default_ping_status' );
+ $post->post_pingback = get_option( 'default_pingback_flag' );
+ $post->post_category = get_option( 'default_category' );
+ $post->page_template = 'default';
+ $post->post_parent = 0;
+ $post->menu_order = 0;
+ }
+
+ $post->post_content = apply_filters( 'default_content', $post_content );
+ $post->post_title = apply_filters( 'default_title', $post_title );
+ $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt );
$post->post_name = '';
- $post->post_author = '';
- $post->post_date = '';
- $post->post_date_gmt = '';
- $post->post_password = '';
- $post->post_status = 'draft';
- $post->post_type = $post_type;
- $post->to_ping = '';
- $post->pinged = '';
- $post->comment_status = get_option( 'default_comment_status' );
- $post->ping_status = get_option( 'default_ping_status' );
- $post->post_pingback = get_option( 'default_pingback_flag' );
- $post->post_category = get_option( 'default_category' );
- $post->post_content = apply_filters( 'default_content', $post_content);
- $post->post_title = apply_filters( 'default_title', $post_title );
- $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt);
- $post->page_template = 'default';
- $post->post_parent = 0;
- $post->menu_order = 0;
return $post;
}
@@ -465,6 +473,7 @@ function wp_write_post() {
}
// Check for autosave collisions
+ // Does this need to be updated? ~ Mark
$temp_id = false;
if ( isset($_POST['temp_ID']) ) {
$temp_id = (int) $_POST['temp_ID'];
@@ -473,7 +482,7 @@ function wp_write_post() {
foreach ( $draft_ids as $temp => $real )
if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then )
unset($draft_ids[$temp]);
-
+
if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write
$_POST['post_ID'] = $draft_ids[$temp_id];
unset($_POST['temp_ID']);
@@ -513,6 +522,7 @@ function wp_write_post() {
add_meta( $post_ID );
// Reunite any orphaned attachments with their parent
+ // Does this need to be udpated? ~ Mark
if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
$draft_ids = array();
if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )
diff --git a/wp-admin/post-new.php b/wp-admin/post-new.php
index 9753f9f57..318dbb22f 100644
--- a/wp-admin/post-new.php
+++ b/wp-admin/post-new.php
@@ -50,7 +50,8 @@ When you’re promoted, just reload this page and you’ll be able to bl
// Show post form.
if ( current_user_can($post_type_object->edit_type_cap) ) {
- $post = get_default_post_to_edit( $post_type );
+ $post = get_default_post_to_edit( $post_type, true );
+ $post_ID = $post->ID;
include('edit-form-advanced.php');
}
diff --git a/wp-includes/js/autosave.dev.js b/wp-includes/js/autosave.dev.js
index 7109d5403..9ff7234b1 100644
--- a/wp-includes/js/autosave.dev.js
+++ b/wp-includes/js/autosave.dev.js
@@ -39,7 +39,7 @@ jQuery(document).ready( function($) {
// preview
$('#post-preview').click(function(){
- if ( 1 > $('#post_ID').val() && notSaved ) {
+ if ( $('#auto_draft').val() == '1' && notSaved ) {
autosaveDelayPreview = true;
autosave();
return false;
@@ -58,7 +58,7 @@ jQuery(document).ready( function($) {
if ( typeof tinyMCE != 'undefined' ) {
$('#title')[$.browser.opera ? 'keypress' : 'keydown'](function (e) {
if ( e.which == 9 && !e.shiftKey && !e.controlKey && !e.altKey ) {
- if ( ($("#post_ID").val() < 1) && ($("#title").val().length > 0) ) { autosave(); }
+ if ( ($('#auto_draft').val() == '1') && ($("#title").val().length > 0) ) { autosave(); }
if ( tinyMCE.activeEditor && ! tinyMCE.activeEditor.isHidden() && dotabkey ) {
e.preventDefault();
dotabkey = false;
@@ -70,11 +70,10 @@ jQuery(document).ready( function($) {
}
// autosave new posts after a title is typed but not if Publish or Save Draft is clicked
- if ( 0 > $('#post_ID').val() ) {
+ if ( '1' == $('#auto_draft').val() ) {
$('#title').blur( function() {
- if ( !this.value || 0 < $('#post_ID').val() )
+ if ( !this.value || $('#auto_draft').val() != '1' )
return;
-
delayed_autosave();
});
}
@@ -121,24 +120,19 @@ function autosave_parse_response(response) {
// called when autosaving pre-existing post
function autosave_saved(response) {
+ blockSave = false;
autosave_parse_response(response); // parse the ajax response
autosave_enable_buttons(); // re-enable disabled form buttons
}
// called when autosaving new post
function autosave_saved_new(response) {
+ blockSave = false;
var res = autosave_parse_response(response), tempID, postID;
- // if no errors: update post_ID from the temporary value, grab new save-nonce for that new ID
if ( res && res.responses.length && !res.errors ) {
- tempID = jQuery('#post_ID').val();
+ // An ID is sent only for real auto-saves, not for autosave=0 "keepalive" saves
postID = parseInt( res.responses[0].id, 10 );
autosave_update_post_ID( postID ); // disabled form buttons are re-enabled here
- if ( tempID < 0 && postID > 0 ) { // update media buttons
- notSaved = false;
- jQuery('#media-buttons a').each(function(){
- this.href = this.href.replace(tempID, postID);
- });
- }
if ( autosaveDelayPreview ) {
autosaveDelayPreview = false;
doPreview();
@@ -151,22 +145,11 @@ function autosave_saved_new(response) {
function autosave_update_post_ID( postID ) {
if ( !isNaN(postID) && postID > 0 ) {
if ( postID == parseInt(jQuery('#post_ID').val(), 10) ) { return; } // no need to do this more than once
- jQuery('#post_ID').attr({name: "post_ID"});
- jQuery('#post_ID').val(postID);
- // We need new nonces
- jQuery.post(autosaveL10n.requestFile, {
- action: "autosave-generate-nonces",
- post_ID: postID,
- autosavenonce: jQuery('#autosavenonce').val(),
- post_type: jQuery('#post_type').val()
- }, function(html) {
- jQuery('#_wpnonce').val(html.updateNonce);
- jQuery('#delete-action a.submitdelete').attr('href', html.deleteURL);
- autosave_enable_buttons(); // re-enable disabled form buttons
- jQuery('#delete-action a.submitdelete').fadeIn();
- },
- 'json');
+ notSaved = false;
+ autosave_enable_buttons();
+ jQuery('#delete-action a.submitdelete').fadeIn();
jQuery('#hiddenaction').val('editpost');
+ jQuery('#auto_draft').val('0'); // No longer an auto-draft
}
}
@@ -217,6 +200,7 @@ function delayed_autosave() {
autosave = function() {
// (bool) is rich editor enabled and active
+ blockSave = true;
var rich = (typeof tinyMCE != "undefined") && tinyMCE.activeEditor && !tinyMCE.activeEditor.isHidden(), post_data, doAutoSave, ed, origStatus, successCallback;
autosave_disable_buttons();
@@ -281,6 +265,8 @@ autosave = function() {
if ( jQuery("#post_author").size() )
post_data["post_author"] = jQuery("#post_author").val();
post_data["user_ID"] = jQuery("#user-id").val();
+ if ( jQuery('#auto_draft').val() == '1' )
+ post_data["auto_draft"] = '1';
if ( doAutoSave ) {
autosaveLast = jQuery("#title").val()+jQuery("#content").val();
@@ -288,15 +274,13 @@ autosave = function() {
post_data['autosave'] = 0;
}
- if ( parseInt(post_data["post_ID"], 10) < 1 ) {
- post_data["temp_ID"] = post_data["post_ID"];
+ if ( post_data["auto_draft"] == '1' ) {
successCallback = autosave_saved_new; // new post
} else {
successCallback = autosave_saved; // pre-existing post
}
autosaveOldMessage = jQuery('#autosave').html();
-
jQuery.ajax({
data: post_data,
beforeSend: doAutoSave ? autosave_loading : null,
diff --git a/wp-includes/js/autosave.js b/wp-includes/js/autosave.js
index 1c0561303..9d5a883be 100644
--- a/wp-includes/js/autosave.js
+++ b/wp-includes/js/autosave.js
@@ -1 +1 @@
-var autosave,autosaveLast="",autosavePeriodical,autosaveOldMessage="",autosaveDelayPreview=false,notSaved=true,blockSave=false,interimLogin=false;jQuery(document).ready(function(b){var a=true;autosaveLast=b("#post #title").val()+b("#post #content").val();autosavePeriodical=b.schedule({time:autosaveL10n.autosaveInterval*1000,func:function(){autosave()},repeat:true,protect:true});b("#post").submit(function(){b.cancel(autosavePeriodical)});b('input[type="submit"], a.submitdelete',"#submitpost").click(function(){blockSave=true;window.onbeforeunload=null;b(":button, :submit","#submitpost").each(function(){var c=b(this);if(c.hasClass("button-primary")){c.addClass("button-primary-disabled")}else{c.addClass("button-disabled")}});b("#ajax-loading").css("visibility","visible")});window.onbeforeunload=function(){var c=typeof(tinyMCE)!="undefined"?tinyMCE.activeEditor:false,e,d;if(c&&!c.isHidden()){if(c.isDirty()){return autosaveL10n.saveAlert}}else{e=b("#post #title").val(),d=b("#post #content").val();if((e||d)&&e+d!=autosaveLast){return autosaveL10n.saveAlert}}};b("#post-preview").click(function(){if(1>b("#post_ID").val()&¬Saved){autosaveDelayPreview=true;autosave();return false}doPreview();return false});doPreview=function(){b("input#wp-preview").val("dopreview");b("form#post").attr("target","wp-preview").submit().attr("target","");b("input#wp-preview").val("")};if(typeof tinyMCE!="undefined"){b("#title")[b.browser.opera?"keypress":"keydown"](function(c){if(c.which==9&&!c.shiftKey&&!c.controlKey&&!c.altKey){if((b("#post_ID").val()<1)&&(b("#title").val().length>0)){autosave()}if(tinyMCE.activeEditor&&!tinyMCE.activeEditor.isHidden()&&a){c.preventDefault();a=false;tinyMCE.activeEditor.focus();return false}}})}if(0>b("#post_ID").val()){b("#title").blur(function(){if(!this.value||0 0){autosave_update_slug(a)}}}if(f){jQuery("#autosave").html(f)}else{if(autosaveOldMessage&&e){jQuery("#autosave").html(autosaveOldMessage)}}return e}function autosave_saved(a){autosave_parse_response(a);autosave_enable_buttons()}function autosave_saved_new(b){var d=autosave_parse_response(b),c,a;if(d&&d.responses.length&&!d.errors){c=jQuery("#post_ID").val();a=parseInt(d.responses[0].id,10);autosave_update_post_ID(a);if(c<0&&a>0){notSaved=false;jQuery("#media-buttons a").each(function(){this.href=this.href.replace(c,a)})}if(autosaveDelayPreview){autosaveDelayPreview=false;doPreview()}}else{autosave_enable_buttons()}}function autosave_update_post_ID(a){if(!isNaN(a)&&a>0){if(a==parseInt(jQuery("#post_ID").val(),10)){return}jQuery("#post_ID").attr({name:"post_ID"});jQuery("#post_ID").val(a);jQuery.post(autosaveL10n.requestFile,{action:"autosave-generate-nonces",post_ID:a,autosavenonce:jQuery("#autosavenonce").val(),post_type:jQuery("#post_type").val()},function(b){jQuery("#_wpnonce").val(b.updateNonce);jQuery("#delete-action a.submitdelete").attr("href",b.deleteURL);autosave_enable_buttons();jQuery("#delete-action a.submitdelete").fadeIn()},"json");jQuery("#hiddenaction").val("editpost")}}function autosave_update_slug(a){if("undefined"!=makeSlugeditClickable&&jQuery.isFunction(makeSlugeditClickable)&&!jQuery("#edit-slug-box > *").size()){jQuery.post(ajaxurl,{action:"sample-permalink",post_id:a,new_title:jQuery("#title").val(),samplepermalinknonce:jQuery("#samplepermalinknonce").val()},function(b){jQuery("#edit-slug-box").html(b);makeSlugeditClickable()})}}function autosave_loading(){jQuery("#autosave").html(autosaveL10n.savingText)}function autosave_enable_buttons(){setTimeout(function(){jQuery(":button, :submit","#submitpost").removeAttr("disabled");jQuery("#ajax-loading").css("visibility","hidden")},500)}function autosave_disable_buttons(){jQuery(":button, :submit","#submitpost").attr("disabled","disabled");setTimeout(autosave_enable_buttons,5000)}function delayed_autosave(){setTimeout(function(){if(blockSave){return}autosave()},200)}autosave=function(){var c=(typeof tinyMCE!="undefined")&&tinyMCE.activeEditor&&!tinyMCE.activeEditor.isHidden(),d,f,b,e,a;autosave_disable_buttons();d={action:"autosave",post_ID:jQuery("#post_ID").val()||0,post_title:jQuery("#title").val()||"",autosavenonce:jQuery("#autosavenonce").val(),post_type:jQuery("#post_type").val()||"",autosave:1};jQuery(".tags-input").each(function(){d[this.name]=this.value});f=true;if(jQuery("#TB_window").css("display")=="block"){f=false}if(c&&f){b=tinyMCE.activeEditor;if(b.plugins.spellchecker&&b.plugins.spellchecker.active){f=false}else{if("mce_fullscreen"==b.id){tinyMCE.get("content").setContent(b.getContent({format:"raw"}),{format:"raw"})}tinyMCE.get("content").save()}}d.content=jQuery("#content").val();if(jQuery("#post_name").val()){d.post_name=jQuery("#post_name").val()}if((d.post_title.length==0&&d.content.length==0)||d.post_title+d.content==autosaveLast){f=false}e=jQuery("#original_post_status").val();goodcats=([]);jQuery("[name='post_category[]']:checked").each(function(g){goodcats.push(this.value)});d.catslist=goodcats.join(",");if(jQuery("#comment_status").attr("checked")){d.comment_status="open"}if(jQuery("#ping_status").attr("checked")){d.ping_status="open"}if(jQuery("#excerpt").size()){d.excerpt=jQuery("#excerpt").val()}if(jQuery("#post_author").size()){d.post_author=jQuery("#post_author").val()}d.user_ID=jQuery("#user-id").val();if(f){autosaveLast=jQuery("#title").val()+jQuery("#content").val()}else{d.autosave=0}if(parseInt(d.post_ID,10)<1){d.temp_ID=d.post_ID;a=autosave_saved_new}else{a=autosave_saved}autosaveOldMessage=jQuery("#autosave").html();jQuery.ajax({data:d,beforeSend:f?autosave_loading:null,type:"POST",url:autosaveL10n.requestFile,success:a})};
\ No newline at end of file
+var autosave,autosaveLast="",autosavePeriodical,autosaveOldMessage="",autosaveDelayPreview=false,notSaved=true,blockSave=false,interimLogin=false;jQuery(document).ready(function($){var dotabkey=true;autosaveLast=$("#post #title").val()+$("#post #content").val();autosavePeriodical=$.schedule({time:autosaveL10n.autosaveInterval*1000,func:function(){autosave()},repeat:true,protect:true});$("#post").submit(function(){$.cancel(autosavePeriodical)});$('input[type="submit"], a.submitdelete',"#submitpost").click(function(){blockSave=true;window.onbeforeunload=null;$(":button, :submit","#submitpost").each(function(){var t=$(this);if(t.hasClass("button-primary")){t.addClass("button-primary-disabled")}else{t.addClass("button-disabled")}});$("#ajax-loading").css("visibility","visible")});window.onbeforeunload=function(){var mce=typeof(tinyMCE)!="undefined"?tinyMCE.activeEditor:false,title,content;if(mce&&!mce.isHidden()){if(mce.isDirty()){return autosaveL10n.saveAlert}}else{title=$("#post #title").val(),content=$("#post #content").val();if((title||content)&&title+content!=autosaveLast){return autosaveL10n.saveAlert}}};$("#post-preview").click(function(){if($("#auto_draft").val()=="1"&¬Saved){autosaveDelayPreview=true;autosave();return false}doPreview();return false});doPreview=function(){$("input#wp-preview").val("dopreview");$("form#post").attr("target","wp-preview").submit().attr("target","");$("input#wp-preview").val("")};if(typeof tinyMCE!="undefined"){$("#title")[$.browser.opera?"keypress":"keydown"](function(e){if(e.which==9&&!e.shiftKey&&!e.controlKey&&!e.altKey){if(($("#auto_draft").val()=="1")&&($("#title").val().length>0)){autosave()}if(tinyMCE.activeEditor&&!tinyMCE.activeEditor.isHidden()&&dotabkey){e.preventDefault();dotabkey=false;tinyMCE.activeEditor.focus();return false}}})}if("1"==$("#auto_draft").val()){$("#title").blur(function(){if(!this.value||$("#auto_draft").val()!="1"){return}delayed_autosave()})}});function autosave_parse_response(response){var res=wpAjax.parseAjaxResponse(response,"autosave"),message="",postID,sup,url;if(res&&res.responses&&res.responses.length){message=res.responses[0].data;if(res.responses[0].supplemental){sup=res.responses[0].supplemental;if("disable"==sup.disable_autosave){autosave=function(){};res={errors:true}}if(sup.session_expired&&(url=sup.session_expired)){if(!interimLogin||interimLogin.closed){interimLogin=window.open(url,"login","width=600,height=450,resizable=yes,scrollbars=yes,status=yes");interimLogin.focus()}delete sup.session_expired}jQuery.each(sup,function(selector,value){if(selector.match(/^replace-/)){jQuery("#"+selector.replace("replace-","")).val(value)}})}if(!res.errors){postID=parseInt(res.responses[0].id,10);if(!isNaN(postID)&&postID>0){autosave_update_slug(postID)}}}if(message){jQuery("#autosave").html(message)}else{if(autosaveOldMessage&&res){jQuery("#autosave").html(autosaveOldMessage)}}return res}function autosave_saved(response){blockSave=false;autosave_parse_response(response);autosave_enable_buttons()}function autosave_saved_new(response){blockSave=false;var res=autosave_parse_response(response),tempID,postID;if(res&&res.responses.length&&!res.errors){postID=parseInt(res.responses[0].id,10);autosave_update_post_ID(postID);if(autosaveDelayPreview){autosaveDelayPreview=false;doPreview()}}else{autosave_enable_buttons()}}function autosave_update_post_ID(postID){if(!isNaN(postID)&&postID>0){if(postID==parseInt(jQuery("#post_ID").val(),10)){return}notSaved=false;autosave_enable_buttons();jQuery("#delete-action a.submitdelete").fadeIn();jQuery("#hiddenaction").val("editpost");jQuery("#auto_draft").val("0")}}function autosave_update_slug(post_id){if("undefined"!=makeSlugeditClickable&&jQuery.isFunction(makeSlugeditClickable)&&!jQuery("#edit-slug-box > *").size()){jQuery.post(ajaxurl,{action:"sample-permalink",post_id:post_id,new_title:jQuery("#title").val(),samplepermalinknonce:jQuery("#samplepermalinknonce").val()},function(data){jQuery("#edit-slug-box").html(data);makeSlugeditClickable()})}}function autosave_loading(){jQuery("#autosave").html(autosaveL10n.savingText)}function autosave_enable_buttons(){setTimeout(function(){jQuery(":button, :submit","#submitpost").removeAttr("disabled");jQuery("#ajax-loading").css("visibility","hidden")},500)}function autosave_disable_buttons(){jQuery(":button, :submit","#submitpost").attr("disabled","disabled");setTimeout(autosave_enable_buttons,5000)}function delayed_autosave(){setTimeout(function(){if(blockSave){return}autosave()},200)}autosave=function(){blockSave=true;var rich=(typeof tinyMCE!="undefined")&&tinyMCE.activeEditor&&!tinyMCE.activeEditor.isHidden(),post_data,doAutoSave,ed,origStatus,successCallback;autosave_disable_buttons();post_data={action:"autosave",post_ID:jQuery("#post_ID").val()||0,post_title:jQuery("#title").val()||"",autosavenonce:jQuery("#autosavenonce").val(),post_type:jQuery("#post_type").val()||"",autosave:1};jQuery(".tags-input").each(function(){post_data[this.name]=this.value});doAutoSave=true;if(jQuery("#TB_window").css("display")=="block"){doAutoSave=false}if(rich&&doAutoSave){ed=tinyMCE.activeEditor;if(ed.plugins.spellchecker&&ed.plugins.spellchecker.active){doAutoSave=false}else{if("mce_fullscreen"==ed.id){tinyMCE.get("content").setContent(ed.getContent({format:"raw"}),{format:"raw"})}tinyMCE.get("content").save()}}post_data.content=jQuery("#content").val();if(jQuery("#post_name").val()){post_data.post_name=jQuery("#post_name").val()}if((post_data.post_title.length==0&&post_data.content.length==0)||post_data.post_title+post_data.content==autosaveLast){doAutoSave=false}origStatus=jQuery("#original_post_status").val();goodcats=([]);jQuery("[name='post_category[]']:checked").each(function(i){goodcats.push(this.value)});post_data.catslist=goodcats.join(",");if(jQuery("#comment_status").attr("checked")){post_data.comment_status="open"}if(jQuery("#ping_status").attr("checked")){post_data.ping_status="open"}if(jQuery("#excerpt").size()){post_data.excerpt=jQuery("#excerpt").val()}if(jQuery("#post_author").size()){post_data.post_author=jQuery("#post_author").val()}post_data.user_ID=jQuery("#user-id").val();if(jQuery("#auto_draft").val()=="1"){post_data.auto_draft="1"}if(doAutoSave){autosaveLast=jQuery("#title").val()+jQuery("#content").val()}else{post_data.autosave=0}if(post_data.auto_draft=="1"){successCallback=autosave_saved_new}else{successCallback=autosave_saved}autosaveOldMessage=jQuery("#autosave").html();jQuery.ajax({data:post_data,beforeSend:doAutoSave?autosave_loading:null,type:"POST",url:autosaveL10n.requestFile,success:successCallback})};
\ No newline at end of file
diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php
index f64c6ccf4..0e9232c8b 100644
--- a/wp-includes/link-template.php
+++ b/wp-includes/link-template.php
@@ -111,7 +111,7 @@ function get_permalink($id = 0, $leavename = false) {
$permalink = get_option('permalink_structure');
- if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending')) ) {
+ if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) {
$unixtime = strtotime($post->post_date);
$category = '';
diff --git a/wp-includes/post.php b/wp-includes/post.php
index 2437703ae..df1dd591e 100644
--- a/wp-includes/post.php
+++ b/wp-includes/post.php
@@ -1976,7 +1976,7 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
// Create a valid post name. Drafts and pending posts are allowed to have an empty
// post name.
if ( !isset($post_name) || empty($post_name) ) {
- if ( !in_array( $post_status, array( 'draft', 'pending' ) ) )
+ if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) )
$post_name = sanitize_title($post_title);
else
$post_name = '';
@@ -1989,7 +1989,7 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
$post_date = current_time('mysql');
if ( empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt ) {
- if ( !in_array( $post_status, array( 'draft', 'pending' ) ) )
+ if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) )
$post_date_gmt = get_gmt_from_date($post_date);
else
$post_date_gmt = '0000-00-00 00:00:00';
@@ -2089,7 +2089,7 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
$where = array( 'ID' => $post_ID );
}
- if ( empty($data['post_name']) && !in_array( $data['post_status'], array( 'draft', 'pending' ) ) ) {
+ if ( empty($data['post_name']) && !in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) {
$data['post_name'] = sanitize_title($data['post_title'], $post_ID);
$wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where );
}
@@ -2172,7 +2172,7 @@ function wp_update_post($postarr = array()) {
$post_cats = $post['post_category'];
// Drafts shouldn't be assigned a date unless explicitly done so by the user
- if ( in_array($post['post_status'], array('draft', 'pending')) && empty($postarr['edit_date']) &&
+ if ( in_array($post['post_status'], array('draft', 'pending', 'auto-draft')) && empty($postarr['edit_date']) &&
('0000-00-00 00:00:00' == $post['post_date_gmt']) )
$clear_date = true;
else
@@ -2276,7 +2276,7 @@ function check_and_publish_future_post($post_id) {
* @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix)
*/
function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent) {
- if ( in_array( $post_status, array( 'draft', 'pending' ) ) )
+ if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) )
return $slug;
global $wpdb, $wp_rewrite;
diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php
index 77cbdab4c..58eeb96e5 100644
--- a/wp-includes/script-loader.php
+++ b/wp-includes/script-loader.php
@@ -99,7 +99,7 @@ function wp_default_scripts( &$scripts ) {
'l10n_print_after' => 'try{convertEntities(wpAjax);}catch(e){};'
) );
- $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response'), '20091012' );
+ $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response'), '20100205' );
$scripts->add_data( 'autosave', 'group', 1 );
$scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array('wp-ajax-response'), '20091128' );
|