Post locks: use heartbeat to dynamically update locked posts on the Posts screen, first run, see #23312
git-svn-id: http://core.svn.wordpress.org/trunk@23487 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
34c96ccbf4
commit
9a827a485e
|
@ -145,6 +145,7 @@ if ( $doaction ) {
|
|||
$wp_list_table->prepare_items();
|
||||
|
||||
wp_enqueue_script('inline-edit-post');
|
||||
wp_enqueue_script('edit-post');
|
||||
|
||||
$title = $post_type_object->labels->name;
|
||||
|
||||
|
|
|
@ -555,7 +555,7 @@ class WP_Posts_List_Table extends WP_List_Table {
|
|||
|
||||
if ( $lock_holder && $can_edit_post && $post->post_status != 'trash' ) {
|
||||
printf( '<span class="lock-holder">%s</span>',
|
||||
esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) ) );
|
||||
esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) ) );
|
||||
}
|
||||
|
||||
if ( ! $this->hierarchical_display && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) )
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
(function($){
|
||||
$( document ).on( 'heartbeat-tick.wp-check-locked', function( e, data ) {
|
||||
var locked = data['wp-check-locked'] || {};
|
||||
|
||||
$('#the-list tr').each( function(i, el) {
|
||||
var key = el.id, row = $(el);
|
||||
|
||||
if ( locked.hasOwnProperty( key ) ) {
|
||||
if ( ! row.hasClass('wp-locked') )
|
||||
row.addClass('wp-locked').find('.column-title strong').after( $('<span class="lock-holder" />').text(locked[key]) );
|
||||
row.find('.check-column checkbox').prop('checked', false);
|
||||
} else if ( row.hasClass('wp-locked') ) {
|
||||
row.removeClass('wp-locked').find('.column-title span.lock-holder').remove();
|
||||
}
|
||||
});
|
||||
}).on( 'heartbeat-send.wp-check-locked', function( e, data ) {
|
||||
var check = [];
|
||||
|
||||
$('#the-list tr').each( function(i, el) {
|
||||
check.push( el.id );
|
||||
});
|
||||
|
||||
data['wp-check-locked'] = check;
|
||||
});
|
||||
}(jQuery));
|
|
@ -416,6 +416,8 @@ function wp_default_scripts( &$scripts ) {
|
|||
// @todo: Core no longer uses theme-preview.js. Remove?
|
||||
$scripts->add( 'theme-preview', "/wp-admin/js/theme-preview$suffix.js", array( 'thickbox', 'jquery' ), false, 1 );
|
||||
|
||||
$scripts->add( 'edit-post', "/wp-admin/js/edit-post$suffix.js", array( 'heartbeat' ), false, 1 );
|
||||
|
||||
$scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'suggest' ), false, 1 );
|
||||
did_action( 'init' ) && $scripts->localize( 'inline-edit-post', 'inlineEditL10n', array(
|
||||
'error' => __('Error while saving the changes.'),
|
||||
|
|
Loading…
Reference in New Issue