Ticket #18515: 18515.diff
File 18515.diff, 5.7 KB (added by , 12 years ago) |
---|
-
wp-includes/js/autosave.dev.js
1 var autosave, autosaveLast = '', autosavePeriodical, autosaveOldMessage = '', autosaveDelayPreview = false, notSaved = true, blockSave = false, fullscreen ;1 var autosave, autosaveLast = '', autosavePeriodical, autosaveOldMessage = '', autosaveDelayPreview = false, notSaved = true, blockSave = false, fullscreen, autosaveLockRelease = true; 2 2 3 3 jQuery(document).ready( function($) { 4 4 var dotabkey = true; … … 9 9 //Disable autosave after the form has been submitted 10 10 $("#post").submit(function() { 11 11 $.cancel(autosavePeriodical); 12 autosaveLockRelease = false; 12 13 }); 13 14 14 15 $('input[type="submit"], a.submitdelete', '#submitpost').click(function(){ … … 47 48 } 48 49 }; 49 50 51 $(window).unload( function() { 52 if ( ! autosaveLockRelease ) 53 return; 54 $.ajax({ 55 type: 'POST', 56 url: ajaxurl, 57 async: false, 58 data: { 59 action: 'wp-remove-post-lock', 60 _wpnonce: $('#_wpnonce').val(), 61 post_ID: $('#post_ID').val(), 62 active_post_lock: $('#active_post_lock').val() 63 }, 64 }); 65 } ); 66 50 67 // preview 51 68 $('#post-preview').click(function(){ 52 69 if ( $('#auto_draft').val() == '1' && notSaved ) { … … 99 116 sup = res.responses[0].supplemental; 100 117 if ( 'disable' == sup['disable_autosave'] ) { 101 118 autosave = function() {}; 119 autosaveLockRelease = false; 102 120 res = { errors: true }; 103 121 } 104 122 123 if ( sup['active-post-lock'] ) { 124 jQuery('#active_post_lock').val( sup['active-post-lock'] ); 125 } 126 105 127 if ( sup['alert'] ) { 106 128 jQuery('#autosave-alert').remove(); 107 129 jQuery('#titlediv').after('<div id="autosave-alert" class="error below-h2"><p>' + sup['alert'] + '</p></div>'); -
wp-admin/admin-ajax.php
988 988 $id = $post->ID; 989 989 } 990 990 991 if ( $do_lock && empty( $_POST['auto_draft'] ) && $id && is_numeric( $id ) ) 992 wp_set_post_lock( $id ); 991 if ( $do_lock && empty( $_POST['auto_draft'] ) && $id && is_numeric( $id ) ) { 992 $lock_result = wp_set_post_lock( $id ); 993 $supplemental['active-post-lock'] = implode( ':', $lock_result ); 994 } 993 995 994 996 if ( $nonce_age == 2 ) { 995 997 $supplemental['replace-autosavenonce'] = wp_create_nonce('autosave'); … … 1551 1553 echo json_encode( array( 'message' => $message, 'last_edited' => $last_edited ) ); 1552 1554 die(); 1553 1555 break; 1556 case 'wp-remove-post-lock' : 1557 if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) ) 1558 die( '0' ); 1559 $post_id = (int) $_POST['post_ID']; 1560 if ( ! $post = get_post( $post_id ) ) 1561 die( '0' ); 1562 1563 check_ajax_referer( 'update-' . $post->post_type . '_' . $post_id ); 1564 1565 if ( ! current_user_can( 'edit_post', $post_id ) ) 1566 die( '-1' ); 1567 1568 $active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) ); 1569 if ( $active_lock[1] != get_current_user_id() ) 1570 die( '0' ); 1571 1572 $new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 ) + 5 ) . ':' . $active_lock[1]; 1573 update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) ); 1574 die( '1' ); 1575 1554 1576 default : 1555 1577 do_action( 'wp_ajax_' . $_POST['action'] ); 1556 1578 die('0'); -
wp-admin/includes/post.php
1227 1227 $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); 1228 1228 1229 1229 $time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 ); 1230 1231 1230 if ( $time && $time > time() - $time_window && $user != get_current_user_id() ) 1232 1231 return $user; 1233 1232 return false; … … 1239 1238 * @since 2.5.0 1240 1239 * 1241 1240 * @param int $post_id ID of the post to being edited 1242 * @return bool Returns false if the post doesn't exist of there is no current user 1241 * @return bool|array Returns false if the post doesn't exist of there is no current user, or 1242 * an array of the lock time and the user ID. 1243 1243 */ 1244 1244 function wp_set_post_lock( $post_id ) { 1245 1245 if ( !$post = get_post( $post_id ) ) … … 1251 1251 $lock = "$now:$user_id"; 1252 1252 1253 1253 update_post_meta( $post->ID, '_edit_lock', $lock ); 1254 return array( $now, $user_id ); 1254 1255 } 1255 1256 1256 1257 /** -
wp-admin/post.php
174 174 if ( $last = wp_check_post_lock( $post->ID ) ) { 175 175 add_action('admin_notices', '_admin_notice_post_locked' ); 176 176 } else { 177 wp_set_post_lock( $post->ID );177 $active_post_lock = wp_set_post_lock( $post->ID ); 178 178 wp_enqueue_script('autosave'); 179 179 } 180 180 -
wp-admin/edit-form-advanced.php
231 231 <input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr( $post_type ) ?>" /> 232 232 <input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status) ?>" /> 233 233 <input type="hidden" id="referredby" name="referredby" value="<?php echo esc_url(stripslashes(wp_get_referer())); ?>" /> 234 <?php if ( ! empty( $active_post_lock ) ) { ?> 235 <input type="hidden" id="active_post_lock" value="<?php echo esc_attr( implode( ':', $active_post_lock ) ); ?>" /> 234 236 <?php 237 } 235 238 if ( 'draft' != $post->post_status ) 236 239 wp_original_referer_field(true, 'previous'); 237 240