Changeset 23661
- Timestamp:
- 03/12/2013 03:22:30 AM (12 years ago)
- Location:
- trunk/wp-admin
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/css/wp-admin.css
r23640 r23661 3408 3408 } 3409 3409 3410 #notification-dialog { 3411 position: fixed; 3412 top: 30%; 3413 left: 50%; 3414 width: 450px; 3415 margin-left: -225px; 3416 background: #fff; 3417 z-index: 1000005; 3418 } 3419 3420 #notification-dialog-background { 3421 position: fixed; 3422 top: 0; 3423 left: 0; 3424 right: 0; 3425 bottom: 0; 3426 background: #000; 3427 opacity: 0.5; 3428 filter: alpha(opacity=50); 3429 z-index: 1000000; 3430 } 3431 3432 #notification-dialog .post-locked-message, 3433 #notification-dialog .post-taken-over { 3434 margin: 25px; 3435 } 3436 3437 #notification-dialog .post-locked-message a.button-primary { 3438 margin: 0 10px; 3439 } 3440 3441 #notification-dialog .post-locked-avatar { 3442 float: left; 3443 margin-right: 20px; 3444 } 3445 3446 #notification-dialog .currently-editing { 3447 margin-bottom: 20px; 3448 } 3449 3410 3450 3411 3451 /*------------------------------------------------------------------------------ -
trunk/wp-admin/includes/ajax-actions.php
r23639 r23661 1058 1058 1059 1059 if ( $last = wp_check_post_lock( $post->ID ) ) { 1060 // This will change after we have per-user autosaves 1060 1061 $do_autosave = $do_lock = false; 1061 1062 … … 1065 1066 1066 1067 $supplemental['disable_autosave'] = 'disable'; 1067 $alert .= sprintf( __( '%s is currently editing this article. If you update it, you will overwrite the changes.' ), esc_html( $last_user_name ) );1068 1068 } 1069 1069 … … 1093 1093 else 1094 1094 $id = $post->ID; 1095 }1096 1097 if ( $do_lock && empty( $_POST['auto_draft'] ) && $id && is_numeric( $id ) ) {1098 $lock_result = wp_set_post_lock( $id );1099 $supplemental['active-post-lock'] = implode( ':', $lock_result );1100 1095 } 1101 1096 … … 1778 1773 wp_die( 0 ); 1779 1774 1780 $new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2) + 5 ) . ':' . $active_lock[1];1775 $new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', 120 ) + 5 ) . ':' . $active_lock[1]; 1781 1776 update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) ); 1782 1777 wp_die( 1 ); -
trunk/wp-admin/includes/misc.php
r23584 r23661 587 587 } 588 588 add_filter( 'heartbeat_received', 'wp_check_locked_posts', 10, 2 ); 589 590 /** 591 * Check lock status on the New/Edit Post screen and refresh the lock 592 * 593 * @since 3.6 594 */ 595 function wp_refresh_post_lock( $response, $data, $screen_id ) { 596 if ( 'post' == $screen_id && array_key_exists( 'wp-refresh-post-lock', $data ) ) { 597 $received = $data['wp-refresh-post-lock']; 598 $send = array(); 599 600 if ( !$post_id = absint( $received['post_id'] ) ) 601 return $response; 602 603 if ( !current_user_can('edit_post', $post_id) ) 604 return $response; 605 606 if ( $user_id = wp_check_post_lock( $post_id ) ) { 607 $user = get_userdata( $user_id ); 608 609 $error = array( 610 'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name ) 611 ); 612 613 if ( $avatar = get_avatar( $user->ID, 64 ) ) { 614 if ( preg_match( "|src='([^']+)'|", $avatar, $matches ) ) 615 $error['avatar_src'] = $matches[1]; 616 } 617 618 $send['lock_error'] = $error; 619 } else { 620 if ( $new_lock = wp_set_post_lock( $post_id ) ) 621 $send['new_lock'] = implode( ':', $new_lock ); 622 } 623 624 $response['wp-refresh-post-lock'] = $send; 625 } 626 627 return $response; 628 } 629 add_filter( 'heartbeat_received', 'wp_refresh_post_lock', 10, 3 ); -
trunk/wp-admin/includes/post.php
r23578 r23661 1163 1163 $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); 1164 1164 1165 $time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2);1165 $time_window = apply_filters( 'wp_check_post_lock_window', 120 ); 1166 1166 1167 1167 if ( $time && $time > time() - $time_window && $user != get_current_user_id() ) … … 1193 1193 1194 1194 /** 1195 * Outputs the notice message to say that someone else is editing this post at the moment.1195 * Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post. 1196 1196 * 1197 1197 * @since 2.8.5 … … 1199 1199 */ 1200 1200 function _admin_notice_post_locked() { 1201 $post = get_post(); 1202 $lock = explode( ':', get_post_meta( $post->ID, '_edit_lock', true ) ); 1203 $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); 1204 $last_user = get_userdata( $user ); 1205 $last_user_name = $last_user ? $last_user->display_name : __('Somebody'); 1206 1207 switch ($post->post_type) { 1208 case 'post': 1209 $message = __( 'Warning: %s is currently editing this post' ); 1210 break; 1211 case 'page': 1212 $message = __( 'Warning: %s is currently editing this page' ); 1213 break; 1214 default: 1215 $message = __( 'Warning: %s is currently editing this.' ); 1216 } 1217 1218 $message = sprintf( $message, esc_html( $last_user_name ) ); 1219 echo "<div class='error'><p>$message</p></div>"; 1201 global $post_ID; 1202 1203 if ( !empty( $post_ID ) && ( $user = wp_check_post_lock( $post_ID ) ) ) { 1204 $user = get_userdata( $user ); 1205 $locked = apply_filters( 'show_post_locked_dialog', true, $post_ID, $user ); 1206 } else { 1207 $locked = false; 1208 } 1209 1210 ?> 1211 <div id="notification-dialog-wrap"<?php if ( ! $locked ) echo ' style="display:none"'; ?>> 1212 <div id="notification-dialog-background"></div> 1213 <div id="notification-dialog"> 1214 <?php 1215 1216 if ( $locked ) { 1217 ?> 1218 <div class="post-locked-message"> 1219 <div class="post-locked-avatar"><?php echo get_avatar( $user->ID, 64 ); ?></div> 1220 <p><?php esc_html_e( sprintf( __( 'This content is currently locked. If you take over, %s will be blocked from continuing to edit.' ), $user->display_name ) ); ?></p> 1221 <p> 1222 <a class="button" href="<?php echo esc_url( wp_get_referer() ); ?>"><?php _e('Go back'); ?></a> 1223 <?php 1224 1225 // Allow plugins to prevent some users taking over 1226 if ( apply_filters( 'post_lock_take_over', true, $post_ID, $user ) ) { 1227 ?> 1228 <a class="button button-primary" href="<?php echo esc_url( add_query_arg( 'get-post-lock', '1', get_edit_post_link( $post_ID, 'url' ) ) ); ?>"><?php _e('Take over'); ?></a> 1229 <?php 1230 } 1231 1232 ?> 1233 </p> 1234 </div> 1235 <?php 1236 } else { 1237 ?> 1238 <div class="post-taken-over"> 1239 <div class="post-locked-avatar"></div> 1240 <p class="currently-editing"></p> 1241 <p><a class="button button-primary" href="<?php echo esc_url( admin_url('edit.php') ); ?>"><?php _e('Go to All Posts'); ?></a></p> 1242 </div> 1243 <?php 1244 } 1245 1246 ?> 1247 </div> 1248 </div> 1249 <?php 1220 1250 } 1221 1251 -
trunk/wp-admin/js/post.js
r23587 r23661 252 252 }; 253 253 254 })(jQuery); 254 $(document).on( 'heartbeat-send.refresh-lock', function( e, data ) { 255 var lock = $('#active_post_lock').val(), post_id = $('#post_ID').val(), send = {}; 256 257 if ( !post_id ) 258 return; 259 260 send['post_id'] = post_id; 261 262 if ( lock ) 263 send['lock'] = lock; 264 265 data['wp-refresh-post-lock'] = send; 266 }); 267 268 $(document).on( 'heartbeat-tick.refresh-lock', function( e, data ) { 269 var received, wrap, avatar; 270 271 if ( data['wp-refresh-post-lock'] ) { 272 received = data['wp-refresh-post-lock']; 273 274 if ( received.lock_error ) { 275 // show "editing taken over" message 276 wrap = $('#notification-dialog-wrap'); 277 278 if ( ! wrap.is(':visible') ) { 279 autosave(); 280 wrap.find('p.currently-editing').text( received.lock_error.text ); 281 282 if ( received.lock_error.avatar_src && /^https?:\/\/[a-z0-9]+?\.gravatar\.com\/avatar/.test( received.lock_error.avatar_src ) ) { 283 avatar = $('<img class="avatar avatar-64 photo" width="64" height="64" />').attr( 'src', received.lock_error.avatar_src.replace(/&/g, '&') ); 284 wrap.find('div.post-locked-avatar').empty().append( avatar ); 285 } 286 287 wrap.show(); 288 } 289 } 290 291 if ( received['new_lock'] ) 292 $('#active_post_lock').val( received['new_lock'].replace(/[^0-9:]+/, '') ); 293 } 294 }); 295 296 }(jQuery)); 255 297 256 298 jQuery(document).ready( function($) { -
trunk/wp-admin/post.php
r23445 r23661 148 148 wp_die( __('You can’t edit this item because it is in the Trash. Please restore it and try again.') ); 149 149 150 if ( !empty( $_GET['get-post-lock'] ) ) { 151 wp_set_post_lock( $post_id ); 152 wp_redirect( get_edit_post_link( $post_id, 'url' ) ); 153 exit(); 154 } 155 150 156 $post_type = $post->post_type; 151 157 if ( 'post' == $post_type ) { … … 166 172 } 167 173 168 if ( $last = wp_check_post_lock( $post->ID ) ) { 169 add_action('admin_notices', '_admin_notice_post_locked' ); 170 } else { 174 if ( ! wp_check_post_lock( $post->ID ) ) { 171 175 $active_post_lock = wp_set_post_lock( $post->ID ); 172 176 … … 174 178 wp_enqueue_script('autosave'); 175 179 } 180 181 add_action( 'admin_footer', '_admin_notice_post_locked' ); 176 182 177 183 $title = $post_type_object->labels->edit_item; … … 217 223 if ( !current_user_can($post_type_object->cap->delete_post, $post_id) ) 218 224 wp_die( __('You are not allowed to move this item to the Trash.') ); 225 226 if ( $user_id = wp_check_post_lock( $post_id ) ) { 227 $user = get_userdata( $user_id ); 228 wp_die( sprintf( __( 'You cannot move this item to the Trash. %s is currently editing.' ), $user->display_name ) ); 229 } 219 230 220 231 if ( ! wp_trash_post($post_id) )
Note: See TracChangeset
for help on using the changeset viewer.