WordPress.org

Make WordPress Core

Ticket #24572: 24572.patch

File 24572.patch, 3.0 KB (added by ocean90, 8 years ago)

wp_remove_post_lock()

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

     
    17441744function wp_ajax_wp_remove_post_lock() {
    17451745        if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) )
    17461746                wp_die( 0 );
     1747
    17471748        $post_id = (int) $_POST['post_ID'];
    17481749        if ( ! $post = get_post( $post_id ) )
    17491750                wp_die( 0 );
     
    17531754        if ( ! current_user_can( 'edit_post', $post_id ) )
    17541755                wp_die( -1 );
    17551756
    1756         $active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) );
    1757         if ( $active_lock[1] != get_current_user_id() )
     1757        if ( ! wp_remove_post_lock( $post_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 ) );
    17621760        wp_die( 1 );
    17631761}
    17641762
  • wp-admin/includes/post.php

     
    11761176}
    11771177
    11781178/**
    1179  * Mark the post as currently being edited by the current user
     1179 * Mark the post as currently being edited by the current user.
    11801180 *
    11811181 * @since 2.5.0
    11821182 *
     
    11851185 *      an array of the lock time and the user ID.
    11861186 */
    11871187function wp_set_post_lock( $post_id ) {
    1188         if ( !$post = get_post( $post_id ) )
     1188        if ( ! $post = get_post( $post_id ) )
    11891189                return false;
    1190         if ( 0 == ($user_id = get_current_user_id()) )
     1190
     1191        if ( 0 == ( $user_id = get_current_user_id() ) )
    11911192                return false;
    11921193
    11931194        $now = time();
    11941195        $lock = "$now:$user_id";
    11951196
    11961197        update_post_meta( $post->ID, '_edit_lock', $lock );
     1198
    11971199        return array( $now, $user_id );
    11981200}
    11991201
    12001202/**
     1203 * Mark the post as no longer being edited by the current user by setting the
     1204 * last lock timestamp to a time in the recent past.
     1205 *
     1206 * @since 3.6.0
     1207 *
     1208 * @param int $post_id ID of the post to being edited
     1209 * @return bool|array Returns false if the post doesn't exist of there is no current user, or
     1210 *      an array of the last lock time and the user ID.
     1211 */
     1212function wp_remove_post_lock( $post_id ) {
     1213        if ( ! $post = get_post( $post_id ) )
     1214                return false;
     1215
     1216        if ( 0 == ( $user_id = get_current_user_id() ) )
     1217                return false;
     1218
     1219        // Set post lock time to a time in recent past
     1220        $then = time() - apply_filters( 'wp_check_post_lock_window', 120 ) + 5;
     1221        $removal_lock = "$then:$user_id";
     1222
     1223        update_post_meta( $post->ID, '_edit_lock', $removal_lock );
     1224
     1225        return array( $then, $user_id );
     1226}
     1227
     1228/**
    12011229 * Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post.
    12021230 *
    12031231 * @since 2.8.5
     
    12131241                $locked = false;
    12141242        }
    12151243
    1216         if ( $locked && ( $sendback = wp_get_referer() ) && 
     1244        if ( $locked && ( $sendback = wp_get_referer() ) &&
    12171245                false === strpos( $sendback, 'post.php' ) && false === strpos( $sendback, 'post-new.php' ) ) {
    12181246
    12191247                $sendback_text = __('Go back');