<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[23487] trunk: Post locks: use heartbeat to dynamically update locked posts on the Posts screen, first run, see #23312</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/23487">23487</a></dd>
<dt>Author</dt> <dd>azaozz</dd>
<dt>Date</dt> <dd>2013-02-25 23:17:10 +0000 (Mon, 25 Feb 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Post locks: use heartbeat to dynamically update locked posts on the Posts screen, first run, see <a href="http://core.trac.wordpress.org/ticket/23312">#23312</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmineditphp">trunk/wp-admin/edit.php</a></li>
<li><a href="#trunkwpadminincludesclasswppostslisttablephp">trunk/wp-admin/includes/class-wp-posts-list-table.php</a></li>
<li><a href="#trunkwpadminincludesmiscphp">trunk/wp-admin/includes/misc.php</a></li>
<li><a href="#trunkwpincludesscriptloaderphp">trunk/wp-includes/script-loader.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkwpadminjseditpostjs">trunk/wp-admin/js/edit-post.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmineditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit.php (23486 => 23487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit.php        2013-02-25 22:58:42 UTC (rev 23486)
+++ trunk/wp-admin/edit.php        2013-02-25 23:17:10 UTC (rev 23487)
</span><span class="lines">@@ -145,6 +145,7 @@
</span><span class="cx"> $wp_list_table->prepare_items();
</span><span class="cx">
</span><span class="cx"> wp_enqueue_script('inline-edit-post');
</span><ins>+wp_enqueue_script('edit-post');
</ins><span class="cx">
</span><span class="cx"> $title = $post_type_object->labels->name;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpadminincludesclasswppostslisttablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-posts-list-table.php (23486 => 23487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-posts-list-table.php        2013-02-25 22:58:42 UTC (rev 23486)
+++ trunk/wp-admin/includes/class-wp-posts-list-table.php        2013-02-25 23:17:10 UTC (rev 23487)
</span><span class="lines">@@ -555,7 +555,7 @@
</span><span class="cx">
</span><span class="cx">                                 if ( $lock_holder && $can_edit_post && $post->post_status != 'trash' ) {
</span><span class="cx">                                         printf( '<span class="lock-holder">%s</span>',
</span><del>-                                                esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) ) );
</del><ins>+                                                esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) ) );
</ins><span class="cx">                                 }
</span><span class="cx">
</span><span class="cx">                                 if ( ! $this->hierarchical_display && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) )
</span></span></pre></div>
<a id="trunkwpadminincludesmiscphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/misc.php (23486 => 23487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/misc.php        2013-02-25 22:58:42 UTC (rev 23486)
+++ trunk/wp-admin/includes/misc.php        2013-02-25 23:17:10 UTC (rev 23487)
</span><span class="lines">@@ -561,3 +561,29 @@
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> add_action('admin_head', '_ipad_meta');
</span><ins>+
+/**
+ * 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 );
</ins></span></pre></div>
<a id="trunkwpadminjseditpostjs"></a>
<div class="addfile"><h4>Added: trunk/wp-admin/js/edit-post.js (0 => 23487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/edit-post.js         (rev 0)
+++ trunk/wp-admin/js/edit-post.js        2013-02-25 23:17:10 UTC (rev 23487)
</span><span class="lines">@@ -0,0 +1,25 @@
</span><ins>+(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));
</ins><span class="cx">Property changes on: trunk/wp-admin/js/edit-post.js
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkwpincludesscriptloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/script-loader.php (23486 => 23487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/script-loader.php        2013-02-25 22:58:42 UTC (rev 23486)
+++ trunk/wp-includes/script-loader.php        2013-02-25 23:17:10 UTC (rev 23487)
</span><span class="lines">@@ -416,6 +416,8 @@
</span><span class="cx">                 // @todo: Core no longer uses theme-preview.js. Remove?
</span><span class="cx">                 $scripts->add( 'theme-preview', "/wp-admin/js/theme-preview$suffix.js", array( 'thickbox', 'jquery' ), false, 1 );
</span><span class="cx">
</span><ins>+                $scripts->add( 'edit-post', "/wp-admin/js/edit-post$suffix.js", array( 'heartbeat' ), false, 1 );
+
</ins><span class="cx">                 $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'suggest' ), false, 1 );
</span><span class="cx">                 did_action( 'init' ) && $scripts->localize( 'inline-edit-post', 'inlineEditL10n', array(
</span><span class="cx">                         'error' => __('Error while saving the changes.'),
</span></span></pre>
</div>
</div>
</body>
</html>