wp_check_locked_posts

Check lock status for posts displayed on the Posts screen.

Description

(array) wp_check_locked_posts( (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_check_locked_posts' ) ) { 
  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_check_locked_posts($response, $data, $screen_id); 
  15.  

Defined (1)

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

/wp-admin/includes/misc.php  
  1. function wp_check_locked_posts( $response, $data, $screen_id ) { 
  2. $checked = array(); 
  3.  
  4. if ( array_key_exists( 'wp-check-locked-posts', $data ) && is_array( $data['wp-check-locked-posts'] ) ) { 
  5. foreach ( $data['wp-check-locked-posts'] as $key ) { 
  6. if ( ! $post_id = absint( substr( $key, 5 ) ) ) 
  7. continue; 
  8.  
  9. if ( ( $user_id = wp_check_post_lock( $post_id ) ) && ( $user = get_userdata( $user_id ) ) && current_user_can( 'edit_post', $post_id ) ) { 
  10. $send = array( 'text' => sprintf( __( '%s is currently editing' ), $user->display_name ) ); 
  11.  
  12. if ( ( $avatar = get_avatar( $user->ID, 18 ) ) && preg_match( "|src='([^']+)'|", $avatar, $matches ) ) 
  13. $send['avatar_src'] = $matches[1]; 
  14.  
  15. $checked[$key] = $send; 
  16.  
  17. if ( ! empty( $checked ) ) 
  18. $response['wp-check-locked-posts'] = $checked; 
  19.  
  20. return $response;