bp_docs_check_post_lock

Check to see if the post is currently being edited by another user.

Description

(bool|int) bp_docs_check_post_lock( (int) $post_id ); 

This is a verbatim copy of wp_check_post_lock(), which is only available in the admin

Returns (bool|int)

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( 'bp_docs_check_post_lock' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-docs/includes/edit-lock.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 = bp_docs_check_post_lock($post_id); 
  9.  

Defined (1)

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

/includes/edit-lock.php  
  1. function bp_docs_check_post_lock( $post_id ) { 
  2. if ( !$post = get_post( $post_id ) ) 
  3. return false; 
  4.  
  5. if ( !$lock = get_post_meta( $post->ID, '_bp_docs_last_pinged', 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. $heartbeat_interval = bp_docs_heartbeat_pulse(); 
  13.  
  14. // Bail out of the lock if four pings have been missed (one minute, by default) 
  15. $time_window = apply_filters( 'bp_docs_post_lock_interval', $heartbeat_interval * 4 ); 
  16.  
  17. if ( $time && $time > time() - $time_window && $user != get_current_user_id() ) { 
  18. return $user; 
  19.  
  20. return false;