I18N: Correct translator comments placement in `wp-admin/edit-comments.php`.

This ensures that the translator comments are displayed for the strings they refer to, e.g. to explain placeholders in comment action messages, and are not displayed for unrelated strings, e.g. "Undo", to avoid confusion.

Includes minor code layout fixes and wrapping a few long lines for better readability.

Follow-up to [35549], [45926], [45932].

Props afercia.
See #57839.
Built from https://develop.svn.wordpress.org/trunk@55630


git-svn-id: http://core.svn.wordpress.org/trunk@55142 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2023-04-06 16:44:22 +00:00
parent 94b55b2643
commit 4f6e5a3b7f
3 changed files with 100 additions and 23 deletions

View File

@ -32,7 +32,14 @@ if ( $doaction ) {
$comment_status = wp_unslash( $_REQUEST['comment_status'] ); $comment_status = wp_unslash( $_REQUEST['comment_status'] );
$delete_time = wp_unslash( $_REQUEST['pagegen_timestamp'] ); $delete_time = wp_unslash( $_REQUEST['pagegen_timestamp'] );
$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s AND %s > comment_date_gmt", $comment_status, $delete_time ) ); $comment_ids = $wpdb->get_col(
$wpdb->prepare(
"SELECT comment_ID FROM $wpdb->comments
WHERE comment_approved = %s AND %s > comment_date_gmt",
$comment_status,
$delete_time
)
);
$doaction = 'delete'; $doaction = 'delete';
} elseif ( isset( $_REQUEST['delete_comments'] ) ) { } elseif ( isset( $_REQUEST['delete_comments'] ) ) {
$comment_ids = $_REQUEST['delete_comments']; $comment_ids = $_REQUEST['delete_comments'];
@ -52,7 +59,19 @@ if ( $doaction ) {
$untrashed = 0; $untrashed = 0;
$deleted = 0; $deleted = 0;
$redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() ); $redirect_to = remove_query_arg(
array(
'trashed',
'untrashed',
'deleted',
'spammed',
'unspammed',
'approved',
'unapproved',
'ids',
),
wp_get_referer()
);
$redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to ); $redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to );
wp_defer_comment_counting( true ); wp_defer_comment_counting( true );
@ -286,7 +305,14 @@ if ( isset( $_REQUEST['error'] ) ) {
} }
} }
if ( isset( $_REQUEST['approved'] ) || isset( $_REQUEST['deleted'] ) || isset( $_REQUEST['trashed'] ) || isset( $_REQUEST['untrashed'] ) || isset( $_REQUEST['spammed'] ) || isset( $_REQUEST['unspammed'] ) || isset( $_REQUEST['same'] ) ) { if ( isset( $_REQUEST['approved'] )
|| isset( $_REQUEST['deleted'] )
|| isset( $_REQUEST['trashed'] )
|| isset( $_REQUEST['untrashed'] )
|| isset( $_REQUEST['spammed'] )
|| isset( $_REQUEST['unspammed'] )
|| isset( $_REQUEST['same'] )
) {
$approved = isset( $_REQUEST['approved'] ) ? (int) $_REQUEST['approved'] : 0; $approved = isset( $_REQUEST['approved'] ) ? (int) $_REQUEST['approved'] : 0;
$deleted = isset( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0; $deleted = isset( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0;
$trashed = isset( $_REQUEST['trashed'] ) ? (int) $_REQUEST['trashed'] : 0; $trashed = isset( $_REQUEST['trashed'] ) ? (int) $_REQUEST['trashed'] : 0;
@ -297,35 +323,63 @@ if ( isset( $_REQUEST['approved'] ) || isset( $_REQUEST['deleted'] ) || isset( $
if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) { if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) {
if ( $approved > 0 ) { if ( $approved > 0 ) {
/* translators: %s: Number of comments. */ $messages[] = sprintf(
$messages[] = sprintf( _n( '%s comment approved.', '%s comments approved.', $approved ), $approved ); /* translators: %s: Number of comments. */
_n( '%s comment approved.', '%s comments approved.', $approved ),
$approved
);
} }
if ( $spammed > 0 ) { if ( $spammed > 0 ) {
$ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0; $ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
/* translators: %s: Number of comments. */
$messages[] = sprintf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", 'bulk-comments' ) ) . '">' . __( 'Undo' ) . '</a><br />'; $messages[] = sprintf(
/* translators: %s: Number of comments. */
_n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ),
$spammed
) . sprintf(
' <a href="%1$s">%2$s</a><br />',
esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", 'bulk-comments' ) ),
__( 'Undo' )
);
} }
if ( $unspammed > 0 ) { if ( $unspammed > 0 ) {
/* translators: %s: Number of comments. */ $messages[] = sprintf(
$messages[] = sprintf( _n( '%s comment restored from the spam.', '%s comments restored from the spam.', $unspammed ), $unspammed ); /* translators: %s: Number of comments. */
_n( '%s comment restored from the spam.', '%s comments restored from the spam.', $unspammed ),
$unspammed
);
} }
if ( $trashed > 0 ) { if ( $trashed > 0 ) {
$ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0; $ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
/* translators: %s: Number of comments. */
$messages[] = sprintf( _n( '%s comment moved to the Trash.', '%s comments moved to the Trash.', $trashed ), $trashed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", 'bulk-comments' ) ) . '">' . __( 'Undo' ) . '</a><br />'; $messages[] = sprintf(
/* translators: %s: Number of comments. */
_n( '%s comment moved to the Trash.', '%s comments moved to the Trash.', $trashed ),
$trashed
) . sprintf(
' <a href="%1$s">%2$s</a><br />',
esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", 'bulk-comments' ) ),
__( 'Undo' )
);
} }
if ( $untrashed > 0 ) { if ( $untrashed > 0 ) {
/* translators: %s: Number of comments. */ $messages[] = sprintf(
$messages[] = sprintf( _n( '%s comment restored from the Trash.', '%s comments restored from the Trash.', $untrashed ), $untrashed ); /* translators: %s: Number of comments. */
_n( '%s comment restored from the Trash.', '%s comments restored from the Trash.', $untrashed ),
$untrashed
);
} }
if ( $deleted > 0 ) { if ( $deleted > 0 ) {
/* translators: %s: Number of comments. */ $messages[] = sprintf(
$messages[] = sprintf( _n( '%s comment permanently deleted.', '%s comments permanently deleted.', $deleted ), $deleted ); /* translators: %s: Number of comments. */
_n( '%s comment permanently deleted.', '%s comments permanently deleted.', $deleted ),
$deleted
);
} }
if ( $same > 0 ) { if ( $same > 0 ) {
@ -333,19 +387,34 @@ if ( isset( $_REQUEST['approved'] ) || isset( $_REQUEST['deleted'] ) || isset( $
if ( $comment ) { if ( $comment ) {
switch ( $comment->comment_approved ) { switch ( $comment->comment_approved ) {
case '1': case '1':
$messages[] = __( 'This comment is already approved.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>'; $messages[] = __( 'This comment is already approved.' ) . sprintf(
' <a href="%1$s">%2$s</a>',
esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ),
__( 'Edit comment' )
);
break; break;
case 'trash': case 'trash':
$messages[] = __( 'This comment is already in the Trash.' ) . ' <a href="' . esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ) . '"> ' . __( 'View Trash' ) . '</a>'; $messages[] = __( 'This comment is already in the Trash.' ) . sprintf(
' <a href="%1$s">%2$s</a>',
esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ),
__( 'View Trash' )
);
break; break;
case 'spam': case 'spam':
$messages[] = __( 'This comment is already marked as spam.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>'; $messages[] = __( 'This comment is already marked as spam.' ) . sprintf(
' <a href="%1$s">%2$s</a>',
esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ),
__( 'Edit comment' )
);
break; break;
} }
} }
} }
echo '<div id="moderated" class="updated notice is-dismissible"><p>' . implode( "<br />\n", $messages ) . '</p></div>'; printf(
'<div id="moderated" class="updated notice is-dismissible"><p>%s</p></div>',
implode( "<br />\n", $messages )
);
} }
} }
?> ?>

View File

@ -442,8 +442,13 @@ foreach ( $bulk_counts as $message => $count ) {
} }
if ( 'trashed' === $message && isset( $_REQUEST['ids'] ) ) { if ( 'trashed' === $message && isset( $_REQUEST['ids'] ) ) {
$ids = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] ); $ids = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] );
$messages[] = '<a href="' . esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", 'bulk-posts' ) ) . '">' . __( 'Undo' ) . '</a>';
$messages[] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", 'bulk-posts' ) ),
__( 'Undo' )
);
} }
if ( 'untrashed' === $message && isset( $_REQUEST['ids'] ) ) { if ( 'untrashed' === $message && isset( $_REQUEST['ids'] ) ) {
@ -460,7 +465,10 @@ foreach ( $bulk_counts as $message => $count ) {
} }
if ( $messages ) { if ( $messages ) {
echo '<div id="message" class="updated notice is-dismissible"><p>' . implode( ' ', $messages ) . '</p></div>'; printf(
'<div id="message" class="updated notice is-dismissible"><p>%s</p></div>',
implode( ' ', $messages )
);
} }
unset( $messages ); unset( $messages );

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.3-alpha-55629'; $wp_version = '6.3-alpha-55630';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.