From 12de05107e4c8b006bde6ee8916f34eb476d08da Mon Sep 17 00:00:00 2001 From: donncha Date: Fri, 13 Jun 2008 17:21:00 +0000 Subject: WP Merge with revision 8075 git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1328 7be80a69-a1ef-0310-a953-fb0f7c49ff36 --- wp-admin/admin-ajax.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'wp-admin/admin-ajax.php') diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 663880e..aef321f 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -1,7 +1,7 @@ get_col( "SELECT name FROM $wpdb->terms WHERE name LIKE ('%$s%')" ); + $results = $wpdb->get_col( $wpdb->prepare("SELECT name FROM $wpdb->terms WHERE name LIKE (%s)", '%' . $s . '%') ); echo join( $results, "\n" ); die; } @@ -462,10 +462,11 @@ case 'add-user' : $x->send(); break; case 'autosave' : // The name of this action is hardcoded in edit_post() - $nonce_age = check_ajax_referer( 'autosave', 'autosavenonce'); + define( 'DOING_AUTOSAVE', true ); + + $nonce_age = check_ajax_referer( 'autosave', 'autosavenonce' ); global $current_user; - $_POST['post_status'] = 'draft'; $_POST['post_category'] = explode(",", $_POST['catslist']); $_POST['tags_input'] = explode(",", $_POST['tags_input']); if($_POST['post_type'] == 'page' || empty($_POST['post_category'])) @@ -479,8 +480,9 @@ case 'autosave' : // The name of this action is hardcoded in edit_post() $supplemental = array(); - $id = 0; + $id = $revision_id = 0; if($_POST['post_ID'] < 0) { + $_POST['post_status'] = 'draft'; $_POST['temp_ID'] = $_POST['post_ID']; if ( $do_autosave ) { $id = wp_write_post(); @@ -511,8 +513,18 @@ 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 ) { - $id = edit_post(); + // 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; -- cgit