wp_refresh_post_lock

Check lock status on the New/Edit Post screen and refresh the lock.

Description

(array) wp_refresh_post_lock( (array) $response, (array) $data, (string) $screen_id ); 

Returns (array)

The Heartbeat response.

Parameters (3)

0. $response (array)
The Heartbeat response.
1. $data (array)
The $_POST data sent.
2. $screen_id (string)
The screen id.

Usage

  1. if ( !function_exists( 'wp_refresh_post_lock' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/misc.php'; 
  3.  
  4. // The Heartbeat response. 
  5. $response = array(); 
  6.  
  7. // The $_POST data sent. 
  8. $data = array(); 
  9.  
  10. // The screen id. 
  11. $screen_id = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wp_refresh_post_lock($response, $data, $screen_id); 
  15.  

Defined (1)

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

/wp-admin/includes/misc.php  
  1. function wp_refresh_post_lock( $response, $data, $screen_id ) { 
  2. if ( array_key_exists( 'wp-refresh-post-lock', $data ) ) { 
  3. $received = $data['wp-refresh-post-lock']; 
  4. $send = array(); 
  5.  
  6. if ( ! $post_id = absint( $received['post_id'] ) ) 
  7. return $response; 
  8.  
  9. if ( ! current_user_can('edit_post', $post_id) ) 
  10. return $response; 
  11.  
  12. if ( ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) ) { 
  13. $error = array( 
  14. 'text' => sprintf( __( '%s has taken over and is currently editing.' ), $user->display_name ) 
  15. ); 
  16.  
  17. if ( $avatar = get_avatar( $user->ID, 64 ) ) { 
  18. if ( preg_match( "|src='([^']+)'|", $avatar, $matches ) ) 
  19. $error['avatar_src'] = $matches[1]; 
  20.  
  21. $send['lock_error'] = $error; 
  22. } else { 
  23. if ( $new_lock = wp_set_post_lock( $post_id ) ) 
  24. $send['new_lock'] = implode( ':', $new_lock ); 
  25.  
  26. $response['wp-refresh-post-lock'] = $send; 
  27.  
  28. return $response;