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

  1. if ( !function_exists( 'wp_check_post_lock' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/post.php'; 
  3.  
  4. // ID of the post to check for editing 
  5. $post_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_check_post_lock($post_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/post.php  
  1. function wp_check_post_lock( $post_id ) { 
  2. if ( !$post = get_post( $post_id ) ) 
  3. return false; 
  4.  
  5. if ( !$lock = get_post_meta( $post->ID, '_edit_lock', true ) ) 
  6. return false; 
  7.  
  8. $lock = explode( ':', $lock ); 
  9. $time = $lock[0]; 
  10. $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); 
  11.  
  12. /** This filter is documented in wp-admin/includes/ajax-actions.php */ 
  13. $time_window = apply_filters( 'wp_check_post_lock_window', 150 ); 
  14.  
  15. if ( $time && $time > time() - $time_window && $user != get_current_user_id() ) 
  16. return $user; 
  17. return false;