Skip to content

Commit

Permalink
Posts, Post Types: Improve the docs for wp_check_post_lock() and `w…
Browse files Browse the repository at this point in the history
…p_set_post_lock()`.

See #39888.
Built from https://develop.svn.wordpress.org/trunk@40423


git-svn-id: http://core.svn.wordpress.org/trunk@40321 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
SergeyBiryukov committed Apr 13, 2017
1 parent 902b914 commit bef3ff1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
29 changes: 19 additions & 10 deletions wp-admin/includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -1448,15 +1448,18 @@ function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
*
* @since 2.5.0
*
* @param int $post_id ID of the post to check for editing
* @return integer False: not locked or locked by current user. Int: user ID of user with lock.
* @param int $post_id ID of the post to check for editing.
* @return int|false ID of the user with lock. False if the post does not exist, post is not locked,
* or post is locked by current user.
*/
function wp_check_post_lock( $post_id ) {
if ( !$post = get_post( $post_id ) )
if ( ! $post = get_post( $post_id ) ) {
return false;
}

if ( !$lock = get_post_meta( $post->ID, '_edit_lock', true ) )
if ( ! $lock = get_post_meta( $post->ID, '_edit_lock', true ) ) {
return false;
}

$lock = explode( ':', $lock );
$time = $lock[0];
Expand All @@ -1465,8 +1468,10 @@ function wp_check_post_lock( $post_id ) {
/** This filter is documented in wp-admin/includes/ajax-actions.php */
$time_window = apply_filters( 'wp_check_post_lock_window', 150 );

if ( $time && $time > time() - $time_window && $user != get_current_user_id() )
if ( $time && $time > time() - $time_window && $user != get_current_user_id() ) {
return $user;
}

return false;
}

Expand All @@ -1475,20 +1480,24 @@ function wp_check_post_lock( $post_id ) {
*
* @since 2.5.0
*
* @param int $post_id ID of the post to being edited
* @return bool|array Returns false if the post doesn't exist of there is no current user, or
* an array of the lock time and the user ID.
* @param int $post_id ID of the post being edited.
* @return array|false Array of the lock time and user ID. False if the post does not exist or there
* is no current user.
*/
function wp_set_post_lock( $post_id ) {
if ( !$post = get_post( $post_id ) )
if ( ! $post = get_post( $post_id ) ) {
return false;
if ( 0 == ($user_id = get_current_user_id()) )
}

if ( 0 == ( $user_id = get_current_user_id() ) ) {
return false;
}

$now = time();
$lock = "$now:$user_id";

update_post_meta( $post->ID, '_edit_lock', $lock );

return array( $now, $user_id );
}

Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.8-alpha-40422';
$wp_version = '4.8-alpha-40423';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit bef3ff1

Please sign in to comment.