From bef3ff1377a188050fcc099b9ff65ef6fba3516d Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 13 Apr 2017 23:02:42 +0000 Subject: [PATCH] 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 --- wp-admin/includes/post.php | 29 +++++++++++++++++++---------- wp-includes/version.php | 2 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 1054f2b2e0..c9ac04244d 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -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 ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index bd04737afe..86c2feb50d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.