wp_check_post_lock
Check to see if the post is currently being edited by another user.
Description
(integer) wp_check_post_lock( (int) $post_id );
Returns (integer)
False: not locked or locked by current user. Int: user ID of user with lock.
Parameters (1)
- 0. $post_id (int)
- ID of the post to check for editing
Usage
if ( !function_exists( 'wp_check_post_lock' ) ) { require_once ABSPATH . '/wp-admin/includes/post.php'; } // ID of the post to check for editing $post_id = -1; // NOTICE! Understand what this does before running. $result = wp_check_post_lock($post_id);
Defined (1)
The function is defined in the following location(s).
- /wp-admin/includes/post.php
- function wp_check_post_lock( $post_id ) {
- if ( !$post = get_post( $post_id ) )
- return false;
- if ( !$lock = get_post_meta( $post->ID, '_edit_lock', true ) )
- return false;
- $lock = explode( ':', $lock );
- $time = $lock[0];
- $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true );
- /** 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() )
- return $user;
- return false;
- }