Posts, Post Types: Improve the docs for `wp_check_post_lock()` and `wp_set_post_lock()`.

See #39888.

git-svn-id: https://develop.svn.wordpress.org/trunk@40423 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2017-04-13 23:01:20 +00:00
parent a844db32e2
commit 1fd9d6026d
1 changed files with 19 additions and 10 deletions

View File

@ -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];
@ -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;
}
@ -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 );
}