WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/12/2013 03:22:30 AM (7 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/misc.php

    r23584 r23661  
    587587}
    588588add_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 */
     595function 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}
     629add_filter( 'heartbeat_received', 'wp_refresh_post_lock', 10, 3 );
Note: See TracChangeset for help on using the changeset viewer.