wp_check_post_lock()
Determines whether the post is currently being edited by another user.
Hooks from the function
Return
Int|false
. ID of the user with lock. False if the post does not exist, post is not locked, the user with lock does not exist, or the post is locked by current user.
Usage
wp_check_post_lock( $post );
- $post(int|WP_Post) (required)
- ID or object of the post to check for editing.
Changelog
Since 2.5.0 | Introduced. |
wp_check_post_lock() wp check post lock code WP 6.5.2
function wp_check_post_lock( $post ) { $post = get_post( $post ); if ( ! $post ) { return false; } $lock = get_post_meta( $post->ID, '_edit_lock', true ); if ( ! $lock ) { return false; } $lock = explode( ':', $lock ); $time = $lock[0]; $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); if ( ! get_userdata( $user ) ) { return false; } /** 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 && get_current_user_id() != $user ) { return $user; } return false; }