Skip to content

Commit 3d462b2

Browse files
shekharnwaghellatrixchriszarate
authored andcommitted
RTC: Fix stuck "Join" link in post list when lock expires (#76795)
* RTC: Fix stuck "Join" link in post list when lock expires Always render both "Edit" and "Join" as separate spans in the row action link and toggle visibility via CSS using the .wp-collaborative-editing class the heartbeat already manages. Replaces aria-label with screen-reader-text spans so the accessible name stays in sync with the visible text across lock state changes. * RTC: Fix checkbox not showing for locked posts in post list The CSS selectors used `.wp-locked` to override core's hidden checkbox, but core's list-tables.css uses `tr.wp-locked` which has higher specificity. The `display: revert` rule never took effect, leaving checkboxes hidden on locked rows. * RTC: Use sprintf with multi-line template for action link markup * RTC: Target .wp-locked for Edit/Join toggle in compat layer The CSS was targeting .wp-collaborative-editing, a class only set by core 7.0's inline-edit-post.js. The compat layer runs on older versions where the heartbeat uses .wp-locked, so the toggle never worked. Since this CSS is only output when RTC is enabled, .wp-locked always means collaborative editing here. ---- Co-authored-by: shekharnwagh <shekharnwagh@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: chriszarate <czarate@git.wordpress.org>
1 parent d3ec009 commit 3d462b2

2 files changed

Lines changed: 60 additions & 18 deletions

File tree

‎backport-changelog/7.0/11346.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
https://github.com/WordPress/wordpress-develop/pull/11346
2+
3+
* https://github.com/WordPress/gutenberg/pull/76795

‎lib/compat/wordpress-7.0/collaboration.php‎

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ function gutenberg_filter_locked_posts_heartbeat_for_rtc( $response ) {
233233
*
234234
* Also re-enables checkboxes and row actions that WordPress core hides for
235235
* locked posts, since collaborative editing means the post is not exclusively
236-
* locked.
236+
* locked. Toggles "Edit" / "Join" action link text via the
237+
* `.wp-collaborative-editing` class that the heartbeat already manages.
237238
*/
238239
function gutenberg_post_list_collaboration_styles() {
239240
?>
@@ -253,14 +254,31 @@ function gutenberg_post_list_collaboration_styles() {
253254
/*
254255
* Re-enable controls that core hides for locked posts,
255256
* since RTC allows collaborative editing.
257+
* Must use `tr.wp-locked` to match core's specificity in
258+
* list-tables.css and actually override its `display: none`.
256259
*/
257-
.wp-locked .check-column label,
258-
.wp-locked .check-column input[type="checkbox"] {
260+
tr.wp-locked .check-column label,
261+
tr.wp-locked .check-column input[type="checkbox"] {
259262
display: revert;
260263
}
261-
.wp-locked .row-actions .inline {
264+
tr.wp-locked .row-actions .inline {
262265
display: revert;
263266
}
267+
/*
268+
* Toggle "Edit" / "Join" action link text based on lock state.
269+
* The heartbeat adds/removes .wp-locked on locked rows. This
270+
* CSS only runs when RTC is enabled, so .wp-locked here always
271+
* means collaborative editing, not exclusive locking.
272+
*/
273+
.join-action-text {
274+
display: none;
275+
}
276+
.wp-locked .edit-action-text {
277+
display: none;
278+
}
279+
.wp-locked .join-action-text {
280+
display: inline;
281+
}
264282
</style>
265283
<?php
266284
}
@@ -288,30 +306,51 @@ function gutenberg_filter_locked_post_text_for_rtc( $translation, $text, $domain
288306
}
289307

290308
/**
291-
* Filters post row actions to change "Edit" to "Join" for locked posts
309+
* Filters post row actions to render both "Edit" and "Join" link text
292310
* when real-time collaboration is enabled.
293311
*
312+
* Both labels are always present in the markup; CSS toggles visibility
313+
* based on the `.wp-collaborative-editing` class the heartbeat manages.
314+
* This ensures the link text updates when the lock state changes without
315+
* requiring a page reload.
316+
*
294317
* @param string[] $actions An array of row action links.
295318
* @param WP_Post $post The post object.
296319
* @return string[] Modified row action links.
297320
*/
298321
function gutenberg_post_list_collaboration_row_actions( $actions, $post ) {
299-
if ( ! function_exists( 'wp_check_post_lock' ) ) {
300-
require_once ABSPATH . 'wp-admin/includes/post.php';
301-
}
302-
303-
$lock_holder = wp_check_post_lock( $post->ID );
304-
if ( ! $lock_holder ) {
322+
if ( ! isset( $actions['edit'] ) ) {
305323
return $actions;
306324
}
307325

308-
if ( isset( $actions['edit'] ) ) {
309-
$actions['edit'] = preg_replace(
310-
'/>Edit</',
311-
'>' . esc_html__( 'Join', 'gutenberg' ) . '<',
312-
$actions['edit']
313-
);
314-
}
326+
$title = _draft_or_post_title( $post->ID );
327+
328+
/*
329+
* Both "Edit" and "Join" labels are rendered. The visible label is
330+
* toggled by CSS based on the row's `wp-collaborative-editing` class,
331+
* which is added or removed by inline-edit-post.js in response to
332+
* heartbeat ticks.
333+
*/
334+
$actions['edit'] = sprintf(
335+
'<a href="%1$s">'
336+
. '<span class="edit-action-text">'
337+
. '<span aria-hidden="true">%2$s</span>'
338+
. '<span class="screen-reader-text">%3$s</span>'
339+
. '</span>'
340+
. '<span class="join-action-text">'
341+
. '<span aria-hidden="true">%4$s</span>'
342+
. '<span class="screen-reader-text">%5$s</span>'
343+
. '</span>'
344+
. '</a>',
345+
get_edit_post_link( $post->ID ),
346+
__( 'Edit' ),
347+
/* translators: %s: Post title. */
348+
sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ),
349+
/* translators: Action link text for a singular post in the post list. Can be any type of post. */
350+
_x( 'Join', 'post list', 'gutenberg' ),
351+
/* translators: %s: Post title. */
352+
sprintf( __( 'Join editing &#8220;%s&#8221;', 'gutenberg' ), $title )
353+
);
315354

316355
return $actions;
317356
}

0 commit comments

Comments
 (0)