Changeset 7103 for trunk/wp-admin/admin-ajax.php
- Timestamp:
- 02/29/2008 09:51:36 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/admin-ajax.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-ajax.php
r7098 r7103 471 471 case 'autosave' : // The name of this action is hardcoded in edit_post() 472 472 check_ajax_referer( 'autosave', 'autosavenonce' ); 473 global $current_user; 474 473 475 $_POST['post_content'] = $_POST['content']; 474 476 $_POST['post_excerpt'] = $_POST['excerpt']; … … 479 481 unset($_POST['post_category']); 480 482 483 $do_autosave = (bool) $_POST['autosave']; 484 $do_lock = true; 485 486 $data = '<div class="updated"><p>' . sprintf( __('Saved at %s.'), date( __('g:i:s a'), current_time( 'timestamp', true ) ) ) . '</p></div>'; 487 488 $supplemental = array(); 489 490 $id = 0; 481 491 if($_POST['post_ID'] < 0) { 482 492 $_POST['temp_ID'] = $_POST['post_ID']; 483 $id = wp_write_post(); 484 if( is_wp_error($id) ) 485 die($id->get_error_message()); 486 else 487 die("$id"); 493 if ( $do_autosave ) 494 $id = wp_write_post(); 488 495 } else { 489 496 $post_ID = (int) $_POST['post_ID']; 490 497 $_POST['ID'] = $post_ID; 491 498 $post = get_post($post_ID); 499 500 if ( $last = wp_check_post_lock( $post->ID ) ) { 501 $do_autosave = $do_lock = false; 502 503 $last_user = get_userdata( $last ); 504 $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' ); 505 $data = new WP_Error( 'locked', sprintf( 506 $_POST['post_type'] == 'page' ? __( 'Autosave disabled: %s is currently editing this page.' ) : __( 'Autosave disabled: %s is currently editing this post.' ), 507 wp_specialchars( $last_user_name ) 508 ) ); 509 510 $supplemental['disable_autosave'] = 'disable'; 511 } 512 492 513 if ( 'page' == $post->post_type ) { 493 514 if ( !current_user_can('edit_page', $post_ID) ) … … 497 518 die(__('You are not allowed to edit this post.')); 498 519 } 499 wp_update_post($_POST); 500 } 501 die('0'); 502 break; 520 if ( $do_autosave ) 521 $id = wp_update_post($_POST); 522 else 523 $id = $post->ID; 524 } 525 526 if ( $do_lock && $id && is_numeric($id) ) 527 wp_set_post_lock( $id ); 528 529 $x = new WP_Ajax_Response( array( 530 'what' => 'autosave', 531 'id' => $id, 532 'data' => $id ? $data : '', 533 'supplemental' => $supplemental 534 ) ); 535 $x->send(); 536 break; 503 537 case 'autosave-generate-nonces' : 504 538 check_ajax_referer( 'autosave', 'autosavenonce' );
Note: See TracChangeset
for help on using the changeset viewer.