Post locks: use heartbeat to dynamically update locked posts on the Posts screen, first run, see #23312

git-svn-id: https://develop.svn.wordpress.org/trunk@23487 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2013-02-25 23:17:10 +00:00
parent 12a8779a74
commit 756c28bf5c
5 changed files with 55 additions and 1 deletions

View File

@@ -561,3 +561,29 @@ function _ipad_meta() {
}
}
add_action('admin_head', '_ipad_meta');
/**
* Check lock status for posts displayed on the Posts screen
*
* @since 3.6
*/
function wp_check_locked_posts( $response, $data ) {
$checked = array();
if ( array_key_exists( 'wp-check-locked', $data ) && is_array( $data['wp-check-locked'] ) ) {
foreach ( $data['wp-check-locked'] as $key ) {
$post_id = (int) substr( $key, 5 );
if ( current_user_can( 'edit_post', $post_id ) && ( $user_id = wp_check_post_lock( $post_id ) ) ) {
if ( $user = get_userdata( $user_id ) )
$checked[$key] = sprintf( __( '%s is currently editing' ), $user->display_name );
}
}
}
if ( ! empty( $checked ) )
$response['wp-check-locked'] = $checked;
return $response;
}
add_filter( 'heartbeat_received', 'wp_check_locked_posts', 10, 2 );