bp_docs_add_edit_lock_cb

AJAX handler for setting edit lock.

Description

bp_docs_add_edit_lock_cb(); 

Called when a user enters an Edit page.


Usage

  1. if ( !function_exists( 'bp_docs_add_edit_lock_cb' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-docs/includes/edit-lock.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_docs_add_edit_lock_cb(); 
  7.  

Defined (1)

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

/includes/edit-lock.php  
  1. function bp_docs_add_edit_lock_cb() { 
  2. $doc_id = isset( $_POST['doc_id'] ) ? (int) $_POST['doc_id'] : false; 
  3.  
  4. if ( ! $doc_id ) { 
  5. return; 
  6.  
  7. $doc = get_post( $doc_id ); 
  8.  
  9. if ( ! $doc || is_wp_error( $doc ) ) { 
  10. return; 
  11.  
  12. if ( bp_docs_get_post_type_name() !== $doc->post_type ) { 
  13. return; 
  14.  
  15. if ( ! is_user_logged_in() ) { 
  16. return; 
  17.  
  18. // Is this post already locked? 
  19. $lock = bp_docs_check_post_lock( $doc_id ); 
  20. if ( ! empty( $lock ) && $lock != bp_loggedin_user_id() ) { 
  21. die(); 
  22.  
  23. $now = time(); 
  24. $user_id = bp_loggedin_user_id(); 
  25. $lock = "$now:$user_id"; 
  26.  
  27. update_post_meta( $doc_id, '_bp_docs_last_pinged', $lock ); 
  28.  
  29. die( json_encode( '1' ) );