From 5504c11b58f8da629711016fda4b430ccda98a0a Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 3 Mar 2008 20:58:06 +0000 Subject: [PATCH] Only show "saved at" when the post was actually saved. Props mdawaffe. fixes #6053 git-svn-id: http://svn.automattic.com/wordpress/trunk@7138 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-ajax.php | 13 +++++++++---- wp-includes/js/autosave.js | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index ec9c3e316c..8644ae3aca 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -483,15 +483,18 @@ case 'autosave' : // The name of this action is hardcoded in edit_post() $do_autosave = (bool) $_POST['autosave']; $do_lock = true; - $data = '

' . sprintf( __('Saved at %s.'), date( __('g:i:s a'), current_time( 'timestamp', true ) ) ) . '

'; + $data = ''; + $message = '

' . sprintf( __('Saved at %s.'), date( __('g:i:s a'), current_time( 'timestamp', true ) ) ) . '

'; $supplemental = array(); $id = 0; if($_POST['post_ID'] < 0) { $_POST['temp_ID'] = $_POST['post_ID']; - if ( $do_autosave ) + if ( $do_autosave ) { $id = wp_write_post(); + $data = $message; + } } else { $post_ID = (int) $_POST['post_ID']; $_POST['ID'] = $post_ID; @@ -517,10 +520,12 @@ case 'autosave' : // The name of this action is hardcoded in edit_post() if ( !current_user_can('edit_post', $post_ID) ) die(__('You are not allowed to edit this post.')); } - if ( $do_autosave ) + if ( $do_autosave ) { $id = wp_update_post($_POST); - else + $data = $message; + } else { $id = $post->ID; + } } if ( $do_lock && $id && is_numeric($id) ) diff --git a/wp-includes/js/autosave.js b/wp-includes/js/autosave.js index 26fdb58034..891914e940 100644 --- a/wp-includes/js/autosave.js +++ b/wp-includes/js/autosave.js @@ -17,6 +17,7 @@ jQuery(function($) { // called when autosaving pre-existing post function autosave_saved(response) { + var oldMessage = jQuery('#autosave').html(); var res = wpAjax.parseAjaxResponse(response, 'autosave'); // parse the ajax response var message = ''; @@ -38,6 +39,7 @@ function autosave_saved(response) { } } if ( message ) { jQuery('#autosave').html(message); } // update autosave message + else if ( oldMessage && res ) { jQuery('#autosave').html( oldMessage ); } autosave_enable_buttons(); // re-enable disabled form buttons return res; }