Posts, Post Types: Improve the docs for wp_check_post_lock() and wp_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
This commit is contained in:
Sergey Biryukov 2017-04-13 23:02:42 +00:00
parent 902b91400d
commit bef3ff1377
2 changed files with 20 additions and 11 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 );
}

View File

@ -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.