From 9dbb61ea6bda3ef0d9716b8eb493d3f6a02f30d0 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 6 Apr 2023 16:42:40 +0000 Subject: [PATCH] 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 --- src/wp-admin/edit-comments.php | 107 +++++++++++++++++++++++++++------ src/wp-admin/edit.php | 14 ++++- 2 files changed, 99 insertions(+), 22 deletions(-) diff --git a/src/wp-admin/edit-comments.php b/src/wp-admin/edit-comments.php index 866678badf..d1960c91b4 100644 --- a/src/wp-admin/edit-comments.php +++ b/src/wp-admin/edit-comments.php @@ -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 ) . ' ' . __( 'Undo' ) . '
'; + + $messages[] = sprintf( + /* translators: %s: Number of comments. */ + _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), + $spammed + ) . sprintf( + ' %2$s
', + 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 ) . ' ' . __( 'Undo' ) . '
'; + + $messages[] = sprintf( + /* translators: %s: Number of comments. */ + _n( '%s comment moved to the Trash.', '%s comments moved to the Trash.', $trashed ), + $trashed + ) . sprintf( + ' %2$s
', + 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.' ) . ' ' . __( 'Edit comment' ) . ''; + $messages[] = __( 'This comment is already approved.' ) . sprintf( + ' %2$s', + esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ), + __( 'Edit comment' ) + ); break; case 'trash': - $messages[] = __( 'This comment is already in the Trash.' ) . ' ' . __( 'View Trash' ) . ''; + $messages[] = __( 'This comment is already in the Trash.' ) . sprintf( + ' %2$s', + esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ), + __( 'View Trash' ) + ); break; case 'spam': - $messages[] = __( 'This comment is already marked as spam.' ) . ' ' . __( 'Edit comment' ) . ''; + $messages[] = __( 'This comment is already marked as spam.' ) . sprintf( + ' %2$s', + esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ), + __( 'Edit comment' ) + ); break; } } } - echo '

' . implode( "
\n", $messages ) . '

'; + printf( + '

%s

', + implode( "
\n", $messages ) + ); } } ?> diff --git a/src/wp-admin/edit.php b/src/wp-admin/edit.php index 634f7a977f..7361aa1d40 100644 --- a/src/wp-admin/edit.php +++ b/src/wp-admin/edit.php @@ -442,8 +442,13 @@ foreach ( $bulk_counts as $message => $count ) { } if ( 'trashed' === $message && isset( $_REQUEST['ids'] ) ) { - $ids = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] ); - $messages[] = '' . __( 'Undo' ) . ''; + $ids = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] ); + + $messages[] = sprintf( + '%2$s', + 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 '

' . implode( ' ', $messages ) . '

'; + printf( + '

%s

', + implode( ' ', $messages ) + ); } unset( $messages );