From 7f0b4902863dcb5821f9f12777e13426893440b6 Mon Sep 17 00:00:00 2001 From: Aristeides Stathopoulos Date: Tue, 23 Jan 2024 11:52:21 +0200 Subject: [PATCH] code tweaks for readability --- admin/admin.php | 87 +++++--- admin/comment-parent.php | 2 +- admin/views/comment-parent-box.php | 8 +- admin/views/config-page.php | 311 +++++++++++++++++++++-------- inc/clean-emails.php | 54 +++-- inc/forms.php | 14 +- inc/hacks.php | 12 +- 7 files changed, 334 insertions(+), 154 deletions(-) diff --git a/admin/admin.php b/admin/admin.php index 8b5564c..108f74c 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -99,10 +99,21 @@ public function forward_comment(): void { $comment_id = (int) $_GET['comment_id']; $comment = \get_comment( $comment_id ); - /* translators: %1$s is replaced by (a link to) the blog's name, %2$s by (a link to) the title of the blogpost. */ - echo '

' . \sprintf( \esc_html__( 'Forwarding comment from %1$s to %2$s.', 'comment-hacks' ), '' . \esc_html( $comment->comment_author ) . '', \esc_html( $this->options['forward_name'] ) ) . '

'; + echo '

'; + \printf( + /* translators: %1$s is replaced by (a link to) the blog's name, %2$s by (a link to) the title of the blogpost. */ + \esc_html__( 'Forwarding comment from %1$s to %2$s.', 'comment-hacks' ), + '' . \esc_html( $comment->comment_author ) . '', + \esc_html( $this->options['forward_name'] ) + ); + echo '

'; - $intro = \sprintf( 'This comment was forwarded from %s where it was left on: %s.', '' . \esc_html( \get_bloginfo( 'name' ) ) . '', '' . \get_the_title( $comment->comment_post_ID ) . '' ) . "\n\n"; + $intro = \sprintf( + /* translators: %1$s is replaced by (a link to) the blog's name, %2$s by (a link to) the title of the post. */ + \esc_html__( 'This comment was forwarded from %1$s where it was left on: %2$s.', 'comment-hacks' ), + '' . \esc_html( \get_bloginfo( 'name' ) ) . '', + '' . \get_the_title( $comment->comment_post_ID ) . '' + ) . "\n\n"; if ( ! empty( $this->options['forward_extra'] ) ) { $intro .= $this->options['forward_extra'] . "\n\n"; @@ -176,8 +187,17 @@ public function register_meta_boxes(): void { * @param WP_Post $post Current post object. */ public function meta_box_callback( $post ): void { - echo ''; - echo '
'; + ?> + + +
+ absolute_min + 1 ) > $input['mincomlength'] || empty( $input['mincomlength'] ) ) { - /* translators: %d is replaced with the minimum number of characters */ - \add_settings_error( $this->hook, 'min_length_invalid', \sprintf( \__( 'The minimum length you entered is invalid, please enter a minimum length above %d.', 'comment-hacks' ), $this->absolute_min ) ); + \add_settings_error( + $this->hook, + 'min_length_invalid', + \sprintf( + /* translators: %d is replaced with the minimum number of characters */ + \__( 'The minimum length you entered is invalid, please enter a minimum length above %d.', 'comment-hacks' ), + $this->absolute_min + ) + ); $input['mincomlength'] = 15; } @@ -316,14 +346,7 @@ public function options_validate( array $input ): array { * @param mixed $value The input value to cast to boolean. */ private function sanitize_bool( $value ): bool { - if ( $value ) { - $value = true; - } - if ( empty( $value ) ) { - $value = false; - } - - return $value; + return ( $value || ! empty( $value ) ); } /** @@ -335,11 +358,7 @@ private function sanitize_bool( $value ): bool { * @return array $input The array with sanitized input values. */ private function sanitize_string( $value, $default ) { - if ( $value === '' ) { - $value = $default; - } - - return $value; + return ( $value === '' ) ? $default : $value; } /** @@ -388,17 +407,21 @@ public function config_page(): void { // Show the content of the options array when debug is enabled. if ( \defined( 'WP_DEBUG' ) && \WP_DEBUG ) { - echo '

', \esc_html__( 'Options debug', 'comment-hacks' ), '

'; - echo '
'; - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Debug output. - echo \str_replace( - '', - '', - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export -- This is only shown in debug mode. - \highlight_string( "options = " . \var_export( $this->options, true ) . ';', true ), - $num - ); - echo '
'; + ?> +

+
+ ', + '', + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export -- This is only shown in debug mode. + \highlight_string( "options = " . \var_export( $this->options, true ) . ';', true ), + $num + ); + ?> +
+ - - + +
+ + + +
diff --git a/admin/views/config-page.php b/admin/views/config-page.php index 7a1c867..6ad2557 100644 --- a/admin/views/config-page.php +++ b/admin/views/config-page.php @@ -10,19 +10,27 @@

@@ -35,24 +43,37 @@
- - +
- + - +
@@ -63,24 +84,36 @@
- - +
- + - +
@@ -92,18 +125,29 @@
- + - options['comment_policy'] ); ?> name="" id="comment_policy"/> + options['comment_policy'] ); ?> + name="" + id="comment_policy" + />

- +

- +
- + - +

- + - +
@@ -147,41 +207,61 @@

' ); + printf( + /* translators: %s expands to an email button icon */ + esc_html__( 'This plugin adds an "E-mail" action link on the comments overview page as well as an email all commenters button (%s) on individual post pages in the admin bar. You can customize the default messages here.', 'comment-hacks' ), + '' + ); ?>

- + - +
- + - +
- + - +
@@ -194,7 +274,9 @@
- + esc_html__( 'Don\'t redirect first time commenters', 'comment-hacks' ), ] ); - - if ( isset( $this->options['redirect_page'] ) && $this->options['redirect_page'] !== 0 ) { - echo '

' . esc_html__( 'Current redirect page', 'comment-hacks' ) . ''; - } - ?> + + options['redirect_page'] ) && $this->options['redirect_page'] !== 0 ) : ?> +
+
+ + + +
@@ -227,10 +312,17 @@ -
- + options['clean_emails'] ); ?> /> + + options['clean_emails'] ); ?> + />
@@ -243,47 +335,83 @@ - - - - -
- + + +
- + + +
- + + +
- + + +
- + + +
@@ -296,10 +424,17 @@ -
- + options['disable_email_all_commenters'] ); ?> /> + + options['disable_email_all_commenters'] ); ?> + />
diff --git a/inc/clean-emails.php b/inc/clean-emails.php index 9c99dee..0a41e2c 100644 --- a/inc/clean-emails.php +++ b/inc/clean-emails.php @@ -76,18 +76,21 @@ public function comment_email_headers( $message_headers ) { public function comment_notification_text( $message, $comment_id ): string { $this->setup_data( $comment_id ); + $comment_url = \get_permalink( $this->comment->comment_post_ID ) . '#comment-' . $comment_id; + $comment_link = '' . \esc_html( $this->post->post_title ) . ''; + switch ( $this->comment->comment_type ) { case 'pingback': /* translators: %s is replaced with the post title */ - $this->message = \sprintf( \__( 'New pingback on "%s"', 'comment-hacks' ), '' . \esc_html( $this->post->post_title ) . '' ) . '

'; + $this->message = \sprintf( \__( 'New pingback on "%s"', 'comment-hacks' ), $comment_link ) . '

'; break; case 'trackback': /* translators: %s is replaced with the post title */ - $this->message = \sprintf( \__( 'New trackback on "%s"', 'comment-hacks' ), '' . \esc_html( $this->post->post_title ) . '' ) . '

'; + $this->message = \sprintf( \__( 'New trackback on "%s"', 'comment-hacks' ), $comment_link ) . '

'; break; default: /* translators: %s is replaced with the post title */ - $this->message = \sprintf( \__( 'New comment on "%s"', 'comment-hacks' ), '' . \esc_html( $this->post->post_title ) . '' ) . '

'; + $this->message = \sprintf( \__( 'New comment on "%s"', 'comment-hacks' ), $comment_link ) . '

'; break; } $this->add_comment_basics(); @@ -108,24 +111,39 @@ public function comment_notification_text( $message, $comment_id ): string { public function comment_moderation_text( $message, $comment_id ): string { $this->setup_data( $comment_id ); + $comment_link = '' . \esc_html( $this->post->post_title ) . ''; + switch ( $this->comment->comment_type ) { case 'pingback': - /* translators: %1$s is replaced with the post title */ - $this->message = \sprintf( \__( 'A new pingback on the post "%1$s" is waiting for your approval:', 'comment-hacks' ), '' . \esc_html( $this->post->post_title ) . '' ) . '

'; + $this->message = \sprintf( + /* translators: %1$s is replaced with the post title */ + \__( 'A new pingback on the post "%1$s" is waiting for your approval:', 'comment-hacks' ), + $comment_link + ) . '

'; break; case 'trackback': - /* translators: %1$s is replaced with the post title */ - $this->message = \sprintf( \__( 'A new trackback on the post "%1$s" is waiting for your approval:', 'comment-hacks' ), '' . \esc_html( $this->post->post_title ) . '' ) . '

'; + $this->message = \sprintf( + /* translators: %1$s is replaced with the post title */ + \__( 'A new trackback on the post "%1$s" is waiting for your approval:', 'comment-hacks' ), + $comment_link + ) . '

'; break; default: - /* translators: %1$s is replaced with the post title */ - $this->message = \sprintf( \__( 'A new comment on the post "%1$s" is waiting for your approval:', 'comment-hacks' ), '' . \esc_html( $this->post->post_title ) . '' ) . '

'; + $this->message = \sprintf( + /* translators: %1$s is replaced with the post title */ + \__( 'A new comment on the post "%1$s" is waiting for your approval:', 'comment-hacks' ), + $comment_link + ) . '

'; break; } $this->add_comment_basics(); $this->comment_moderation_actions(); - $this->message .= ' | ' . \sprintf( '%2$s', $this->comment->comment_author_IP, \__( 'Whois', 'comment-hacks' ) ); + $this->message .= ' | ' . \sprintf( + '%2$s', + $this->comment->comment_author_IP, + \__( 'Whois', 'comment-hacks' ) + ); $this->message .= '

'; $this->get_moderation_msg(); @@ -207,11 +225,17 @@ private function get_moderation_msg(): void { if ( $comments_waiting > 1 ) { --$comments_waiting; - /* translators: %s is replaced with the number of comments waiting for approval */ - $this->message .= \sprintf( \__( 'Currently this and %s other comments are waiting for approval.', 'comment-hacks' ), \number_format_i18n( $comments_waiting ) ); + $this->message .= \sprintf( + /* translators: %s is replaced with the number of comments waiting for approval */ + \__( 'Currently this and %s other comments are waiting for approval.', 'comment-hacks' ), + \number_format_i18n( $comments_waiting ) + ); $this->message .= ' '; - /* translators: %1$s and %2$s are replaced with the HTML for a link to the moderation panel */ - $this->message .= \sprintf( \__( 'Please visit the %1$smoderation panel%2$s.', 'comment-hacks' ), '', '' ) . '
'; + $this->message .= \sprintf( + /* translators: %s is replaced with the HTML for a link to the moderation panel, with text "moderation panel". */ + \__( 'Please visit the %s.', 'comment-hacks' ), + '' . \__( 'moderation panel', 'comment-hacks' ) . '' + ) . '
'; } } @@ -267,6 +291,6 @@ private function comment_action_links( array $actions ): void { private function comment_action_link( string $label, string $action ): string { $url = \admin_url( \sprintf( 'comment.php?action=%s&c=%d', $action, $this->comment_id ) ); - return \sprintf( '%2$s', \esc_url( $url ), \esc_html( $label ) ); + return '' . \esc_html( $label ) . ''; } } diff --git a/inc/forms.php b/inc/forms.php index c4a8a5c..70cb8ab 100644 --- a/inc/forms.php +++ b/inc/forms.php @@ -31,12 +31,14 @@ public function __construct() { * @return void */ public function comment_form_fields() { - echo ''; + ?> + +