wp_set_post_lock

Mark the post as currently being edited by the current user.

Description

(bool|array) wp_set_post_lock( (int) $post_id ); 

Returns (bool|array)

Returns false if the post doesn't exist of there is no current user, or an array of the lock time and the user ID.

Parameters (1)

0. $post_id (int)
ID of the post to being edited

Usage

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

Defined (1)

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

/wp-admin/includes/post.php  
  1. function wp_set_post_lock( $post_id ) { 
  2. if ( !$post = get_post( $post_id ) ) 
  3. return false; 
  4. if ( 0 == ($user_id = get_current_user_id()) ) 
  5. return false; 
  6.  
  7. $now = time(); 
  8. $lock = "$now:$user_id"; 
  9.  
  10. update_post_meta( $post->ID, '_edit_lock', $lock ); 
  11. return array( $now, $user_id );