Make WordPress Core


Ignore:
Timestamp:
03/12/2013 03:22:30 AM (12 years ago)
Author:
azaozz
Message:

Check post locks with heartbeat and display modal notifications when a post is locked or a user takes over editing, props dh-shredder, see #23697

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/post.php

    r23578 r23661  
    11631163    $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true );
    11641164
    1165     $time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 );
     1165    $time_window = apply_filters( 'wp_check_post_lock_window', 120 );
    11661166
    11671167    if ( $time && $time > time() - $time_window && $user != get_current_user_id() )
     
    11931193
    11941194/**
    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.
    11961196 *
    11971197 * @since 2.8.5
     
    11991199 */
    12001200function _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
    12201250}
    12211251
Note: See TracChangeset for help on using the changeset viewer.