WordPress.org

Make WordPress Core

Ticket #24572: wp_unset_post_lock.patch

File wp_unset_post_lock.patch, 2.0 KB (added by bbrooks, 5 years ago)

New post unlocking function and refactor of an ajax handler to use new function

  • wp-admin/includes/ajax-actions.php

    Property changes on: .
    ___________________________________________________________________
    Added: svn:ignore
       + wp-config.php
    
    
     
    17571757        if ( $active_lock[1] != get_current_user_id() )
    17581758                wp_die( 0 );
    17591759
    1760         $new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', 120 ) + 5 ) . ':' . $active_lock[1];
    1761         update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) );
    1762         wp_die( 1 );
     1760        $unlock_result = wp_unset_post_lock( $post_id );
     1761
     1762        if( is_array( $unlock_result ) )
     1763                wp_die( 1 );
     1764        else
     1765                wp_die( 0 );
    17631766}
    17641767
    17651768function wp_ajax_dismiss_wp_pointer() {
  • wp-admin/includes/post.php

     
    11861186        return array( $now, $user_id );
    11871187}
    11881188
     1189
    11891190/**
     1191 * Mark the post as no longer being edited by the current user by setting the
     1192 * last lock timestamp to a time in the recent past
     1193 *
     1194 * @since 3.6.0
     1195 *
     1196 * @param int $post_id ID of the post to being edited
     1197 * @return bool|array Returns false if the post doesn't exist of there is no current user, or
     1198 *      an array of the last lock time and the user ID.
     1199 */
     1200function wp_unset_post_lock( $post_id ) {
     1201
     1202        if ( !$post = get_post( $post_id ) )
     1203                return false;
     1204        if ( 0 == ($user_id = get_current_user_id()) )
     1205                return false;
     1206
     1207        // Set post lock time to a time in recent past
     1208        $then = time() - apply_filters( 'wp_check_post_lock_window', 120 ) + 5;
     1209        $removal_lock = "$then:$user_id";
     1210
     1211        update_post_meta( $post->ID, '_edit_lock', $removal_lock );
     1212        return array( $then, $user_id );
     1213}
     1214
     1215/**
    11901216 * Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post.
    11911217 *
    11921218 * @since 2.8.5