Skip to content

Commit 896d208

Browse files
committed
Real-time collaboration: Update "Join" action label in post list if lock expires
When RTC is enabled, let the "Join" action link in the post list turn into "Edit" after the post lock expires. Do this by rendering both "Edit" and "Join" as separate spans and toggling visibility via CSS using the `wp-collaborative-editing` class that heartbeat already manages. Do the same to aria-label with screen-reader-text spans so the accessible name stays in sync with the visible text across lock state changes. Developed in #11346. Follow-up to [62074]. Props shekharnwagh. See #64622. git-svn-id: https://develop.svn.wordpress.org/trunk@62146 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c125357 commit 896d208

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

src/wp-admin/css/list-tables.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,18 @@ tr.wp-locked .row-actions .trash {
639639
display: block;
640640
}
641641

642+
.join-action-text {
643+
display: none;
644+
}
645+
646+
.wp-collaborative-editing .edit-action-text {
647+
display: none;
648+
}
649+
650+
.wp-collaborative-editing .join-action-text {
651+
display: inline;
652+
}
653+
642654
#menu-locations-wrap .widefat {
643655
width: 60%;
644656
}

src/wp-admin/includes/class-wp-posts-list-table.php

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,24 +1491,44 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
14911491
$title = _draft_or_post_title();
14921492

14931493
if ( $can_edit_post && 'trash' !== $post->post_status ) {
1494-
$is_rtc_locked = get_option( 'wp_collaboration_enabled' ) && wp_check_post_lock( $post->ID );
1494+
$is_rtc_enabled = (bool) get_option( 'wp_collaboration_enabled' );
14951495

1496-
$actions['edit'] = sprintf(
1497-
'<a href="%s" aria-label="%s">%s</a>',
1498-
get_edit_post_link( $post->ID ),
1499-
esc_attr(
1500-
sprintf(
1501-
$is_rtc_locked
1502-
/* translators: %s: Post title. */
1503-
? __( 'Join editing &#8220;%s&#8221;', 'post list' )
1504-
/* translators: %s: Post title. */
1505-
: __( 'Edit &#8220;%s&#8221;' ),
1506-
$title
1507-
)
1508-
),
1509-
/* translators: Action link text for a singular post in the post list. Can be any type of post. */
1510-
$is_rtc_locked ? _x( 'Join', 'post list' ) : __( 'Edit' )
1511-
);
1496+
/*
1497+
* When RTC is enabled, both "Edit" and "Join" labels are rendered.
1498+
* The visible label is toggled by CSS based on the row's
1499+
* `wp-collaborative-editing` class, which is added or removed by
1500+
* inline-edit-post.js in response to heartbeat ticks.
1501+
*/
1502+
if ( $is_rtc_enabled ) {
1503+
$actions['edit'] = sprintf(
1504+
'<a href="%1$s">'
1505+
. '<span class="edit-action-text">'
1506+
. '<span aria-hidden="true">%2$s</span>'
1507+
. '<span class="screen-reader-text">%3$s</span>'
1508+
. '</span>'
1509+
. '<span class="join-action-text">'
1510+
. '<span aria-hidden="true">%4$s</span>'
1511+
. '<span class="screen-reader-text">%5$s</span>'
1512+
. '</span>'
1513+
. '</a>',
1514+
get_edit_post_link( $post->ID ),
1515+
__( 'Edit' ),
1516+
/* translators: %s: Post title. */
1517+
sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ),
1518+
/* translators: Action link text for a singular post in the post list. Can be any type of post. */
1519+
_x( 'Join', 'post list' ),
1520+
/* translators: %s: Post title. */
1521+
sprintf( __( 'Join editing &#8220;%s&#8221;', 'post list' ), $title )
1522+
);
1523+
} else {
1524+
$actions['edit'] = sprintf(
1525+
'<a href="%s" aria-label="%s">%s</a>',
1526+
get_edit_post_link( $post->ID ),
1527+
/* translators: %s: Post title. */
1528+
esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ),
1529+
__( 'Edit' )
1530+
);
1531+
}
15121532

15131533
/**
15141534
* Filters whether Quick Edit should be enabled for the given post type.

0 commit comments

Comments
 (0)