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.

git-svn-id: https://develop.svn.wordpress.org/trunk@55630 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2023-04-06 16:42:40 +00:00
parent b6b6ded79a
commit 9dbb61ea6b
2 changed files with 99 additions and 22 deletions

View File

@ -32,7 +32,14 @@ if ( $doaction ) {
$comment_status = wp_unslash( $_REQUEST['comment_status'] );
$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';
} elseif ( isset( $_REQUEST['delete_comments'] ) ) {
$comment_ids = $_REQUEST['delete_comments'];
@ -52,7 +59,19 @@ if ( $doaction ) {
$untrashed = 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 );
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;
$deleted = isset( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 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 ) {
/* translators: %s: Number of comments. */
$messages[] = sprintf( _n( '%s comment approved.', '%s comments approved.', $approved ), $approved );
$messages[] = sprintf(
/* translators: %s: Number of comments. */
_n( '%s comment approved.', '%s comments approved.', $approved ),
$approved
);
}
if ( $spammed > 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 ) {
/* translators: %s: Number of comments. */
$messages[] = sprintf( _n( '%s comment restored from the spam.', '%s comments restored from the spam.', $unspammed ), $unspammed );
$messages[] = sprintf(
/* translators: %s: Number of comments. */
_n( '%s comment restored from the spam.', '%s comments restored from the spam.', $unspammed ),
$unspammed
);
}
if ( $trashed > 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 ) {
/* translators: %s: Number of comments. */
$messages[] = sprintf( _n( '%s comment restored from the Trash.', '%s comments restored from the Trash.', $untrashed ), $untrashed );
$messages[] = sprintf(
/* translators: %s: Number of comments. */
_n( '%s comment restored from the Trash.', '%s comments restored from the Trash.', $untrashed ),
$untrashed
);
}
if ( $deleted > 0 ) {
/* translators: %s: Number of comments. */
$messages[] = sprintf( _n( '%s comment permanently deleted.', '%s comments permanently deleted.', $deleted ), $deleted );
$messages[] = sprintf(
/* translators: %s: Number of comments. */
_n( '%s comment permanently deleted.', '%s comments permanently deleted.', $deleted ),
$deleted
);
}
if ( $same > 0 ) {
@ -333,19 +387,34 @@ if ( isset( $_REQUEST['approved'] ) || isset( $_REQUEST['deleted'] ) || isset( $
if ( $comment ) {
switch ( $comment->comment_approved ) {
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;
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;
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;
}
}
}
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'] ) ) {
$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>';
$ids = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] );
$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'] ) ) {
@ -460,7 +465,10 @@ foreach ( $bulk_counts as $message => $count ) {
}
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 );