From d54502c404e91b7a55446a69f6d8ecf22c42b9f3 Mon Sep 17 00:00:00 2001 From: Caleb Stauffer Date: Fri, 16 Jun 2023 14:06:06 -0400 Subject: [PATCH 1/7] save --- collectors/emails.php | 168 +++++++++++++++++++++++++++++ data/emails.php | 25 +++++ output/html/emails.php | 239 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 432 insertions(+) create mode 100644 collectors/emails.php create mode 100644 data/emails.php create mode 100644 output/html/emails.php diff --git a/collectors/emails.php b/collectors/emails.php new file mode 100644 index 000000000..97d3e044b --- /dev/null +++ b/collectors/emails.php @@ -0,0 +1,168 @@ + + */ +class QM_Collector_Emails extends QM_DataCollector { + + public $id = 'emails'; + + public function get_storage(): QM_Data { + return new QM_Data_Emails(); + } + + /** + * @return void + */ + public function set_up() { + parent::set_up(); + add_filter( 'pre_wp_mail', array( $this, 'filter_pre_wp_mail' ), 9999, 2 ); + add_action( 'wp_mail_succeeded', array( $this, 'action_wp_mail_succeeded' ) ); + add_action( 'wp_mail_failed', array( $this, 'action_wp_mail_failed' ) ); + } + + /** + * @return void + */ + public function tear_down() { + remove_filter( 'pre_wp_mail', array( $this, 'filter_pre_wp_mail' ), 9999 ); + remove_action( 'wp_mail_succeeded', array( $this, 'action_wp_mail_succeeded' ) ); + remove_action( 'wp_mail_failed', array( $this, 'action_wp_mail_failed' ) ); + + parent::tear_down(); + } + + /** + * @return array + */ + public function get_concerned_actions() { + return array( + 'phpmailer_init', + 'wp_mail_succeeded', + 'wp_mail_failed', + ); + } + + /** + * @return array + */ + public function get_concerned_filters() { + return array( + 'pre_wp_mail', + 'wp_mail', + 'wp_mail_from', + 'wp_mail_from_name', + 'wp_mail_content_type', + 'wp_mail_charset', + ); + } + + protected function hash( $value ) { + $value = json_encode( $value ); + return wp_hash( $value ); + } + + public function filter_pre_wp_mail( $preempt, $atts ) { + if ( is_null( $preempt ) ) { + return null; + } + + if ( is_null( $this->data->preempted ) ) { + $this->data->preempted = array(); + } + + $hash = $this->hash( $atts ); + $trace = new QM_Backtrace( array( + 'ignore_hook' => array( + current_filter() => true, + ), + ) ); + + $this->data->preempted[] = $hash; + $this->data->emails[ $hash ] = array( + 'atts' => $atts, + 'error' => null, + 'filtered_trace' => $trace->get_filtered_trace(), + ); + + return $preempt; + } + + public function action_wp_mail_succeeded( $atts ) { + $hash = $this->hash( $atts ); + $trace = new QM_Backtrace( array( + 'ignore_hook' => array( + current_filter() => true, + ), + ) ); + + $this->data->emails[ $hash ] = array( + 'atts' => $atts, + 'error' => null, + 'filtered_trace' => $trace->get_filtered_trace(), + ); + } + + public function action_wp_mail_failed( $error ) { + if ( is_null( $this->data->failed ) ) { + $this->data->failed = array(); + } + + $atts = $error->get_error_data( 'wp_mail_failed' ); + $hash = $this->hash( $atts ); + $trace = new QM_Backtrace( array( + 'ignore_hook' => array( + current_filter() => true, + ), + ) ); + + $this->data->failed[] = $hash; + $this->data->emails[ $hash ] = array( + 'atts' => $atts, + 'error' => $error, + 'filtered_trace' => $trace->get_filtered_trace(), + ); + } + + public function process() { + $this->data->counts = array( + 'preempted' => 0, + 'failed' => 0, + 'succeeded' => 0, + 'total' => 0, + ); + + if ( ! is_array( $this->data->preempted ) ) { + $this->data->preempted = array(); + } + + if ( ! is_array( $this->data->failed ) ) { + $this->data->failed = array(); + } +do_action( 'qm/debug', $this->data->emails ); + foreach ( $this->data->emails as $hash => $email ) { + $this->data->counts['total']++; + + if ( in_array( $hash, $this->data->preempted ) ) { + $this->data->counts['preempted']++; + } else if ( in_array( $hash, $this->data->failed ) ) { + $this->data->counts['failed']++; + } else { + $this->data->counts['succeeded']++; + } + } + } + +} + +# Load early to catch early emails +QM_Collectors::add( new QM_Collector_Emails() ); \ No newline at end of file diff --git a/data/emails.php b/data/emails.php new file mode 100644 index 000000000..a477e6043 --- /dev/null +++ b/data/emails.php @@ -0,0 +1,25 @@ + + */ + public $preempted; + + /** + * @var array + */ + public $failed; + + /** + * @var array + */ + public $counts; +} \ No newline at end of file diff --git a/output/html/emails.php b/output/html/emails.php new file mode 100644 index 000000000..287423d0f --- /dev/null +++ b/output/html/emails.php @@ -0,0 +1,239 @@ + + */ + public function get_type_labels() { + return array( + /* translators: %s: Total number of emails */ + 'total' => _x( 'Total: %s', 'Emails', 'query-monitor' ), + 'plural' => __( 'Emails', 'query-monitor' ), + /* translators: %s: Total number of emails */ + 'count' => _x( 'Emails (%s)', 'Emails', 'query-monitor' ), + ); + } + + /** + * @return void + */ + public function output() { + /** @var QM_Data_Emails $data */ + $data = $this->collector->get_data(); + + if ( empty( $data->emails ) ) { + $this->before_non_tabular_output(); + + $notice = __( 'No emails.', 'query-monitor' ); + echo $this->build_notice( $notice ); // WPCS: XSS ok. + + $this->after_non_tabular_output(); + + return; + } + + $this->before_tabular_output(); + + echo ''; + echo ''; + echo '' . esc_html__( 'To', 'query-monitor' ) . ''; + echo '' . esc_html__( 'Subject', 'query-monitor' ) . ''; + echo '' . esc_html__( 'Caller', 'query-monitor' ) . ''; + // echo '' . esc_html__( 'Headers', 'query-monitor' ) . ''; + echo '' . esc_html__( 'Attachments', 'query-monitor' ) . ''; + echo ''; + echo ''; + + echo ''; + + foreach ( $data->emails as $hash => $row ) { + $is_error = false; + $row_attr = array(); + $stack = array(); + $css = ''; + $to = $row['atts']['to']; + + if ( is_array( $to ) ) { + $to = implode( PHP_EOL, $to ); + } + + $filtered_trace = $row['filtered_trace']; + + foreach ( $filtered_trace as $frame ) { + $stack[] = self::output_filename( $frame['display'], $frame['calling_file'], $frame['calling_line'] ); + } + + $is_error = in_array( $hash, $data->preempted ) || in_array( $hash, $data->failed ); + + if ( $is_error ) { + $css = 'qm-warn'; + } + + $attr = ''; + foreach ( $row_attr as $a => $v ) { + $attr .= ' ' . $a . '="' . esc_attr( (string) $v ) . '"'; + } + + printf( // WPCS: XSS ok. + '', + $attr, + esc_attr( $css ) + ); + + printf( + '%s', + nl2br( esc_html( $to ) ) + ); + + echo ''; + + echo esc_html( $row['atts']['subject'] ); + + if ( is_wp_error( $row['error'] ) ) { + $error = QueryMonitor::icon( 'warning' ); + echo '
' . $error . ' ' . $row['error']->get_error_message( 'wp_mail_failed' ); + } + + echo ''; + + $caller = array_shift( $stack ); + + echo ''; + + if ( ! empty( $stack ) ) { + echo self::build_toggler(); // WPCS: XSS ok; + } + + echo '
    '; + + echo "
  1. {$caller}
  2. "; // WPCS: XSS ok. + + if ( ! empty( $stack ) ) { + echo '
  3. ' . implode( '
  4. ', $stack ) . '
  5. '; // WPCS: XSS ok. + } + + echo '
'; + + // echo ''; + // self::output_inner( $row['atts']['headers'] ); + // echo ''; + + printf( + '%d', + count( $row['atts']['attachments'] ) + ); + + echo ''; + } + + echo ''; + echo ''; + + echo ''; + printf( + '%s', + sprintf( + /* translators: %s: Number of HTTP API requests */ + esc_html( _nx( 'Total: %s', 'Total: %s', $data->counts['total'], 'Emails', 'query-monitor' ) ), + '' . esc_html( number_format_i18n( $data->counts['total'] ) ) . '' + ) + ); + echo ''; + echo ''; + + $this->after_tabular_output(); + } + + /** + * @param array $class + * @return array + */ + public function admin_class( array $class ) { + /** @var QM_Data_Email */ + $data = $this->collector->get_data(); + + if ( ! empty( $data->preempted ) || ! empty( $data->failed ) ) { + $class[] = 'qm-error'; + } + + return $class; + + } + + /** + * @param array $menu + * @return array + */ + public function admin_menu( array $menu ) { + /** @var QM_Data_Email */ + $data = $this->collector->get_data(); + + $type_label = $this->get_type_labels(); + $label = sprintf( + $type_label['count'], + number_format_i18n( $data->counts['total'] ) + ); + + $args = array( + 'title' => esc_html( $label ), + 'id' => esc_attr( "query-monitor-{$this->collector->id}" ), + 'href' => esc_attr( '#' . $this->collector->id() ), + ); + + if ( ! empty( $data->preempted ) || ! empty( $data->failed ) ) { + $args['meta']['classname'] = 'qm-error'; + } + + $id = $this->collector->id(); + $menu[ $id ] = $this->menu( $args ); + + return $menu; + + } + +} + +/** + * @param array $output + * @param QM_Collectors $collectors + * @return array + */ +function register_qm_output_html_emails( array $output, QM_Collectors $collectors ) { + $collector = QM_Collectors::get( 'emails' ); + if ( $collector ) { + $output['emails'] = new QM_Output_Html_Emails( $collector ); + } + return $output; +} + +add_filter( 'qm/outputter/html', 'register_qm_output_html_emails', 110, 2 ); \ No newline at end of file From 4872ed340bf68e9d9488fc44faff917d0c22cb14 Mon Sep 17 00:00:00 2001 From: Caleb Stauffer Date: Fri, 16 Jun 2023 17:16:19 -0400 Subject: [PATCH 2/7] save --- collectors/emails.php | 4 ++-- output/html/emails.php | 30 +++++++++++++++++++----------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/collectors/emails.php b/collectors/emails.php index 97d3e044b..c5a04b598 100644 --- a/collectors/emails.php +++ b/collectors/emails.php @@ -90,7 +90,7 @@ public function filter_pre_wp_mail( $preempt, $atts ) { $this->data->preempted[] = $hash; $this->data->emails[ $hash ] = array( 'atts' => $atts, - 'error' => null, + 'error' => new WP_Error( 'pre_wp_mail', 'Preempted sending email.' ), 'filtered_trace' => $trace->get_filtered_trace(), ); @@ -148,7 +148,7 @@ public function process() { if ( ! is_array( $this->data->failed ) ) { $this->data->failed = array(); } -do_action( 'qm/debug', $this->data->emails ); + foreach ( $this->data->emails as $hash => $email ) { $this->data->counts['total']++; diff --git a/output/html/emails.php b/output/html/emails.php index 287423d0f..22b8cf58f 100644 --- a/output/html/emails.php +++ b/output/html/emails.php @@ -69,7 +69,7 @@ public function output() { echo '' . esc_html__( 'To', 'query-monitor' ) . ''; echo '' . esc_html__( 'Subject', 'query-monitor' ) . ''; echo '' . esc_html__( 'Caller', 'query-monitor' ) . ''; - // echo '' . esc_html__( 'Headers', 'query-monitor' ) . ''; + echo '' . esc_html__( 'Headers', 'query-monitor' ) . ''; echo '' . esc_html__( 'Attachments', 'query-monitor' ) . ''; echo ''; echo ''; @@ -121,7 +121,7 @@ public function output() { if ( is_wp_error( $row['error'] ) ) { $error = QueryMonitor::icon( 'warning' ); - echo '
' . $error . ' ' . $row['error']->get_error_message( 'wp_mail_failed' ); + echo '
' . $error . ' ' . $row['error']->get_error_message(); } echo ''; @@ -144,9 +144,9 @@ public function output() { echo ''; - // echo ''; - // self::output_inner( $row['atts']['headers'] ); - // echo ''; + echo ''; + self::output_inner( $row['atts']['headers'] ); + echo ''; printf( '%d', @@ -157,18 +157,26 @@ public function output() { } echo ''; - echo ''; - echo ''; + echo ''; printf( - '%s', + '%s %s %s', sprintf( - /* translators: %s: Number of HTTP API requests */ - esc_html( _nx( 'Total: %s', 'Total: %s', $data->counts['total'], 'Emails', 'query-monitor' ) ), + /* translators: %s: Total number of emails */ + esc_html_x( 'Total: %s', 'Total emails', 'query-monitor' ), '' . esc_html( number_format_i18n( $data->counts['total'] ) ) . '' + ), + sprintf( + /* translators: %s: Total number of emails preempted */ + esc_html_x( 'Preempted: %s', 'Preempted emails', 'query-monitor' ), + '' . esc_html( number_format_i18n( $data->counts['preempted'] ) ) . '' + ), + sprintf( + /* translators: %s: Total number of emails failed */ + esc_html_x( 'Failed: %s', 'Failed emails', 'query-monitor' ), + '' . esc_html( number_format_i18n( $data->counts['failed'] ) ) . '' ) ); - echo ''; echo ''; $this->after_tabular_output(); From 4b8c36cd019b1a3a68ef79915d60fbe2d6a10200 Mon Sep 17 00:00:00 2001 From: Caleb Stauffer Date: Mon, 19 Jun 2023 11:48:25 -0400 Subject: [PATCH 3/7] save --- collectors/emails.php | 85 ++++++++++++++++++++++++------------------ output/html/emails.php | 10 +++-- 2 files changed, 56 insertions(+), 39 deletions(-) diff --git a/collectors/emails.php b/collectors/emails.php index c5a04b598..3d7df7e0b 100644 --- a/collectors/emails.php +++ b/collectors/emails.php @@ -25,8 +25,8 @@ public function get_storage(): QM_Data { */ public function set_up() { parent::set_up(); + add_filter( 'wp_mail', array( $this, 'filter_wp_mail' ), 9999 ); add_filter( 'pre_wp_mail', array( $this, 'filter_pre_wp_mail' ), 9999, 2 ); - add_action( 'wp_mail_succeeded', array( $this, 'action_wp_mail_succeeded' ) ); add_action( 'wp_mail_failed', array( $this, 'action_wp_mail_failed' ) ); } @@ -34,8 +34,8 @@ public function set_up() { * @return void */ public function tear_down() { + remove_filter( 'wp_mail', array( $this, 'filter_wp_mail' ), 9999 ); remove_filter( 'pre_wp_mail', array( $this, 'filter_pre_wp_mail' ), 9999 ); - remove_action( 'wp_mail_succeeded', array( $this, 'action_wp_mail_succeeded' ) ); remove_action( 'wp_mail_failed', array( $this, 'action_wp_mail_failed' ) ); parent::tear_down(); @@ -66,18 +66,39 @@ public function get_concerned_filters() { ); } - protected function hash( $value ) { - $value = json_encode( $value ); + /** + * Other attributes of wp_mail() are changed, + * so use the attributes that aren't changed + * to generate identifying hash. + */ + protected function hash( $atts ) { + $to = $atts['to']; + + if ( ! is_array( $to ) ) { + $to = explode( ',', $to ); + $to = array_map( 'trim', $to ); + } + + $value = json_encode( array( + 'to' => $to, + 'subject' => $atts['subject'], + 'message' => $atts['message'], + ) ); + return wp_hash( $value ); } - public function filter_pre_wp_mail( $preempt, $atts ) { - if ( is_null( $preempt ) ) { - return null; - } + public function filter_wp_mail( $atts ) { + $atts = wp_parse_args( $atts, array( + 'to' => array(), + 'subject' => '', + 'message' => '', + 'headers' => array(), + 'attachments' => array(), + ) ); - if ( is_null( $this->data->preempted ) ) { - $this->data->preempted = array(); + if ( ! is_array( $atts['to'] ) ) { + $atts['to'] = explode( ',', $atts['to'] ); } $hash = $this->hash( $atts ); @@ -87,29 +108,30 @@ public function filter_pre_wp_mail( $preempt, $atts ) { ), ) ); - $this->data->preempted[] = $hash; $this->data->emails[ $hash ] = array( 'atts' => $atts, - 'error' => new WP_Error( 'pre_wp_mail', 'Preempted sending email.' ), + 'error' => null, 'filtered_trace' => $trace->get_filtered_trace(), ); - return $preempt; + return $atts; } - public function action_wp_mail_succeeded( $atts ) { - $hash = $this->hash( $atts ); - $trace = new QM_Backtrace( array( - 'ignore_hook' => array( - current_filter() => true, - ), - ) ); + public function filter_pre_wp_mail( $preempt, $atts ) { + if ( is_null( $preempt ) ) { + return null; + } - $this->data->emails[ $hash ] = array( - 'atts' => $atts, - 'error' => null, - 'filtered_trace' => $trace->get_filtered_trace(), - ); + if ( is_null( $this->data->preempted ) ) { + $this->data->preempted = array(); + } + + $hash = $this->hash( $atts ); + + $this->data->preempted[] = $hash; + $this->data->emails[ $hash ]['error'] = new WP_Error( 'pre_wp_mail', 'Preempted sending email.' ); + + return $preempt; } public function action_wp_mail_failed( $error ) { @@ -119,18 +141,9 @@ public function action_wp_mail_failed( $error ) { $atts = $error->get_error_data( 'wp_mail_failed' ); $hash = $this->hash( $atts ); - $trace = new QM_Backtrace( array( - 'ignore_hook' => array( - current_filter() => true, - ), - ) ); $this->data->failed[] = $hash; - $this->data->emails[ $hash ] = array( - 'atts' => $atts, - 'error' => $error, - 'filtered_trace' => $trace->get_filtered_trace(), - ); + $this->data->emails[ $hash ]['error'] = $error; } public function process() { @@ -165,4 +178,4 @@ public function process() { } # Load early to catch early emails -QM_Collectors::add( new QM_Collector_Emails() ); \ No newline at end of file +QM_Collectors::add( new QM_Collector_Emails() ); diff --git a/output/html/emails.php b/output/html/emails.php index 22b8cf58f..6676ec539 100644 --- a/output/html/emails.php +++ b/output/html/emails.php @@ -104,6 +104,10 @@ public function output() { $attr .= ' ' . $a . '="' . esc_attr( (string) $v ) . '"'; } + if ( ! is_array( $row['atts']['headers'] ) ) { + $row['atts']['headers'] = array(); + } + printf( // WPCS: XSS ok. '', $attr, @@ -120,8 +124,8 @@ public function output() { echo esc_html( $row['atts']['subject'] ); if ( is_wp_error( $row['error'] ) ) { - $error = QueryMonitor::icon( 'warning' ); - echo '
' . $error . ' ' . $row['error']->get_error_message(); + $icon = QueryMonitor::icon( 'warning' ); + echo '
' . $icon . __( 'Failed sending:', 'query-monitor' ) . ' ' . $row['error']->get_error_message(); } echo ''; @@ -244,4 +248,4 @@ function register_qm_output_html_emails( array $output, QM_Collectors $collector return $output; } -add_filter( 'qm/outputter/html', 'register_qm_output_html_emails', 110, 2 ); \ No newline at end of file +add_filter( 'qm/outputter/html', 'register_qm_output_html_emails', 110, 2 ); From bc619207096004887184f7aae926cdc5855dcdd1 Mon Sep 17 00:00:00 2001 From: Caleb Stauffer Date: Mon, 19 Jun 2023 12:18:21 -0400 Subject: [PATCH 4/7] save --- collectors/emails.php | 4 ++++ output/html/emails.php | 23 +++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/collectors/emails.php b/collectors/emails.php index 3d7df7e0b..9c04b5a80 100644 --- a/collectors/emails.php +++ b/collectors/emails.php @@ -101,6 +101,10 @@ public function filter_wp_mail( $atts ) { $atts['to'] = explode( ',', $atts['to'] ); } + if ( ! is_array( $atts['attachments'] ) ) { + $atts['attachments'] = explode( "\n", str_replace( "\r\n", "\n", $atts['attachments'] ) ); + } + $hash = $this->hash( $atts ); $trace = new QM_Backtrace( array( 'ignore_hook' => array( diff --git a/output/html/emails.php b/output/html/emails.php index 6676ec539..78d551eea 100644 --- a/output/html/emails.php +++ b/output/html/emails.php @@ -148,14 +148,25 @@ public function output() { echo ''; - echo ''; - self::output_inner( $row['atts']['headers'] ); + $is_empty = empty( $row['atts']['headers'] ); + + echo ''; + if ( $is_empty ) { + echo '—'; + } else { + self::output_inner( $row['atts']['headers'] ); + } echo ''; - printf( - '%d', - count( $row['atts']['attachments'] ) - ); + $is_empty = empty( $row['atts']['attachments'] ); + + echo ''; + if ( $is_empty ) { + echo '—'; + } else { + self::output_inner( $row['atts']['attachments'] ); + } + echo ''; echo ''; } From f8ed707128bb7f391ba3f37d0cba094d41ba7fb8 Mon Sep 17 00:00:00 2001 From: Caleb Stauffer Date: Tue, 20 Jun 2023 12:22:35 -0400 Subject: [PATCH 5/7] add return value --- data/emails.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/data/emails.php b/data/emails.php index a477e6043..330765783 100644 --- a/data/emails.php +++ b/data/emails.php @@ -6,6 +6,9 @@ */ class QM_Data_Emails extends QM_Data { + /** + * @var array> + */ public $emails; /** @@ -22,4 +25,4 @@ class QM_Data_Emails extends QM_Data { * @var array */ public $counts; -} \ No newline at end of file +} From 89ccc332fc0926727d8e7144bf7c79bed436cac7 Mon Sep 17 00:00:00 2001 From: Caleb Stauffer Date: Tue, 20 Jun 2023 15:21:45 -0400 Subject: [PATCH 6/7] fix test errors --- collectors/emails.php | 39 ++++++++++++++++++++++++++++----------- output/html/emails.php | 17 +++++------------ 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/collectors/emails.php b/collectors/emails.php index 9c04b5a80..8dd109e57 100644 --- a/collectors/emails.php +++ b/collectors/emails.php @@ -70,6 +70,9 @@ public function get_concerned_filters() { * Other attributes of wp_mail() are changed, * so use the attributes that aren't changed * to generate identifying hash. + * + * @param array> $atts + * @return string */ protected function hash( $atts ) { $to = $atts['to']; @@ -79,15 +82,25 @@ protected function hash( $atts ) { $to = array_map( 'trim', $to ); } - $value = json_encode( array( + $data = array( 'to' => $to, 'subject' => $atts['subject'], 'message' => $atts['message'], - ) ); + ); + + $datastring = json_encode( $data ); - return wp_hash( $value ); + if ( ! is_string( $datastring ) ) { + $datastring = print_r( $data, true ); + } + + return wp_hash( $datastring ); } + /** + * @param array> $atts + * @return array> + */ public function filter_wp_mail( $atts ) { $atts = wp_parse_args( $atts, array( 'to' => array(), @@ -121,15 +134,16 @@ public function filter_wp_mail( $atts ) { return $atts; } + /** + * @param null|bool $preempt + * @param array> $atts + * @return null|bool + */ public function filter_pre_wp_mail( $preempt, $atts ) { if ( is_null( $preempt ) ) { return null; } - if ( is_null( $this->data->preempted ) ) { - $this->data->preempted = array(); - } - $hash = $this->hash( $atts ); $this->data->preempted[] = $hash; @@ -138,11 +152,11 @@ public function filter_pre_wp_mail( $preempt, $atts ) { return $preempt; } + /** + * @param WP_Error $error + * @return void + */ public function action_wp_mail_failed( $error ) { - if ( is_null( $this->data->failed ) ) { - $this->data->failed = array(); - } - $atts = $error->get_error_data( 'wp_mail_failed' ); $hash = $this->hash( $atts ); @@ -150,6 +164,9 @@ public function action_wp_mail_failed( $error ) { $this->data->emails[ $hash ]['error'] = $error; } + /** + * @return void + */ public function process() { $this->data->counts = array( 'preempted' => 0, diff --git a/output/html/emails.php b/output/html/emails.php index 78d551eea..eafec9180 100644 --- a/output/html/emails.php +++ b/output/html/emails.php @@ -78,7 +78,6 @@ public function output() { foreach ( $data->emails as $hash => $row ) { $is_error = false; - $row_attr = array(); $stack = array(); $css = ''; $to = $row['atts']['to']; @@ -99,18 +98,12 @@ public function output() { $css = 'qm-warn'; } - $attr = ''; - foreach ( $row_attr as $a => $v ) { - $attr .= ' ' . $a . '="' . esc_attr( (string) $v ) . '"'; - } - if ( ! is_array( $row['atts']['headers'] ) ) { $row['atts']['headers'] = array(); } printf( // WPCS: XSS ok. - '', - $attr, + '', esc_attr( $css ) ); @@ -202,7 +195,7 @@ public function output() { * @return array */ public function admin_class( array $class ) { - /** @var QM_Data_Email */ + /** @var QM_Data_Emails */ $data = $this->collector->get_data(); if ( ! empty( $data->preempted ) || ! empty( $data->failed ) ) { @@ -218,7 +211,7 @@ public function admin_class( array $class ) { * @return array */ public function admin_menu( array $menu ) { - /** @var QM_Data_Email */ + /** @var QM_Data_Emails */ $data = $this->collector->get_data(); $type_label = $this->get_type_labels(); @@ -229,8 +222,8 @@ public function admin_menu( array $menu ) { $args = array( 'title' => esc_html( $label ), - 'id' => esc_attr( "query-monitor-{$this->collector->id}" ), - 'href' => esc_attr( '#' . $this->collector->id() ), + 'id' => esc_attr( "query-monitor-{$this->collector->id}" ), + 'href' => esc_attr( '#' . $this->collector->id() ), ); if ( ! empty( $data->preempted ) || ! empty( $data->failed ) ) { From 110022af31157a92a7ced22fce6be3a9ff4101a2 Mon Sep 17 00:00:00 2001 From: Caleb Stauffer Date: Wed, 21 Jun 2023 10:15:29 -0400 Subject: [PATCH 7/7] fix code smells --- output/html/emails.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/output/html/emails.php b/output/html/emails.php index eafec9180..ef81cc582 100644 --- a/output/html/emails.php +++ b/output/html/emails.php @@ -118,7 +118,8 @@ public function output() { if ( is_wp_error( $row['error'] ) ) { $icon = QueryMonitor::icon( 'warning' ); - echo '
' . $icon . __( 'Failed sending:', 'query-monitor' ) . ' ' . $row['error']->get_error_message(); + echo '
' . $icon; // WPCS: XSS ok. + echo esc_html( __( 'Failed sending:', 'query-monitor' ) . ' ' . $row['error']->get_error_message() ); } echo '';